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] C_API behavior test #6904

Merged
merged 45 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e669537
test_to_allocMemory
damnkk Dec 7, 2022
77f81fa
MapMemory
damnkk Dec 7, 2022
fa98a3c
testAllocate/freeImage
damnkk Dec 8, 2022
2c5a422
testToDstEvent
damnkk Dec 8, 2022
baa92b8
Remove debug code
damnkk Dec 12, 2022
0c058f8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2022
988a7a5
step
damnkk Dec 12, 2022
933a5ba
step
damnkk Dec 12, 2022
7a08028
Update setup.py
damnkk Dec 12, 2022
0957164
up
damnkk Dec 12, 2022
cbd5c90
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2022
fa30516
up
damnkk Dec 12, 2022
4658a1f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2022
ecfb2ae
up
damnkk Dec 12, 2022
3bdddf4
u
damnkk Dec 12, 2022
bf09454
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2022
8e75f54
reModify
damnkk Dec 13, 2022
ab0ffda
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2022
0b9f6aa
reModify
damnkk Dec 13, 2022
26fd593
reModify
damnkk Dec 13, 2022
2f45d88
reModity
damnkk Dec 13, 2022
3d3a8b0
reModify
damnkk Dec 13, 2022
33fa41c
reModify
damnkk Dec 13, 2022
2e8d369
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2022
1a86471
remodify
damnkk Dec 13, 2022
b4fd596
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2022
a151b98
reModify
damnkk Dec 13, 2022
2d3fe14
reModify
damnkk Dec 13, 2022
486d725
Merge branch 'taichi-dev:master' into c_api_test1
damnkk Dec 14, 2022
d7636da
remodify
damnkk Dec 14, 2022
651d62c
reModify
damnkk Dec 14, 2022
769269d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 14, 2022
bf54e92
final_test
damnkk Dec 15, 2022
c0de4e1
Merge branch 'master' into c_api_test1
damnkk Dec 15, 2022
55c8c8c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2022
9044d7a
final_test
damnkk Dec 15, 2022
89b401e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2022
6d6c2a1
final_test
damnkk Dec 15, 2022
e4afea9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 15, 2022
f6e397c
step
damnkk Dec 17, 2022
6a12eac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 17, 2022
f8b99c9
Merge branch 'master' into c_api_test1
damnkk Dec 20, 2022
f90c117
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 2022
e1916e8
step
damnkk Dec 20, 2022
f4758f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 20, 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 @@ -81,6 +81,8 @@ const char *describe_error(TiError error) {
return "invalid state";
case TI_ERROR_INCOMPATIBLE_MODULE:
return "incompatible module";
case TI_ERROR_OUT_OF_MEMORY:
return "out of memory";
default:
return "unknown error";
}
Expand Down
100 changes: 71 additions & 29 deletions c_api/tests/c_api_behavior_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,81 @@ TEST_F(CapiTest, TestBehaviorGetRuntimeCapabilities) {

TEST_F(CapiTest, TestBehaviorAllocateMemory) {
auto inner = [&](TiArch arch) {
if (ti::is_arch_available(arch)) {
// Attempt to allocate memory with size of 1024
TiRuntime runtime = ti_create_runtime(arch);
for (int i = 0; i < 4; ++i) {
TiMemoryAllocateInfo allocate_info;
allocate_info.size = 1024;
allocate_info.usage = TI_MEMORY_USAGE_STORAGE_BIT << i;
TiMemory memory = ti_allocate_memory(runtime, &allocate_info);
TI_ASSERT(memory != TI_NULL_HANDLE);
ti_free_memory(runtime, memory);
}
if (!ti::is_arch_available(arch)) {
TI_WARN("arch {} is not supported, so this test is skipped", arch);
return;
}
damnkk marked this conversation as resolved.
Show resolved Hide resolved
// Attempt to allocate memory with size of 1024
TiRuntime runtime = ti_create_runtime(arch);
damnkk marked this conversation as resolved.
Show resolved Hide resolved
TiMemoryAllocateInfo allocateInfo;
allocateInfo.size = 1024;
allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT;
TiMemory memory = ti_allocate_memory(runtime, &allocateInfo);
TI_ASSERT(memory != TI_NULL_HANDLE);
ti_free_memory(runtime, memory);
ti_destroy_runtime(runtime);
};
inner(TI_ARCH_VULKAN);
}

// runtime and allocate_info are both null
{
ti_allocate_memory(TI_NULL_HANDLE, nullptr);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
}
TEST_F(CapiTest, TestBehaviorAllocInvalidMemory) {
auto inner = [&](TiArch arch) {
if (!ti::is_arch_available(arch)) {
TI_WARN("arch {} is not supported, so this test is skipped", arch);
return;
}
// Attemp to run out of memory
TiRuntime runtime = ti_create_runtime(arch);
TiMemoryAllocateInfo allocateInfo;
allocateInfo.size = 1000000000000000000;
allocateInfo.usage = TI_MEMORY_USAGE_STORAGE_BIT;
TiMemory memory = ti_allocate_memory(runtime, &allocateInfo);
EXPECT_TAICHI_ERROR(TI_ERROR_OUT_OF_MEMORY);
TI_ASSERT(memory == TI_NULL_HANDLE);
ti_destroy_runtime(runtime);
};
inner(TI_ARCH_VULKAN);
}

// runtime is not null, allocate_info is null
{
ti_allocate_memory(runtime, nullptr);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
}
TEST_F(CapiTest, TestBehaviorAllocMemoryNoArg) {
auto inner = [&](TiArch arch) {
if (!ti::is_arch_available(arch)) {
TI_WARN("arch {} is not supported, so this test is skipped", arch);
return;
}
// runtime and allocate_info are both null
ti_allocate_memory(TI_NULL_HANDLE, nullptr);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
};
inner(TI_ARCH_VULKAN);
}

// runtime is null, allocate is not null;
{
TiMemoryAllocateInfo allocate_info;
allocate_info.size = 1024;
ti_allocate_memory(TI_NULL_HANDLE, &allocate_info);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
}
ti_destroy_runtime(runtime);
TEST_F(CapiTest, TestBehaviorAllocMemoryNoAllocInfo) {
auto inner = [&](TiArch arch) {
if (!ti::is_arch_available(arch)) {
TI_WARN("arch {} is not supported, so this test is skipped", arch);
return;
}
// runtime is not null, allocate_info is null
TiRuntime runtime = ti_create_runtime(arch);
ti_allocate_memory(runtime, nullptr);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
ti_destroy_runtime(runtime);
};
inner(TI_ARCH_VULKAN);
}

TEST_F(CapiTest, TestBehaviorAllocMemoryNoRuntime) {
auto inner = [&](TiArch arch) {
if (!ti::is_arch_available(arch)) {
TI_WARN("arch {} is not supported, so this test is skipped", arch);
return;
}
// runtime is null, allocate is not null;
TiMemoryAllocateInfo allocateInfo;
allocateInfo.size = 1024;
ti_allocate_memory(TI_NULL_HANDLE, &allocateInfo);
EXPECT_TAICHI_ERROR(TI_ERROR_ARGUMENT_NULL);
};
inner(TI_ARCH_VULKAN);
}
Expand Down
4 changes: 3 additions & 1 deletion taichi/rhi/vulkan/vulkan_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ IVkBuffer create_buffer(VkDevice device,

VkResult res = vmaCreateBuffer(allocator, buffer_info, alloc_info,
&buffer->buffer, &buffer->allocation, nullptr);
assert(res != VK_ERROR_OUT_OF_DEVICE_MEMORY);
if (res == VK_ERROR_OUT_OF_DEVICE_MEMORY) {
PENGUINLIONG marked this conversation as resolved.
Show resolved Hide resolved
throw std::bad_alloc();
} // FIXME: (damnkk) Should be removed when RHI error codes are ready
BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create buffer");

return buffer;
Expand Down