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

[aot] Serialize built graph, deserialize and run. #5016

Closed
wants to merge 5 commits into from

Conversation

ailzhang
Copy link
Contributor

@ailzhang ailzhang commented May 20, 2022

Stack from ghstack (oldest at bottom):

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.

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};
Copy link
Member

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.

taichi/backends/vulkan/aot_module_loader_impl.h Outdated Show resolved Hide resolved
@@ -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.
Copy link
Member

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);
Copy link
Member

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...

Copy link
Contributor Author

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!

ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 20, 2022
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]
@ailzhang ailzhang requested a review from k-ye May 20, 2022 11:23
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 20, 2022
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
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 21, 2022
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
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 22, 2022
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
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 22, 2022
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
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 22, 2022
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
ailzhang pushed a commit to ailzhang/taichi that referenced this pull request May 22, 2022
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
Copy link
Member

@k-ye k-ye left a 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;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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]
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ailzhang
❌ Ailing Zhang


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]
@ailzhang
Copy link
Contributor Author

Agh got some CLA issue on my newly setup workstation, lemme see if I can hack it around...

@ailzhang ailzhang closed this May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants