Skip to content

Commit

Permalink
yb/fix mem leak (DeepLink-org#746)
Browse files Browse the repository at this point in the history
* fix mem leak
  • Loading branch information
yangbofun authored Dec 19, 2023
1 parent 3792185 commit be0bebb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions impl/ascend/common/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ void printContiguousTensor(diopiContextHandle_t ctx, const AscendTensor& at, cha
CALL_ACLRT(aclrtMemcpyAsync(
ptrHost, at.numel() * at.elemsize(), at.data(), at.numel() * at.elemsize(), ACL_MEMCPY_DEVICE_TO_HOST, reinterpret_cast<aclrtStream>(stream)));
CALL_ACLRT(aclrtSynchronizeStream(reinterpret_cast<aclrtStream>(stream)));
CALL_ACLRT(aclrtFreeHost(ptrHost));

} else {
const void* ptrHostCopy;
diopiGetTensorDataConst(at.tensorHandle(), &ptrHostCopy);
Expand Down
4 changes: 2 additions & 2 deletions impl/ascend_npu/torch_npu/csrc/DIOPIAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1795,8 +1795,8 @@ class OpCommandImpl {
size_t outputDataBuffArrLen = outputNum * sizeof(uintptr_t);

size_t totalMemLen = inputTensorDescArrLen + inputDataBuffArrLen + outputTensorDescArrLen + outputDataBuffArrLen;

char* basePtr = static_cast<char*>(malloc(totalMemLen));
std::unique_ptr<char, void (*)(void*)> basePtrUnique((char*)malloc(totalMemLen), free);
char* basePtr = basePtrUnique.get();
AT_ASSERT(basePtr != nullptr);
const aclTensorDesc** aclTensorInputDescArr = reinterpret_cast<const aclTensorDesc**>(basePtr);
basePtr += inputTensorDescArrLen;
Expand Down

0 comments on commit be0bebb

Please sign in to comment.