Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix NDArray ToDLPack Bug #13698

Merged
merged 2 commits into from
Dec 21, 2018
Merged
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
5 changes: 2 additions & 3 deletions src/ndarray/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,10 @@ struct NDArrayDLManager {
};

DLManagedTensor* NDArray::ToDLPack() const {
CHECK(!is_none()) << "NDArray is not initialized";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm. Such check should never fail as ToDLPack will only be called after wait_to_read or wait_to_write so the NDArray should always be initialized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But when users use C++ API directly, they may forget to call WaitToRead or WaitToWrite before calling ToDLPack.

NDArrayDLManager* dlmanager(new NDArrayDLManager);
dlmanager->handle = *this;
if (!is_none()) {
dlmanager->tensor.dl_tensor = data().dltensor();
}
dlmanager->tensor.dl_tensor = dlmanager->handle.data().dltensor();
dlmanager->tensor.manager_ctx = dlmanager;
dlmanager->tensor.deleter = [](DLManagedTensor* dlmanager){
delete static_cast<NDArrayDLManager*>(dlmanager->manager_ctx);
Expand Down