Skip to content

Commit

Permalink
[libc] Explicitly pin memory for the HSA memory transfer (llvm#73973)
Browse files Browse the repository at this point in the history
Summary:
This portion of code handles mapping the RPC client memory over to the
device. HSA copies need to be between two slices of memory that HSA has
allocated. Previously we used coarse-grained memory to act as the host
source. However, the support for this varies depending on the kernel and
version and should not be relied upon. This patch changes that handling
to use the `hsa_amd_memory_lock` API to explicitly pin memory to a
location sufficient for a DMA transfer to the GPU.
  • Loading branch information
jhuber6 authored Nov 30, 2023
1 parent bf4a876 commit 0584e6c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libc/utils/gpu/loader/amdgpu/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,20 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
handle_error(err);

void *rpc_client_buffer;
if (hsa_status_t err = hsa_amd_memory_pool_allocate(
coarsegrained_pool, rpc_get_client_size(),
/*flags=*/0, &rpc_client_buffer))
if (hsa_status_t err = hsa_amd_memory_lock(
const_cast<void *>(rpc_get_client_buffer(device_id)),
rpc_get_client_size(),
/*agents=*/nullptr, 0, &rpc_client_buffer))
handle_error(err);
std::memcpy(rpc_client_buffer, rpc_get_client_buffer(device_id),
rpc_get_client_size());

// Copy the RPC client buffer to the address pointed to by the symbol.
if (hsa_status_t err =
hsa_memcpy(*reinterpret_cast<void **>(rpc_client_host), dev_agent,
rpc_client_buffer, host_agent, rpc_get_client_size()))
handle_error(err);

if (hsa_status_t err = hsa_amd_memory_pool_free(rpc_client_buffer))
if (hsa_status_t err = hsa_amd_memory_unlock(
const_cast<void *>(rpc_get_client_buffer(device_id))))
handle_error(err);
if (hsa_status_t err = hsa_amd_memory_pool_free(rpc_client_host))
handle_error(err);
Expand Down

0 comments on commit 0584e6c

Please sign in to comment.