auto tune step two tune process

pull/12869/head
laiyongqiang 4 years ago
parent 4543094519
commit f16cea00a4

@ -26,6 +26,7 @@ build_in_impl_path = get_built_in_impl_path()
# op function list
op_build = "compile"
def _initialize(impl_path):
"""Initialize"""
if impl_path == "":
@ -37,6 +38,7 @@ def _initialize(impl_path):
sys.path.insert(0, op_module_name)
def _replace_range(args):
for arg in args:
if not arg.__contains__('range'):
@ -47,6 +49,7 @@ def _replace_range(args):
if value < 0:
range_item[index] = None
def build_op(build_type, json_str):
"""
call op functions with function name and input args json_str
@ -89,9 +92,9 @@ def build_op(build_type, json_str):
op_module = __import__(op_name)
else:
if is_dynamic_shape:
op_module = __import__("impl.dynamic."+op_name, globals(), locals(), [op_name], 0)
op_module = __import__("impl.dynamic." + op_name, globals(), locals(), [op_name], 0)
else:
op_module = __import__("impl."+op_name, globals(), locals(), [op_name], 0)
op_module = __import__("impl." + op_name, globals(), locals(), [op_name], 0)
# get function
if build_type == op_build:
if custom_flag:
@ -149,6 +152,7 @@ def compile_with_json(json_str):
ret = build_op(op_build, json_str)
return ret
if __name__ == "__main__":
in_args = sys.stdin.readline()
result = compile_with_json(in_args)

@ -15,6 +15,7 @@
"""tbe common"""
import os
class TBEException(Exception):
"""tbe exception class"""
@ -64,6 +65,7 @@ def _check_arg_info(item):
if 'param_type' not in item or not item['param_type']:
raise ValueError("Json string Errors, key:param_type not found.")
def get_input_output(io_info, args):
"""
Parse args.
@ -100,6 +102,7 @@ def get_input_output(io_info, args):
if len(item) > 1:
args.append(arg)
def get_attr(attr_info, args):
"""
Parse args.
@ -118,6 +121,7 @@ def get_attr(attr_info, args):
if item["name"] != "isRef":
args.append(item['value'])
def get_args(op_info, arg_type):
"""
Parse args.

File diff suppressed because it is too large Load Diff

@ -80,8 +80,8 @@ std::map<int64_t, KernelModPtr> KernelFusion(const std::vector<FusionScopeInfo>
size_t hash_id = GenFusionJsonHash(fusion_op);
auto json_name =
fusion_kernel_name.append("_").append(std::to_string(hash_id)).append("_").append(std::to_string(device_id));
fusion_op["graph_id"] = fusion_scope_iter.graph_id;
fusion_op["fusion_op_name"] = json_name;
fusion_op["full_name"] = fusion_scope_iter.full_name;
// get io size
std::vector<size_t> input_size_list;
std::vector<size_t> output_size_list;

@ -19,6 +19,7 @@
#include <utility>
#include <vector>
#include <map>
#include <string>
#include "backend/kernel_compiler/kernel.h"
namespace mindspore {
namespace kernel {
@ -26,15 +27,15 @@ namespace kernel {
* @brief fuse op and return a callable mod
*/
struct FusionScopeInfo {
FusionScopeInfo(int64_t id, uint32_t g_id, std::vector<AnfNodePtr> in, std::vector<AnfNodePtr> comp,
FusionScopeInfo(int64_t id, std::string f_name, std::vector<AnfNodePtr> in, std::vector<AnfNodePtr> comp,
std::vector<AnfNodePtr> out)
: scope_id(id),
graph_id(g_id),
full_name(f_name),
input_nodes(std::move(in)),
compute_nodes(std::move(comp)),
output_nodes(std::move(out)) {}
int64_t scope_id{};
uint32_t graph_id{};
std::string full_name{};
std::vector<AnfNodePtr> input_nodes;
std::vector<AnfNodePtr> compute_nodes;
std::vector<AnfNodePtr> output_nodes;

@ -123,7 +123,6 @@ bool TbeKernelJsonCreator::GenTbeSingleKernelJson(const std::shared_ptr<mindspor
nlohmann::json op_info_json;
op_info_json[kJIsDynamicShape] = tbe::TbeDynamicShapeUtil::GetDynamicShapeAttr(anf_node->cast<CNodePtr>());
auto func_name = op_info_ptr->kernel_name();
op_info_json["graph_id"] = AnfAlgo::GetGraphId(anf_node.get());
op_info_json[kJName] = func_name;
op_info_json[kJModuleName] = std::string("impl.") + func_name;
op_info_json[kJPyModulePath] = kPyPath;
@ -163,7 +162,6 @@ bool TbeKernelJsonCreator::GenTbeSingleKernelJson(const std::shared_ptr<mindspor
op_info_json["Type"] = op_name;
op_info_json[kJKernelName] = json_name_;
op_info_json[kGenModel] = kSingle;
op_info_json[kJFullName] = anf_node->fullname_with_scope();
// create attr_desc
nlohmann::json attr_desc;

@ -43,7 +43,7 @@ const int8_t MULTI_ELTWISE_SIZE = 4;
using FusedNodeRecord = std::vector<std::unordered_set<AnfNodePtr>>;
struct BufferFusionInfo_t {
uint32_t graph_id;
std::string full_name;
std::vector<AnfNodePtr> anf_nodes;
std::vector<AnfNodePtr> inputs_list;
std::vector<AnfNodePtr> outputs_list;

@ -387,7 +387,6 @@ void RemoveCircle(const session::KernelGraph &kernel_graph,
void UbPatternFusion::GetBufferFusionInfo(session::KernelGraph *kernel_graph,
std::unordered_map<int64_t, BufferFusionInfo_t> *buffer_fusion_infos) const {
MS_EXCEPTION_IF_NULL(buffer_fusion_infos);
auto graph_id = kernel_graph->graph_id();
GetFusionScopeComputeNodeList(kernel_graph, buffer_fusion_infos);
GetFusionScopeInputNodeList(*kernel_graph, buffer_fusion_infos);
GetFusionScopeOutputNodeList(kernel_graph, buffer_fusion_infos);
@ -397,7 +396,11 @@ void UbPatternFusion::GetBufferFusionInfo(session::KernelGraph *kernel_graph,
for (auto &buffer_fusion_info : *buffer_fusion_infos) {
buffer_fusion_info.second.kernel_build_info =
CreateFusionOpKernelInfo(buffer_fusion_info.second.inputs_list, buffer_fusion_info.second.outputs_list);
buffer_fusion_info.second.graph_id = graph_id;
// just for full_name_with_scope for every buffer_fusion_info.
auto fusion_node = CreateFusionOp(buffer_fusion_info.second.inputs_list, buffer_fusion_info.second.outputs_list,
buffer_fusion_info.second.anf_nodes, kernel_graph);
MS_EXCEPTION_IF_NULL(fusion_node);
buffer_fusion_info.second.full_name = fusion_node->fullname_with_scope();
}
}
@ -412,7 +415,7 @@ bool UbPatternFusion::FuseBufferFusionPattern(session::KernelGraph *kernel_graph
buffer_fusion_infos.begin(), buffer_fusion_infos.end(), std::back_inserter(fusion_scope_infos),
[](const std::pair<int64_t, BufferFusionInfo_t> &buffer_fusion_info) -> mindspore::kernel::FusionScopeInfo {
return mindspore::kernel::FusionScopeInfo(
buffer_fusion_info.first, buffer_fusion_info.second.graph_id, buffer_fusion_info.second.inputs_list,
buffer_fusion_info.first, buffer_fusion_info.second.full_name, buffer_fusion_info.second.inputs_list,
buffer_fusion_info.second.anf_nodes, buffer_fusion_info.second.outputs_list);
});
auto kernel_mods = mindspore::kernel::KernelFusion(fusion_scope_infos);
@ -447,6 +450,7 @@ bool UbPatternFusion::ReplaceFusionOp(std::unordered_map<int64_t, BufferFusionIn
TraceGuard guard(std::make_shared<TraceOpt>(buffer_fusion_info.anf_nodes[0]->debug_info()));
auto buffer_fusion = CreateFusionOp(buffer_fusion_info.inputs_list, buffer_fusion_info.outputs_list,
buffer_fusion_info.anf_nodes, kernel_graph);
buffer_fusion->set_fullname_with_scope(buffer_fusion_info.full_name);
AnfAlgo::SetSelectKernelBuildInfo(buffer_fusion_info.kernel_build_info, buffer_fusion.get());
// Set abstract of fusion_op node
std::vector<TypeId> types;

Loading…
Cancel
Save