Skip to content

Commit

Permalink
[aot] Dump required device capability in AOT module meta (#6056)
Browse files Browse the repository at this point in the history
  • Loading branch information
PENGUINLIONG authored Sep 14, 2022
1 parent cf4e710 commit 5046716
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scripts/aot-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function prepare-unity-build-env {
cd taichi

# Dependencies
git clone --reference-if-able /var/lib/git-cache https://github.com/taichi-dev/Taichi-UnityExample
git clone --reference-if-able /var/lib/git-cache -b upgrade-modules1 https://github.com/taichi-dev/Taichi-UnityExample

python misc/generate_unity_language_binding.py
cp c_api/unity/*.cs Taichi-UnityExample/Assets/Taichi/Generated
Expand Down
4 changes: 3 additions & 1 deletion taichi/aot/module_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <vector>

#include "taichi/rhi/device.h"
#include "taichi/common/core.h"
#include "taichi/common/serialization.h"

Expand Down Expand Up @@ -120,6 +121,7 @@ struct ModuleData {
std::unordered_map<std::string, CompiledTaichiKernel> kernels;
std::unordered_map<std::string, CompiledTaichiKernel> kernel_tmpls;
std::vector<aot::CompiledFieldData> fields;
std::map<DeviceCapability, uint32_t> required_caps;

size_t root_buffer_size;

Expand All @@ -129,7 +131,7 @@ struct ModuleData {
ts.write_to_file(path);
}

TI_IO_DEF(kernels, kernel_tmpls, fields, root_buffer_size);
TI_IO_DEF(kernels, kernel_tmpls, fields, required_caps, root_buffer_size);
};

} // namespace aot
Expand Down
5 changes: 5 additions & 0 deletions taichi/rhi/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ class Device {
dest.set_cap(k, v);
}
}
void clone_caps(std::map<DeviceCapability, uint32_t> &dest) const {
for (const auto &[k, v] : caps_) {
dest[k] = v;
}
}

void print_all_cap() const;

Expand Down
2 changes: 2 additions & 0 deletions taichi/runtime/gfx/aot_module_builder_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AotDataConverter {
res.kernels[ker.name] = val;
}
res.fields = in.fields;
res.required_caps = in.required_caps;
res.root_buffer_size = in.root_buffer_size;
return res;
}
Expand Down Expand Up @@ -110,6 +111,7 @@ AotModuleBuilderImpl::AotModuleBuilderImpl(
aot_target_device_ =
target_device ? std::move(target_device)
: std::make_unique<aot::TargetDevice>(device_api_backend_);
aot_target_device_->clone_caps(ti_aot_data_.required_caps);
if (!compiled_structs.empty()) {
ti_aot_data_.root_buffer_size = compiled_structs[0].root_size;
}
Expand Down
4 changes: 3 additions & 1 deletion taichi/runtime/gfx/aot_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vector>
#include <map>

#include "taichi/codegen/spirv/kernel_utils.h"
#include "taichi/aot/module_loader.h"
Expand All @@ -17,9 +18,10 @@ struct TaichiAotData {
std::vector<std::vector<std::vector<uint32_t>>> spirv_codes;
std::vector<spirv::TaichiKernelAttributes> kernels;
std::vector<aot::CompiledFieldData> fields;
std::map<DeviceCapability, uint32_t> required_caps;
size_t root_buffer_size{0};

TI_IO_DEF(kernels, fields, root_buffer_size);
TI_IO_DEF(kernels, fields, required_caps, root_buffer_size);
};

} // namespace gfx
Expand Down

0 comments on commit 5046716

Please sign in to comment.