From bc514c6cab89562d1fa1667402a3f481b1159499 Mon Sep 17 00:00:00 2001 From: chenlei_autodiff Date: Wed, 1 Dec 2021 11:00:03 +0800 Subject: [PATCH] [GraphKernel] fix python path for ascend compiler. --- .../parallel_compile/akg_compiler/compiler.py | 14 +------------- .../graph_kernel/lite_adapter/akg_build.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/mindspore/_extends/parallel_compile/akg_compiler/compiler.py b/mindspore/_extends/parallel_compile/akg_compiler/compiler.py index a86ca81ffda..55bdded4694 100644 --- a/mindspore/_extends/parallel_compile/akg_compiler/compiler.py +++ b/mindspore/_extends/parallel_compile/akg_compiler/compiler.py @@ -27,7 +27,7 @@ def run_compiler(op_json, attrs=None): Returns: None """ - from .get_file_path import get_akg_path + from get_file_path import get_akg_path sys.path.insert(0, get_akg_path()) p = __import__("akg", globals(), locals(), ['ms'], 0) func = getattr(p.ms, "compilewithjson") @@ -35,18 +35,6 @@ def run_compiler(op_json, attrs=None): if not res: raise ValueError("Compile error") -def run_compiler_with_json_name(op_json_name, attrs=None): - """ - Run AKG compiler with json file name - - Args: - op_json_name (str): json file name of the op - - Returns: - None - """ - with open(op_json_name, 'r') as f: - return run_compiler(f.read().strip(), attrs) if __name__ == "__main__": if len(sys.argv) > 2: diff --git a/mindspore/ccsrc/backend/optimizer/graph_kernel/lite_adapter/akg_build.cc b/mindspore/ccsrc/backend/optimizer/graph_kernel/lite_adapter/akg_build.cc index ae0764de2be..8726a8adb7b 100644 --- a/mindspore/ccsrc/backend/optimizer/graph_kernel/lite_adapter/akg_build.cc +++ b/mindspore/ccsrc/backend/optimizer/graph_kernel/lite_adapter/akg_build.cc @@ -35,8 +35,12 @@ namespace mindspore::graphkernel { bool CompileSingleJson(const std::string &json_name) { std::string attrs = "None"; std::ostringstream py_cmd; - py_cmd << "from mindspore._extends.parallel_compile.akg_compiler.compiler import run_compiler_with_json_name\n"; - py_cmd << "run_compiler_with_json_name(\'" << json_name << "\', " << attrs << ")"; + py_cmd << "from mindspore._extends.parallel_compile.akg_compiler.get_file_path import get_akg_path\n"; + py_cmd << "import sys\n"; + py_cmd << "sys.path.insert(0, get_akg_path())\n"; + py_cmd << "from akg.ms import compilewithjsonname\n"; + py_cmd << "if not compilewithjsonname(\'" << json_name << "\', " << attrs << "):\n"; + py_cmd << " raise RuntimeError(\'Compile fail for json: " << json_name << "\')"; std::string cmd = "python -c \"" + py_cmd.str() + "\""; auto ret = system(cmd.c_str()); if (!WIFEXITED(ret)) {