Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DICP] use ge graph runner for ascendgraph #860

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions dicp/dicp/vendor/AscendGraph/codegen/ascend.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, graph, aten_graph=None, folder=None, graph_key=None):
self.py_output_names = []
self.graph_output_names = []
self.build_options = []
self.output_nodes = []

self.folder = folder
self.graph_key = graph_key
Expand Down Expand Up @@ -194,8 +195,27 @@ def parse_outputs(self):
self.py_output_names.append(str(node))
self.output_args = real_output_args

if len(self.sym_in_args) > 0 or len(self.sym_to_inputs) > 0:
for output in self.output_args:
info = {}
info['format'] = 'ND'
if hasattr(output, 'meta'):
output = output.meta['val']
if isinstance(output, torch.SymInt):
info['data_type'] = 'INT32'
elif isinstance(output, torch.SymBool):
info['data_type'] = 'BOOL'
else:
info['data_type'] = get_ascend_dtype(output.dtype)
self.output_nodes.append(info)
if len(self.assign_args) > 0:
self.graph_output_names.extend(list(zip(*self.assign_args))[0])
for item in self.assign_args:
index = item[1]
info = {}
info['format'] = self.data_nodes[index]['format']
info['data_type'] = self.data_nodes[index]['data_type']
self.output_nodes.append(info)

def gen_import_code(self):
self.import_code.splice(
Expand All @@ -206,7 +226,7 @@ def gen_import_code(self):
import random
from torch import empty_strided, as_strided, device
from dicp.dynamo_bridge.compile import AsyncCompileKernel
from dicp.vendor.AscendGraph.compile_job import AscendCompileJob
from dicp.vendor.AscendGraph.compile_job import AscendGECompileAclRunJob, AscendGECompileGERunJob

aten = torch.ops.aten
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
Expand Down Expand Up @@ -461,16 +481,19 @@ def gen_graph_json(self):
"build_options": self.build_options,
"data_nodes": self.data_nodes,
"common_nodes": self.common_nodes,
"output_nodes": self.output_nodes,
}
self.remove_symint(graph)
return json.dumps(graph)

def gen_compile_graph_code(self):
compile_graph_code = IndentedBuffer()
graph_json = self.gen_graph_json()
compile_job_type = os.environ.get("DICP_ASCEND_COMPILE_JOB_TYPE", "AscendGECompileGERunJob")
assert compile_job_type in ["AscendGECompileGERunJob", "AscendGECompileAclRunJob"]
compile_graph_code.splice(
f"""
ascend_compile_job = AscendCompileJob('''{graph_json}''')
ascend_compile_job = {compile_job_type}('''{graph_json}''')
async_compile = AsyncCompileKernel()
kernel_cpp_0 = async_compile.compile_kernel(ascend_compile_job)
""", strip=True
Expand Down
Loading
Loading