-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[aot] Serialize built graph, deserialize and run. #5016
Conversation
related: #4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. [ghstack-poisoned]
related: #4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. [ghstack-poisoned]
|
||
// API based on proposal https://github.com/taichi-dev/taichi/issues/3642 | ||
// Initialize Vulkan program | ||
taichi::uint64 *result_buffer{nullptr}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I feel like it would be great if these tests can made the same for all the archs supporting AOT! (cc @turbo0628 @jim19930609 ) A more realistic result probably is that we have different setup routines for each arch. But the graph part stays the same.
@@ -21,6 +21,11 @@ class AotModuleBuilderImpl : public AotModuleBuilder { | |||
void dump(const std::string &output_dir, | |||
const std::string &filename) const override; | |||
|
|||
// FIXME: remove me once TaichiAotData is no longer backend specific. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine to add ti_aot_data_
to the module builder base class. It's just that not every impl uses it, yet?
@@ -147,6 +149,10 @@ void AotModuleBuilderImpl::add_per_backend(const std::string &identifier, | |||
ti_aot_data_.spirv_codes.push_back(compiled.task_spirv_source_codes); | |||
} | |||
|
|||
void AotModuleBuilderImpl::add_compiled_kernel(aot::Kernel *kernel) { | |||
kernel->save_to_module(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just thinking if we can put save_to_module
's impl within each module builder impl. That way aot::Kernel
doesn't need to know anything about the module.
Furthermore, aot::Kernel
has a misleading namespace now. It's probably more suitable to call this CompiledKernel
or something...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on the misleading namespace, I'll leave that to a separate search and replace PR!
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: dd72f446caf0fbb33491d165e64ade93d9d92978 Pull Request resolved: taichi-dev#5016
related: #4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. [ghstack-poisoned]
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
related: taichi-dev#4786 This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
related: taichi-dev#4786 [Update]: based on an offline discussion with @k-ye, I've split the original `Graph` class into `GraphBuilder` and `CompiledGraph` classes in C++. ``` GraphBuilder | compile() | | CompiledGraph <---- serialize/deserialize ----> file | | run() ``` This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. ghstack-source-id: e369b326734b3cffaf91262ed84806044e121c3c Pull Request resolved: taichi-dev#5016
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@@ -37,6 +38,10 @@ class AotModuleBuilder { | |||
virtual void dump(const std::string &output_dir, | |||
const std::string &filename) const = 0; | |||
|
|||
void dump_graph(std::string output_dir) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC, why we need a separate dump_graph
, instead of dumping everything in dump
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@k-ye Since dump_graph
is backend independent so I wanted to keep it in the base class. Note it's called in the dump
in every backend indeed we didn't call them separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesnt need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha nice catch! it was a legacy public api used in the first prototype. Removed in #5024! :D
related: #4786 [Update]: based on an offline discussion with k-ye, I've split the original `Graph` class into `GraphBuilder` and `CompiledGraph` classes in C++. Note that the implementation didn't follow exactly the builder design pattern as our builder is slightly simpler as shown below. The complexity in our problem is more in the need of serialization and deserialization for the same graph representation intead of its construction process. So IMHO it's good enough to separate the GraphBuilder and Runner(`CompiledGraph`) as we discussed. Please feel free to correct me if I'm wrong! ``` GraphBuilder | compile() | | CompiledGraph <---- serialize/deserialize ----> file | | run() ``` This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. [ghstack-poisoned]
Ailing Zhang seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
related: #4786 [Update]: based on an offline discussion with k-ye, I've split the original `Graph` class into `GraphBuilder` and `CompiledGraph` classes in C++. Note that the implementation didn't follow exactly the builder design pattern as our builder is slightly simpler as shown below. The complexity in our problem is more in the need of serialization and deserialization for the same graph representation intead of its construction process. So IMHO it's good enough to separate the GraphBuilder and Runner(`CompiledGraph`) as we discussed. Please feel free to correct me if I'm wrong! ``` GraphBuilder | compile() | | CompiledGraph <---- serialize/deserialize ----> file | | run() ``` This PR demonstrates a minimal example of serializing a built graph, deserializing and running it. [ghstack-poisoned]
Agh got some CLA issue on my newly setup workstation, lemme see if I can hack it around... |
Stack from ghstack (oldest at bottom):
related: #4786
[Update]: based on an offline discussion with @k-ye, I've split the
original
Graph
class intoGraphBuilder
andCompiledGraph
classesin C++. Note that the implementation didn't follow exactly the builder
design pattern as our builder is slightly simpler as shown below.
The complexity in our problem is more in the need of serialization and
deserialization for the same graph representation intead of its
construction process. So IMHO it's good enough to separate the
GraphBuilder and Runner(
CompiledGraph
) as we discussed. Please feelfree to correct me if I'm wrong!
This PR demonstrates a minimal example of serializing a built graph,
deserializing and running it.