Skip to content

Commit

Permalink
[Redo][ATen] Remove AT_ASSERTM from Blob::free_() (pytorch#34168)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#34168

Redo D19153199. It was reverted because it broke CI, due to the change of `AT_ASSERTM` to `TORCH_INTERNAL_ASSERT_DEBUG_ONLY`. Two problems:
1) bug in `TORCH_INTERNAL_ASSERT_DEBUG_ONLY` about MSVC. I'm sending another diff to fix this bug.
2) BlobTest was expecting `Blob::template Get<T>()` to throw when there is a type mismatch.

For now I'll leave `AT_ASSERTM` as it is.

Test Plan:
```
buck test mode/dev //caffe2/caffe2:caffe2_test_cpu -- 'BlobTest' --run-disabled
buck test mode/opt //caffe2/caffe2:caffe2_test_cpu -- 'BlobTest' --run-disabled
```

Reviewed By: yinghai

Differential Revision: D20235225

fbshipit-source-id: 594dad97c03c419afaa8f9023408bc5a119b3cfa
  • Loading branch information
Hao Lu authored and facebook-github-bot committed Mar 4, 2020
1 parent 31cc311 commit a19db54
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions aten/src/ATen/core/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ class CAFFE2_API Blob final : public c10::intrusive_ptr_target {
TypeMeta::Make<typename std::remove_const<T>::type>()));
}

// TODO Remove ShareExternal() and have Blob always own its content
void* ShareExternal(void* allocated, const TypeMeta& meta) {
free_();
meta_ = meta;
pointer_ = static_cast<void*>(allocated);
pointer_ = allocated;
has_ownership_ = false;
return allocated;
}
Expand All @@ -186,15 +185,14 @@ class CAFFE2_API Blob final : public c10::intrusive_ptr_target {

private:
void free_() {
if (has_ownership_) {
AT_ASSERTM(pointer_ != nullptr, "Can't have ownership of nullptr");
if (has_ownership_ && pointer_ != nullptr) {
(*meta_.deleteFn())(pointer_);
}
}

TypeMeta meta_;
void* pointer_ = nullptr;
bool has_ownership_ = false;
void* pointer_;
bool has_ownership_;

C10_DISABLE_COPY_AND_ASSIGN(Blob);
};
Expand Down

0 comments on commit a19db54

Please sign in to comment.