Пример #1
0
 def fusion_rl_tune(self, task_id, json_info):
     """
     RL tune for fusion op
     :param task_id: task id for this op to tune
     :param json_info: op's info
     :return: tune result
     """
     if 'fusion_op' not in json_info or not json_info['fusion_op']:
         raise ValueError("Json string Errors, key:fusion_op not found.")
     kernel_name = json_info["fusion_op"]["fusion_op_name"]
     full_name = json_info["fusion_op"]["full_name"]
     set_current_op_name(kernel_name)
     converted_json = fusion_to_fusion(json.dumps(json_info),
                                       tune_mode="RL")
     job_type = RL_COMPILE
     base_kernel = './kernel_meta/' + kernel_name + '.o'
     try:
         fusion_op(converted_json)
     # pylint: disable=broad-except
     except Exception:
         exc_type, exc_value, _ = sys.exc_info()
         log.error("exc_type:{}, exc_value:{}, exc_traceback:{}".format(
             exc_type, exc_value, traceback.format_exc()))
         return False, job_type
     if self.offline_tune:
         job_type = RL_OFFLINE
         dump_fusion_json(converted_json, self.offline_dump_path)
     else:
         job_type = RL_ONLINE
     graph_id = 0
     l1size = 0
     ret = dispatch_fusion_tune_task(graph_id, task_id, l1size, base_kernel,
                                     kernel_name, full_name, converted_json)
     return ret, job_type
Пример #2
0
    def single_rl_tune(self, task_id, json_info):
        """
        RL tune for single op
        :param task_id: task id for this op to tune
        :param json_info: op's info
        :return: tune result
        """
        if self.offline_tune:
            converted_json = single_to_fusion(json.dumps(json_info),
                                              tune_mode="RL")
        op_type = json_info['op_info']['name']
        kernel_name = json_info['op_info']['kernel_name']
        op_module = __import__("impl." + op_type, globals(), locals(),
                               [op_type], 0)
        op_module_name = "impl." + op_type
        py_fn_name = json_info['op_info']['name']
        op_func = getattr(op_module, py_fn_name, None)

        set_current_op_name(kernel_name)
        inputs_args = get_args(json_info['op_info'], 'inputs')
        outputs_args = get_args(json_info['op_info'], 'outputs')
        attrs_args = get_args(json_info['op_info'], 'attrs')
        op_args = inputs_args, outputs_args, attrs_args
        # todo build with build_single_op_from_c
        base_kernel = './kernel_meta/' + kernel_name + '.o'
        job_type = RL_COMPILE
        try:
            op_func(*inputs_args,
                    *outputs_args,
                    *attrs_args,
                    kernel_name=kernel_name)
        # pylint: disable=broad-except
        except Exception:
            exc_type, exc_value, _ = sys.exc_info()
            log.error("exc_type:{}, exc_value:{}, exc_traceback:{}".format(
                exc_type, exc_value, traceback.format_exc()))
            return False, job_type
        if self.offline_tune:
            job_type = RL_OFFLINE
            dump_fusion_json(converted_json, self.offline_dump_path)
        else:
            job_type = RL_ONLINE
        graph_id = 0
        l1size = 0  # todo need to verify
        ret = dispatch_single_tune_task(graph_id, task_id, l1size, base_kernel,
                                        kernel_name, op_module_name,
                                        op_module_name + "@" + op_module_name,
                                        op_type, op_type, op_args)

        self.module_list[op_module_name] = 1
        self.fusion_need_sync += 1
        return ret, job_type
Пример #3
0
    def single_rl_tune(self, task_id, json_info):
        """
        RL tune for single op
        :param task_id: task id for this op to tune
        :param json_info: op's info
        :return: tune result
        """
        if self.offline_tune:
            converted_json = single_to_fusion(json.dumps(json_info),
                                              tune_mode="RL")
        op_type = json_info['op_info']['name']
        kernel_name = json_info['op_info']['kernel_name']
        full_name = json_info['op_info']['full_name']
        tune_mode = "RL"
        set_current_op_name(kernel_name)
        # todo build with build_single_op_from_c
        base_kernel = './kernel_meta/' + kernel_name + '.o'
        job_type = RL_COMPILE
        compile_info = "{}"
        try:
            compile_info, op_args, op_module_name = build_op(
                OP_BUILD, json.dumps(json_info), tune_mode)
        # pylint: disable=broad-except
        except Exception:
            exc_type, exc_value, _ = sys.exc_info()
            log.error("exc_type:{}, exc_value:{}, exc_traceback:{}".format(
                exc_type, exc_value, traceback.format_exc()))
            return False, job_type, compile_info
        if self.offline_tune:
            job_type = RL_OFFLINE
            dump_fusion_json(converted_json, self.offline_dump_path)
        else:
            job_type = RL_ONLINE
        graph_id = 0
        l1size = 0  # todo need to verify
        ret = dispatch_single_tune_task(graph_id, task_id, l1size, base_kernel,
                                        kernel_name, full_name,
                                        op_module_name + "@" + op_module_name,
                                        op_type, op_type, op_args)

        self.module_list[op_module_name] = 1
        self.fusion_need_sync += 1
        return ret, job_type, json.dumps(compile_info)