Skip to content

Commit

Permalink
Fixed C-API behavior tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PENGUINLIONG committed Dec 21, 2022
1 parent 19fce81 commit c01cf5a
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 362 deletions.
76 changes: 22 additions & 54 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 Expand Up @@ -663,60 +685,6 @@ class AotModule {
}
};

class Event {
TiRuntime runtime_{TI_NULL_HANDLE};
TiEvent event_{TI_NULL_HANDLE};
bool should_destroy_{false};

public:
constexpr bool is_valid() const {
return event_ != nullptr;
}
inline void destroy() {
if (should_destroy_) {
ti_destroy_event(event_);
event_ = TI_NULL_HANDLE;
should_destroy_ = false;
}
}

Event() {
}
Event(const Event &) = delete;
Event(Event &&b) : event_(b.event_), should_destroy_(b.should_destroy_) {
}
Event(TiRuntime runtime, TiEvent event, bool should_destroy)
: runtime_(runtime), event_(event), should_destroy_(should_destroy) {
}
~Event() {
destroy();
}

Event &operator=(const Event &) = delete;
Event &operator=(Event &&b) {
event_ = detail::move_handle(b.event_);
should_destroy_ = std::exchange(b.should_destroy_, false);
return *this;
}

void reset(TiEvent event_) {
ti_reset_event(runtime_, event_);
}
void signal(TiEvent event_) {
ti_signal_event(runtime_, event_);
}
void wait(TiEvent event_) {
ti_wait_event(runtime_, event_);
}

constexpr TiEvent event() const {
return event_;
}
constexpr operator TiEvent() const {
return event_;
}
};

class CapabilityLevelConfigBuilder;
class CapabilityLevelConfig {
public:
Expand Down
Loading

0 comments on commit c01cf5a

Please sign in to comment.