Skip to content

Commit

Permalink
[aot] Fixed C-API behavior tests (taichi-dev#6939)
Browse files Browse the repository at this point in the history
Fixed allocation leakage, unchecked values, camel cases and
uninitialized structs in behavior tests. Reflected in codes, this PR has
done the following:

1. Use lifetime guarded C++ wrapper for usage that are *not* the tested
interface.
2. Removed several *success* tests that might overlap with those in
other tests. (This is not done completely, will make another PR to
refactorize that.)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and quadpixels committed May 13, 2023
1 parent 529f0c8 commit 9ea9962
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 311 deletions.
22 changes: 22 additions & 0 deletions c_api/include/taichi/cpp/taichi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ class Memory {
unmap();
}

TiMemorySlice slice(size_t offset, size_t size) const {
if (offset + size > size_) {
ti_set_last_error(TI_ERROR_ARGUMENT_OUT_OF_RANGE, "size");
return {};
}
TiMemorySlice slice{};
slice.memory = memory_;
slice.offset = offset;
slice.size = size;
return slice;
}
TiMemorySlice slice() const {
return slice(0, size_);
}

constexpr size_t size() const {
return size_;
}
Expand Down Expand Up @@ -271,6 +286,13 @@ class NdArray {
write((const T *)src.data(), src.size() * (sizeof(U) / sizeof(T)));
}

TiMemorySlice slice(size_t offset, size_t size) const {
return memory_.slice(offset, size);
}
TiMemorySlice slice() const {
return memory_.slice();
}

constexpr TiDataType elem_type() const {
return ndarray_.elem_type;
}
Expand Down
Loading

0 comments on commit 9ea9962

Please sign in to comment.