Skip to content

Commit e1395c7

Browse files
authored
[libc] Explicitly pin memory for the client symbol lookup (#73988)
Summary: Previously, we determined that coarse grained memory cannot be used in the general case. That removed the buffer used to transfer the memory, however we still had this lookup. Though we do not access the symbol directly, it still conflicts with the agents apparently. Pin this as well. This resolves the problems @lntue was having with the `libc` GPU build.
1 parent a4745ff commit e1395c7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libc/utils/gpu/loader/amdgpu/Loader.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,18 +464,20 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
464464
executable, rpc_client_symbol_name, &dev_agent, &rpc_client_sym))
465465
handle_error(err);
466466

467-
void *rpc_client_host;
468-
if (hsa_status_t err =
469-
hsa_amd_memory_pool_allocate(coarsegrained_pool, sizeof(void *),
470-
/*flags=*/0, &rpc_client_host))
471-
handle_error(err);
472-
473467
void *rpc_client_dev;
474468
if (hsa_status_t err = hsa_executable_symbol_get_info(
475469
rpc_client_sym, HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS,
476470
&rpc_client_dev))
477471
handle_error(err);
478472

473+
// Pin some memory we can use to obtain the address of the rpc client.
474+
void *rpc_client_storage = nullptr;
475+
void *rpc_client_host = nullptr;
476+
if (hsa_status_t err =
477+
hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
478+
/*agents=*/nullptr, 0, &rpc_client_host))
479+
handle_error(err);
480+
479481
// Copy the address of the client buffer from the device to the host.
480482
if (hsa_status_t err = hsa_memcpy(rpc_client_host, host_agent, rpc_client_dev,
481483
dev_agent, sizeof(void *)))
@@ -497,7 +499,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
497499
if (hsa_status_t err = hsa_amd_memory_unlock(
498500
const_cast<void *>(rpc_get_client_buffer(device_id))))
499501
handle_error(err);
500-
if (hsa_status_t err = hsa_amd_memory_pool_free(rpc_client_host))
502+
if (hsa_status_t err = hsa_amd_memory_unlock(rpc_client_host))
501503
handle_error(err);
502504

503505
// Obtain the GPU's fixed-frequency clock rate and copy it to the GPU.

0 commit comments

Comments
 (0)