Skip to content

Commit

Permalink
Added more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jim19930609 committed Jul 18, 2022
1 parent d3dfe01 commit d2622f6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
5 changes: 5 additions & 0 deletions c_api/src/c_api_test_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "c_api_test_utils.h"
#include "taichi/platform/cuda/detect_cuda.h"

#ifdef TI_WITH_VULKAN
#include "taichi/rhi/vulkan/vulkan_loader.h"
Expand All @@ -15,5 +16,9 @@ bool is_vulkan_available() {
#endif
}

bool is_cuda_available() {
return taichi::is_cuda_api_available();
}

} // namespace utils
} // namespace capi
1 change: 1 addition & 0 deletions c_api/src/c_api_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace capi {
namespace utils {

TI_DLL_EXPORT bool TI_API_CALL is_vulkan_available();
TI_DLL_EXPORT bool TI_API_CALL is_cuda_available();

} // namespace utils
} // namespace capi
71 changes: 71 additions & 0 deletions c_api/tests/c_api_interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ TEST(CapiDryRun, Runtime) {
TiRuntime runtime = ti_create_runtime(arch);
ti_destroy_runtime(runtime);
}

if (capi::utils::is_cuda_available()) {
// Vulkan Runtime
TiArch arch = TiArch::TI_ARCH_CUDA;
TiRuntime runtime = ti_create_runtime(arch);
ti_destroy_runtime(runtime);
}
}

TEST(CapiDryRun, MemoryAllocation) {
Expand All @@ -38,6 +45,28 @@ TEST(CapiDryRun, MemoryAllocation) {

ti_destroy_runtime(runtime);
}

if (capi::utils::is_vulkan_available()) {
// Vulkan Runtime
TiArch arch = TiArch::TI_ARCH_VULKAN;
TiRuntime runtime = ti_create_runtime(arch);

TiMemory memory = ti_allocate_memory(runtime, &alloc_info);
ti_free_memory(runtime, memory);

ti_destroy_runtime(runtime);
}

if (capi::utils::is_cuda_available()) {
// Cuda Runtime
TiArch arch = TiArch::TI_ARCH_CUDA;
TiRuntime runtime = ti_create_runtime(arch);

TiMemory memory = ti_allocate_memory(runtime, &alloc_info);
ti_free_memory(runtime, memory);

ti_destroy_runtime(runtime);
}
}

TEST(CapiDryRun, CpuAotModule) {
Expand All @@ -57,3 +86,45 @@ TEST(CapiDryRun, CpuAotModule) {
ti_destroy_runtime(runtime);
}
}

TEST(CapiDryRun, VulkanAotModule) {
if (capi::utils::is_vulkan_available()) {
const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH");

std::stringstream aot_mod_ss;
aot_mod_ss << folder_dir;

{
// Vulkan Runtime
TiArch arch = TiArch::TI_ARCH_VULKAN;
TiRuntime runtime = ti_create_runtime(arch);

TiAotModule aot_mod =
ti_load_aot_module(runtime, aot_mod_ss.str().c_str());
ti_destroy_aot_module(aot_mod);

ti_destroy_runtime(runtime);
}
}
}

TEST(CapiDryRun, CudaAotModule) {
if (capi::utils::is_cuda_available()) {
const auto folder_dir = getenv("TAICHI_AOT_FOLDER_PATH");

std::stringstream aot_mod_ss;
aot_mod_ss << folder_dir;

{
// Vulkan Runtime
TiArch arch = TiArch::TI_ARCH_CUDA;
TiRuntime runtime = ti_create_runtime(arch);

TiAotModule aot_mod =
ti_load_aot_module(runtime, aot_mod_ss.str().c_str());
ti_destroy_aot_module(aot_mod);

ti_destroy_runtime(runtime);
}
}
}
2 changes: 2 additions & 0 deletions tests/cpp/aot/llvm/kernel_aot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
compile_kernel_aot(arch=ti.cpu)
elif args.arch == "cuda":
compile_kernel_aot(arch=ti.cuda)
elif args.arch == "vulkan":
compile_kernel_aot(arch=ti.vulkan)
else:
assert False
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
__capi_aot_test_cases = {
"CapiDryRun.CpuAotModule":
[os.path.join('cpp', 'aot', 'llvm', 'kernel_aot_test.py'), "--arch=cpu"],
"CapiDryRun.VulkanAotModule": [
os.path.join('cpp', 'aot', 'llvm', 'kernel_aot_test.py'),
"--arch=vulkan"
],
"CapiDryRun.CudaAotModule":
[os.path.join('cpp', 'aot', 'llvm', 'kernel_aot_test.py'), "--arch=cuda"],
}


Expand Down

0 comments on commit d2622f6

Please sign in to comment.