Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not use raw pointer for CpuBuffersInfo::buffers #14574

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
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 onnxruntime/core/providers/cuda/cuda_stream_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct CpuBuffersInfo {
// should contain all values in
// deferred_release_buffer_pool_[my_stream]
// when release my_stream's buffers.
void** buffers;
std::unique_ptr<void*[]> buffers;
// CPU buffer buffers[i].
// Number of buffer points in "buffers".
size_t n_buffers;
Expand All @@ -117,7 +117,6 @@ static void CUDART_CB ReleaseCpuBufferCallback(void* raw_info) {
for (size_t i = 0; i < info->n_buffers; ++i) {
info->allocator->Free(info->buffers[i]);
}
delete[] info->buffers;
}

Status CudaStream::CleanUpOnRunEnd() {
Expand All @@ -128,7 +127,7 @@ Status CudaStream::CleanUpOnRunEnd() {
if (release_cpu_buffer_on_cuda_stream_ && cpu_allocator_->Info().alloc_type == OrtArenaAllocator) {
std::unique_ptr<CpuBuffersInfo> cpu_buffers_info = std::make_unique<CpuBuffersInfo>();
cpu_buffers_info->allocator = cpu_allocator_;
cpu_buffers_info->buffers = new void*[deferred_cpu_buffers_.size()];
cpu_buffers_info->buffers = std::make_unique<void*[]>(deferred_cpu_buffers_.size());
for (size_t i = 0; i < deferred_cpu_buffers_.size(); ++i) {
cpu_buffers_info->buffers[i] = deferred_cpu_buffers_.at(i);
}
Expand Down
5 changes: 2 additions & 3 deletions onnxruntime/core/providers/rocm/rocm_stream_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void RocmStream::EnqueDeferredCPUBuffer(void* cpu_buffer) {

struct CpuBuffersInfo { // TODO: should be moved to base class
AllocatorPtr allocator;
void** buffers;
std::unique_ptr<void*[]> buffers;
// CPU buffer buffers[i].
// Number of buffer points in "buffers".
size_t n_buffers;
Expand All @@ -95,7 +95,6 @@ static void ReleaseCpuBufferCallback(hipStream_t /*stream*/, hipError_t /*status
for (size_t i = 0; i < info->n_buffers; ++i) {
info->allocator->Free(info->buffers[i]);
}
delete[] info->buffers;
}

Status RocmStream::CleanUpOnRunEnd() {
Expand All @@ -106,7 +105,7 @@ Status RocmStream::CleanUpOnRunEnd() {
if (release_cpu_buffer_on_rocm_stream_ && cpu_allocator_->Info().alloc_type == OrtArenaAllocator) {
std::unique_ptr<CpuBuffersInfo> cpu_buffers_info = std::make_unique<CpuBuffersInfo>();
cpu_buffers_info->allocator = cpu_allocator_;
cpu_buffers_info->buffers = new void*[deferred_cpu_buffers_.size()];
cpu_buffers_info->buffers = std::make_unique<void*[]>(deferred_cpu_buffers_.size());
for (size_t i = 0; i < deferred_cpu_buffers_.size(); ++i) {
cpu_buffers_info->buffers[i] = deferred_cpu_buffers_.at(i);
}
Expand Down