Skip to content
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
12 changes: 4 additions & 8 deletions libc/src/__support/RPC/rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
namespace LIBC_NAMESPACE_DECL {
namespace rpc {

/// The libc client instance used to communicate with the server.
Client client;

/// Externally visible symbol to signify the usage of an RPC client to
/// whomever needs to run the server as well as provide a way to initialize
/// the client with a copy..
extern "C" [[gnu::visibility("protected")]] const void *__llvm_libc_rpc_client =
&client;
/// The libc client instance used to communicate with the server. Externally
/// visible symbol to signify the usage of an RPC client to whomever needs to
/// run the server as well as provide a way to initialize the client.
[[gnu::visibility("protected")]] Client client;

} // namespace rpc
} // namespace LIBC_NAMESPACE_DECL
2 changes: 1 addition & 1 deletion libc/src/__support/RPC/rpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static_assert(cpp::is_trivially_copyable<Client>::value &&
"The client is not trivially copyable from the server");

/// The libc client instance used to communicate with the server.
extern Client client;
[[gnu::visibility("protected")]] extern Client client asm("__llvm_rpc_client");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have any policy about this kind of use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Policy? It's standard ELF visibility rules that if you want something to be readable from the GPU runtime it can't have hidden visibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant using asm to rename a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but it's already how we export the libc functions themselves in the libc project so it's nothing new there. It's like

namespace LIBC_NAMESPACE {
  void foo() __asm__("foo");
}


} // namespace rpc
} // namespace LIBC_NAMESPACE_DECL
Expand Down
20 changes: 3 additions & 17 deletions libc/utils/gpu/loader/amdgpu/amdhsa-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,27 +477,15 @@ int load(int argc, const char **argv, const char **envp, void *image,
// device's internal pointer.
hsa_executable_symbol_t rpc_client_sym;
if (hsa_status_t err = hsa_executable_get_symbol_by_name(
executable, "__llvm_libc_rpc_client", &dev_agent, &rpc_client_sym))
executable, "__llvm_rpc_client", &dev_agent, &rpc_client_sym))
handle_error(err);

void *rpc_client_host;
if (hsa_status_t err =
hsa_amd_memory_pool_allocate(finegrained_pool, sizeof(void *),
/*flags=*/0, &rpc_client_host))
handle_error(err);
hsa_amd_agents_allow_access(1, &dev_agent, nullptr, rpc_client_host);

void *rpc_client_dev;
if (hsa_status_t err = hsa_executable_symbol_get_info(
rpc_client_sym, HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS,
&rpc_client_dev))
handle_error(err);

// Copy the address of the client buffer from the device to the host.
if (hsa_status_t err = hsa_memcpy(rpc_client_host, host_agent, rpc_client_dev,
dev_agent, sizeof(void *)))
handle_error(err);

void *rpc_client_buffer;
if (hsa_status_t err =
hsa_amd_memory_lock(&client, sizeof(rpc::Client),
Expand All @@ -506,14 +494,12 @@ int load(int argc, const char **argv, const char **envp, void *image,

// 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, sizeof(rpc::Client)))
hsa_memcpy(rpc_client_dev, dev_agent, rpc_client_buffer, host_agent,
sizeof(rpc::Client)))
handle_error(err);

if (hsa_status_t err = hsa_amd_memory_unlock(&client))
handle_error(err);
if (hsa_status_t err = hsa_amd_memory_pool_free(rpc_client_host))
handle_error(err);

// Obtain the GPU's fixed-frequency clock rate and copy it to the GPU.
// If the clock_freq symbol is missing, no work to do.
Expand Down
9 changes: 2 additions & 7 deletions libc/utils/gpu/loader/nvptx/nvptx-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,15 +314,10 @@ int load(int argc, const char **argv, const char **envp, void *image,
CUdeviceptr rpc_client_dev = 0;
uint64_t client_ptr_size = sizeof(void *);
if (CUresult err = cuModuleGetGlobal(&rpc_client_dev, &client_ptr_size,
binary, "__llvm_libc_rpc_client"))
binary, "__llvm_rpc_client"))
handle_error(err);

CUdeviceptr rpc_client_host = 0;
if (CUresult err =
cuMemcpyDtoH(&rpc_client_host, rpc_client_dev, sizeof(void *)))
handle_error(err);
if (CUresult err =
cuMemcpyHtoD(rpc_client_host, &client, sizeof(rpc::Client)))
if (CUresult err = cuMemcpyHtoD(rpc_client_dev, &client, sizeof(rpc::Client)))
handle_error(err);

LaunchParameters single_threaded_params = {1, 1, 1, 1, 1, 1};
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ struct OpenMPOpt {
// required an RPC server. If its users were all optimized out then we can
// safely remove it.
// TODO: This should be somewhere more common in the future.
if (GlobalVariable *GV = M.getNamedGlobal("__llvm_libc_rpc_client")) {
if (GlobalVariable *GV = M.getNamedGlobal("__llvm_rpc_client")) {
if (!GV->getType()->isPointerTy())
return false;

Expand Down
6 changes: 3 additions & 3 deletions llvm/test/Transforms/OpenMP/keep_rpc_client.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK

@client = internal addrspace(1) global i64 zeroinitializer, align 8
@__llvm_libc_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8

;.
; POSTLINK: @client = internal addrspace(1) global i64 0, align 8
; POSTLINK: @__llvm_libc_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
; POSTLINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
;.
; PRELINK: @client = internal addrspace(1) global i64 0, align 8
; PRELINK: @__llvm_libc_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
;.
define i64 @a() {
; POSTLINK-LABEL: define {{[^@]+}}@a
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/OpenMP/remove_rpc_client.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=PRELINK

@client = internal addrspace(1) global i32 zeroinitializer, align 8
@__llvm_libc_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
@__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8

;.
; PRELINK: @client = internal addrspace(1) global i32 0, align 8
; PRELINK: @__llvm_libc_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
; PRELINK: @__llvm_rpc_client = protected local_unnamed_addr addrspace(1) global ptr addrspacecast (ptr addrspace(1) @client to ptr), align 8
;.
define void @a() {
; POSTLINK-LABEL: define {{[^@]+}}@a() {
Expand Down
13 changes: 4 additions & 9 deletions offload/plugins-nextgen/common/src/RPC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ RPCServerTy::isDeviceUsingRPC(plugin::GenericDeviceTy &Device,
plugin::GenericGlobalHandlerTy &Handler,
plugin::DeviceImageTy &Image) {
#ifdef LIBOMPTARGET_RPC_SUPPORT
return Handler.isSymbolInImage(Device, Image, "__llvm_libc_rpc_client");
return Handler.isSymbolInImage(Device, Image, "__llvm_rpc_client");
#else
return false;
#endif
Expand All @@ -51,19 +51,14 @@ Error RPCServerTy::initDevice(plugin::GenericDeviceTy &Device,
"Failed to initialize RPC server for device %d", Device.getDeviceId());

// Get the address of the RPC client from the device.
void *ClientPtr;
plugin::GlobalTy ClientGlobal("__llvm_libc_rpc_client", sizeof(void *));
plugin::GlobalTy ClientGlobal("__llvm_rpc_client", sizeof(rpc::Client));
if (auto Err =
Handler.getGlobalMetadataFromDevice(Device, Image, ClientGlobal))
return Err;

if (auto Err = Device.dataRetrieve(&ClientPtr, ClientGlobal.getPtr(),
sizeof(void *), nullptr))
return Err;

rpc::Client client(NumPorts, RPCBuffer);
if (auto Err =
Device.dataSubmit(ClientPtr, &client, sizeof(rpc::Client), nullptr))
if (auto Err = Device.dataSubmit(ClientGlobal.getPtr(), &client,
sizeof(rpc::Client), nullptr))
return Err;
Buffers[Device.getDeviceId()] = RPCBuffer;

Expand Down