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

PR #15311: [ROCm] GPU/CPU unified memory for rocm #31

Merged
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
28 changes: 22 additions & 6 deletions xla/stream_executor/rocm/rocm_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,16 +1338,32 @@ struct BitPatternToValue {
/* static */ void* GpuDriver::UnifiedMemoryAllocate(GpuContext* context,
uint64_t bytes) {
ScopedActivateContext activated{context};

LOG(ERROR)
<< "Feature not supported on ROCm platform (UnifiedMemoryAllocate)";
return nullptr;
hipDeviceptr_t result = 0;
// "managed" memory is visible to both CPU and GPU.
hipError_t res = wrap::hipMallocManaged(&result, bytes, hipMemAttachGlobal);
if (res != hipSuccess) {
LOG(ERROR) << "failed to alloc " << bytes
<< " bytes unified memory; result: " << ToString(res);
return nullptr;
}
void* ptr = reinterpret_cast<void*>(result);
VLOG(2) << "allocated " << ptr << " for context " << context->context()
<< " of " << bytes << " bytes in unified memory";
return ptr;
}

/* static */ void GpuDriver::UnifiedMemoryDeallocate(GpuContext* context,
void* location) {
LOG(ERROR)
<< "Feature not supported on ROCm platform (UnifiedMemoryDeallocate)";
ScopedActivateContext activation(context);
hipDeviceptr_t pointer = absl::bit_cast<hipDeviceptr_t>(location);
hipError_t res = wrap::hipFree(pointer);
if (res != hipSuccess) {
LOG(ERROR) << "failed to free unified memory at " << location
<< "; result: " << ToString(res);
} else {
VLOG(2) << "deallocated unified memory at " << location << " for context "
<< context->context();
}
}

/* static */ void* GpuDriver::HostAllocate(GpuContext* context,
Expand Down
1 change: 1 addition & 0 deletions xla/stream_executor/rocm/rocm_driver_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace wrap {
__macro(hipLaunchHostFunc) \
__macro(hipLaunchKernel) \
__macro(hipMalloc) \
__macro(hipMallocManaged) \
__macro(hipMemGetAddressRange) \
__macro(hipMemGetInfo) \
__macro(hipMemcpyDtoD) \
Expand Down
Loading