From a2cf898dbafaf8abae5ed7ecdcad38b4c71aa590 Mon Sep 17 00:00:00 2001 From: Kyle Lucke Date: Sun, 13 Oct 2024 08:46:28 -0700 Subject: [PATCH] Move GpuDriver HostRegister & Unregister into CudaExecutor. PiperOrigin-RevId: 685439655 --- .../xla/stream_executor/cuda/cuda_driver.cc | 25 ------------------- .../xla/stream_executor/cuda/cuda_executor.cc | 20 +++++++++++++-- .../xla/xla/stream_executor/gpu/gpu_driver.h | 16 ------------ 3 files changed, 18 insertions(+), 43 deletions(-) diff --git a/third_party/xla/xla/stream_executor/cuda/cuda_driver.cc b/third_party/xla/xla/stream_executor/cuda/cuda_driver.cc index a60f92165fb0e8..88b955ba05521b 100644 --- a/third_party/xla/xla/stream_executor/cuda/cuda_driver.cc +++ b/third_party/xla/xla/stream_executor/cuda/cuda_driver.cc @@ -808,31 +808,6 @@ void GpuDriver::HostDeallocate(Context* context, void* location) { } } -bool GpuDriver::HostRegister(Context* context, void* location, uint64_t bytes) { - ScopedActivateContext activation(context); - // "Portable" memory is visible to all CUDA contexts. Safe for our use model. - auto status = cuda::ToStatus( - cuMemHostRegister(location, bytes, CU_MEMHOSTREGISTER_PORTABLE)); - if (!status.ok()) { - LOG(ERROR) << "error registering host memory at " << location << ": " - << status; - return false; - } - return true; -} - -bool GpuDriver::HostUnregister(Context* context, void* location) { - ScopedActivateContext activation(context); - auto status = cuda::ToStatus(cuMemHostUnregister(location)); - if (!status.ok()) { - LOG(ERROR) << "error unregistering host memory at " << location << ": " - << status; - return false; - } - return true; -} - - absl::Status GpuDriver::SynchronizeStream(Context* context, CUstream stream) { ScopedActivateContext activated{context}; CHECK(stream != nullptr); diff --git a/third_party/xla/xla/stream_executor/cuda/cuda_executor.cc b/third_party/xla/xla/stream_executor/cuda/cuda_executor.cc index bf156a555d7552..3ed5da5318b9f3 100644 --- a/third_party/xla/xla/stream_executor/cuda/cuda_executor.cc +++ b/third_party/xla/xla/stream_executor/cuda/cuda_executor.cc @@ -906,13 +906,29 @@ bool CudaExecutor::HostMemoryRegister(void* location, uint64_t size) { VLOG(1) << "Called StreamExecutor::HostMemoryRegister(data=" << location << ")"; - return GpuDriver::HostRegister(gpu_context(), location, size); + ScopedActivateContext activation(gpu_context()); + // "Portable" memory is visible to all CUDA contexts. Safe for our use model. + auto status = cuda::ToStatus( + cuMemHostRegister(location, size, CU_MEMHOSTREGISTER_PORTABLE)); + if (!status.ok()) { + LOG(ERROR) << "error registering host memory at " << location << ": " + << status; + return false; + } + return true; } bool CudaExecutor::HostMemoryUnregister(void* location) { VLOG(1) << "Called StreamExecutor::HostUnregister(data=" << location << ")"; - return GpuDriver::HostUnregister(gpu_context(), location); + ScopedActivateContext activation(gpu_context()); + auto status = cuda::ToStatus(cuMemHostUnregister(location)); + if (!status.ok()) { + LOG(ERROR) << "error unregistering host memory at " << location << ": " + << status; + return false; + } + return true; } absl::Status CudaExecutor::SynchronousMemZero(DeviceMemoryBase* location, diff --git a/third_party/xla/xla/stream_executor/gpu/gpu_driver.h b/third_party/xla/xla/stream_executor/gpu/gpu_driver.h index 329b6349187642..5ccc4b75fc558a 100644 --- a/third_party/xla/xla/stream_executor/gpu/gpu_driver.h +++ b/third_party/xla/xla/stream_executor/gpu/gpu_driver.h @@ -81,22 +81,6 @@ class GpuDriver { // https://rocm.docs.amd.com/projects/HIPIFY/en/latest/tables/CUDA_Driver_API_functions_supported_by_HIP.html#memory-management static void HostDeallocate(Context* context, void* location); - // Registers a memory region at location of size bytes via - // cuMemHostRegister/hipHostRegister. - // http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1gf0a9fe11544326dabd743b7aa6b54223 - // https://rocm.docs.amd.com/projects/HIPIFY/en/latest/tables/CUDA_Driver_API_functions_supported_by_HIP.html#memory-management - static bool HostRegister(Context* context, void* location, uint64_t bytes); - - // Unregisters a memory region that was previously registered at location via - // cuMemHostUnregister/hipHostUnregister. - // - // http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__MEM.html#group__CUDA__MEM_1g63f450c8125359be87b7623b1c0b2a14 - // https://rocm.docs.amd.com/projects/HIPIFY/en/latest/tables/CUDA_Driver_API_functions_supported_by_HIP.html#memory-management - // - // TODO(leary) verify an error will be returned if the location wasn't - // previously registered. - static bool HostUnregister(Context* context, void* location); - // Launches a CUDA/ROCm kernel via cuLaunchKernel/hipModuleLaunchKernel. // http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXEC.html#group__CUDA__EXEC_1gb8f3dc3031b40da29d5f9a7139e52e15 // https://rocm.docs.amd.com/projects/HIPIFY/en/latest/tables/CUDA_Driver_API_functions_supported_by_HIP.html#execution-control