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] Fixed C-API behavior tests #6939

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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