Skip to content

Commit 988eb9d

Browse files
committed
feat(tensor): add memory destruction check mechanism during tensor destruction
- Added a mechanism to check if the memory has been destroyed during tensor destruction. - This mechanism prevents repeated memory destruction, enhancing memory management reliability. - Ensures that memory resources are properly handled and reduces the risk of memory - related errors.
1 parent f7cfd14 commit 988eb9d

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Tensor.cu

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,15 @@ namespace nz::data {
208208
}
209209

210210
Tensor::~Tensor() noexcept(false) {
211-
cuStrm::StreamManager<value_type>::Instance().free(_data);
211+
if (_data != nullptr) {
212+
cuStrm::StreamManager<value_type>::Instance().freeAsync(_data);
213+
_data = nullptr;
214+
}
212215
if (_requires_grad) {
213-
cuStrm::StreamManager<value_type>::Instance().free(_grad);
216+
if (_grad != nullptr) {
217+
cuStrm::StreamManager<value_type>::Instance().freeAsync(_grad);
218+
_grad = nullptr;
219+
}
214220
}
215221
}
216222

0 commit comments

Comments
 (0)