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

[llvm] [aot] Add LLVM to CAPI part 8: Added CGraph tests for LLVM backend in C-API #5456

Merged
merged 20 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0d7d2d7
[build] Enabled C-API compilation on CI
jim19930609 Jul 12, 2022
6e03f9c
Fixed minor issue
jim19930609 Jul 13, 2022
d890dee
Enabled CAPI compilation on windows build bots
jim19930609 Jul 13, 2022
630b4ba
Fixed minor issue
jim19930609 Jul 13, 2022
184a660
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 13, 2022
2b51bc3
Removed LLVM-15 test on windows
jim19930609 Jul 13, 2022
ef9519f
[llvm] [aot] Add LLVM to CAPI part 4: Enabled C-API tests on CI & Add…
jim19930609 Jul 14, 2022
59c81e4
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 14, 2022
cdb7257
Removed debug info
jim19930609 Jul 14, 2022
f08033f
Fixed CI issues
jim19930609 Jul 14, 2022
4b13d88
Added C-API tests for LLVM-CPU backend
jim19930609 Jul 15, 2022
33f3c63
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 17, 2022
d36b62d
[llvm] [aot] Add LLVM to CAPI part 5: Added C-API tests for Vulkan ba…
jim19930609 Jul 18, 2022
c9722ab
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 18, 2022
d3dfe01
Minor bug fix
jim19930609 Jul 18, 2022
d2622f6
Added more test cases
jim19930609 Jul 18, 2022
69315ad
[llvm] [aot] Add LLVM to CAPI part 7: Added AOT kernel tests for LLVM…
jim19930609 Jul 18, 2022
8668fe0
[llvm] [aot] Add LLVM to CAPI part 7: Added CGraph tests for LLVM bac…
jim19930609 Jul 19, 2022
a9d3dc3
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 19, 2022
c2ab9dd
Merge branch 'master' of github.com:taichi-dev/taichi into llvm_aot_c…
jim19930609 Jul 19, 2022
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
2 changes: 2 additions & 0 deletions c_api/src/taichi_core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ void ti_destroy_aot_module(TiAotModule mod) {

delete (AotModule *)mod;
}

TiKernel ti_get_aot_module_kernel(TiAotModule mod, const char *name) {
if (mod == nullptr) {
TI_WARN("ignored attempt to get kernel from aot module of null handle");
return TI_NULL_HANDLE;
}
return (TiKernel)((AotModule *)mod)->get().get_kernel(name);
}

TiComputeGraph ti_get_aot_module_compute_graph(TiAotModule mod,
const char *name) {
if (mod == nullptr) {
Expand Down
4 changes: 2 additions & 2 deletions c_api/tests/c_api_aot_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void kernel_aot_test(TiArch arch) {
.value = std::move(arg_value)};

// Kernel Execution
uint32_t arg_count = 2;
TiArgument args[2] = {std::move(arg0), std::move(arg1)};
constexpr uint32_t arg_count = 2;
TiArgument args[arg_count] = {std::move(arg0), std::move(arg1)};

ti_launch_kernel(runtime, k_run, arg_count, &args[0]);

Expand Down
90 changes: 90 additions & 0 deletions c_api/tests/c_api_cgraph_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "gtest/gtest.h"
#include "c_api_test_utils.h"
#include "taichi/taichi_core.h"

void graph_aot_test(TiArch arch) {
uint32_t kArrLen = 100;
int base0_val = 10;
int base1_val = 20;
int base2_val = 30;

const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH");

std::stringstream aot_mod_ss;
aot_mod_ss << folder_dir;

TiMemoryAllocateInfo alloc_info;
alloc_info.size = kArrLen * sizeof(int32_t);
alloc_info.host_write = false;
alloc_info.host_read = false;
alloc_info.export_sharing = false;
alloc_info.usage = TiMemoryUsageFlagBits::TI_MEMORY_USAGE_STORAGE_BIT;

TiRuntime runtime = ti_create_runtime(arch);

// Load Aot and Kernel
TiAotModule aot_mod = ti_load_aot_module(runtime, aot_mod_ss.str().c_str());
TiComputeGraph run_graph =
ti_get_aot_module_compute_graph(aot_mod, "run_graph");

// Prepare Arguments
// base0
TiArgument base0_arg = {.type = TiArgumentType::TI_ARGUMENT_TYPE_I32,
.value = {.i32 = base0_val}};
TiNamedArgument base0_named_arg = {.name = "base0", .argument = base0_arg};

// base1
TiArgument base1_arg = {.type = TiArgumentType::TI_ARGUMENT_TYPE_I32,
.value = {.i32 = base1_val}};
TiNamedArgument base1_named_arg = {.name = "base1", .argument = base1_arg};

// base2
TiArgument base2_arg = {.type = TiArgumentType::TI_ARGUMENT_TYPE_I32,
.value = {.i32 = base2_val}};
TiNamedArgument base2_named_arg = {.name = "base2", .argument = base2_arg};

// arr
TiMemory arr_memory = ti_allocate_memory(runtime, &alloc_info);
TiNdArray arr_array = {.memory = arr_memory,
.shape = {.dim_count = 1, .dims = {kArrLen}},
.elem_shape = {.dim_count = 1, .dims = {1}},
.elem_type = TiDataType::TI_DATA_TYPE_I32};
TiArgumentValue arr_value = {.ndarray = std::move(arr_array)};
TiArgument arr_arg = {.type = TiArgumentType::TI_ARGUMENT_TYPE_NDARRAY,
.value = std::move(arr_value)};
TiNamedArgument arr_named_arg = {.name = "arr", .argument = arr_arg};

// Kernel Execution
constexpr uint32_t arg_count = 4;
TiNamedArgument named_args[arg_count] = {
std::move(base0_named_arg),
std::move(base1_named_arg),
std::move(base2_named_arg),
std::move(arr_named_arg),
};

ti_launch_compute_graph(runtime, run_graph, arg_count, &named_args[0]);

// Check Results
auto *data = reinterpret_cast<int32_t *>(ti_map_memory(runtime, arr_memory));

for (int i = 0; i < kArrLen; i++) {
EXPECT_EQ(data[i], 3 * i + base0_val + base1_val + base2_val);
}

ti_unmap_memory(runtime, arr_memory);
ti_destroy_aot_module(aot_mod);
ti_destroy_runtime(runtime);
}

TEST(CapiGraphTest, CpuGraph) {
TiArch arch = TiArch::TI_ARCH_X64;
graph_aot_test(arch);
}

TEST(CapiGraphTest, CudaGraph) {
if (capi::utils::is_cuda_available()) {
TiArch arch = TiArch::TI_ARCH_CUDA;
graph_aot_test(arch);
}
}
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
}

__capi_aot_test_cases = {
"CapiGraphTest.CpuGraph":
[os.path.join('cpp', 'aot', 'llvm', 'graph_aot_test.py'), "--arch=cpu"],
"CapiGraphTest.CudaGraph":
[os.path.join('cpp', 'aot', 'llvm', 'graph_aot_test.py'), "--arch=cuda"],
"CapiAotTest.CpuKernel":
[os.path.join('cpp', 'aot', 'llvm', 'kernel_aot_test.py'), "--arch=cpu"],
"CapiAotTest.CudaKernel":
Expand Down