这是indexloc提供的服务,不要输入任何密码
Skip to content

Avoid heap allocation for the sub buffer address #97230

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

Merged
merged 1 commit into from
Jul 21, 2025
Merged
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
13 changes: 6 additions & 7 deletions third_party/xla/xla/pjrt/gpu/tfrt/tfrt_gpu_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3004,12 +3004,11 @@ PjRtFuture<> TfrtGpuBuffer::CopyRawToHostFuture(PjRtFuture<void*> dst_future,
return;
}

std::unique_ptr<se::DeviceMemoryBase> sub_buffer;
se::DeviceMemoryBase sub_buffer;
if (transfer_size < device_memory.size()) {
sub_buffer = std::make_unique<se::DeviceMemoryBase>(
device_memory.GetByteSlice(offset, transfer_size));
sub_buffer = device_memory.GetByteSlice(offset, transfer_size);
} else {
sub_buffer = std::make_unique<se::DeviceMemoryBase>(device_memory);
sub_buffer = device_memory;
}

HostMemoryAllocator::OwnedPtr staging_buffer;
Expand All @@ -3024,9 +3023,9 @@ PjRtFuture<> TfrtGpuBuffer::CopyRawToHostFuture(PjRtFuture<void*> dst_future,

auto stream = device->stream();

VLOG(3) << "D2H copy: " << sub_buffer->opaque() << " -> " << host_ptr
<< " (" << transfer_size << " bytes)";
absl::Status status = stream->Memcpy(host_ptr, *sub_buffer, transfer_size);
VLOG(3) << "D2H copy: " << sub_buffer.opaque() << " -> " << host_ptr << " ("
<< transfer_size << " bytes)";
absl::Status status = stream->Memcpy(host_ptr, sub_buffer, transfer_size);
if (!status.ok()) {
LOG(ERROR) << "stream->Memcpy failed: " << status;
promise.Set(status);
Expand Down