diff --git a/torch_npu/csrc/aten/common/ResizeNpu.h b/torch_npu/csrc/aten/common/ResizeNpu.h index c063534bc18a30ff958677e2e4ac07879929c200..c771679130337df3dcf45f29f1d43968feed9379 100644 --- a/torch_npu/csrc/aten/common/ResizeNpu.h +++ b/torch_npu/csrc/aten/common/ResizeNpu.h @@ -34,6 +34,9 @@ static void storage_resize_npu( } at::DataPtr new_data = storage.allocator()->allocate(size); + if (size > 0) { + TORCH_CHECK(new_data, "Get new_data failed", PTA_ERROR(ErrCode::PARAM)); + } size_t itemsize = storage_desc.data_type_.itemsize(); at::DataPtr old_data = storage.set_data_ptr(std::move(new_data)); ptrdiff_t old_size = static_cast(storage.nbytes()); diff --git a/torch_npu/csrc/core/NPUStorageImpl.cpp b/torch_npu/csrc/core/NPUStorageImpl.cpp index 1dbd9da08df41a333164eb29bb60ced2debb1eb8..4d11f506fe683d45ea3927dac2383ac0b489ca48 100644 --- a/torch_npu/csrc/core/NPUStorageImpl.cpp +++ b/torch_npu/csrc/core/NPUStorageImpl.cpp @@ -34,6 +34,9 @@ c10::intrusive_ptr make_npu_storage_impl( { if (data_ptr == nullptr) { data_ptr = allocator->allocate(size_bytes.as_int_unchecked()); + if (size_bytes.as_int_unchecked() > 0) { + TORCH_CHECK(data_ptr, "Get data_ptr failed", PTA_ERROR(ErrCode::PARAM)); + } } // Correctly create NPUStorageImpl object. c10::intrusive_ptr npu_storage_impl = c10::make_intrusive( diff --git a/torch_npu/csrc/distributed/rpc/tensorpipe_npu.cpp b/torch_npu/csrc/distributed/rpc/tensorpipe_npu.cpp index c83bcbdabe282100904caa3378cb69d8c7db3b1c..888f1fcb1a18675e2fd56d0c9b77c3394ed083ae 100644 --- a/torch_npu/csrc/distributed/rpc/tensorpipe_npu.cpp +++ b/torch_npu/csrc/distributed/rpc/tensorpipe_npu.cpp @@ -60,6 +60,9 @@ public: // stream. c10_npu::NPUStreamGuard guard(stream); at::DataPtr dataPtr = c10_npu::NPUCachingAllocator::get()->allocate(length); + if (length > 0) { + TORCH_CHECK(dataPtr, "Get dataPtr failed", PTA_ERROR(ErrCode::PARAM)); + } tensorpipe_npu::NPUBuffer buffer; buffer.ptr = dataPtr.get(); diff --git a/torch_npu/csrc/distributed/rpc/tensorpipe_utils.cpp b/torch_npu/csrc/distributed/rpc/tensorpipe_utils.cpp index 0f6cd5e6c252283e21f2b3bc2c54b994cc9b1814..d3695aa3aa47efed1c597a73125ec42409290365 100644 --- a/torch_npu/csrc/distributed/rpc/tensorpipe_utils.cpp +++ b/torch_npu/csrc/distributed/rpc/tensorpipe_utils.cpp @@ -80,6 +80,9 @@ public: tensorpipe_npu::Allocation &allocation) const override { at::DataPtr dataPtr = at::getCPUAllocator()->allocate(length); + if (length > 0) { + TORCH_CHECK(dataPtr, "Get dataPtr failed", PTA_ERROR(ErrCode::PARAM)); + } tensorpipe_npu::CpuBuffer buffer; buffer.ptr = dataPtr.get();