diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h --- a/libc/src/__support/RPC/rpc.h +++ b/libc/src/__support/RPC/rpc.h @@ -106,20 +106,20 @@ uint64_t port_count; uint32_t lane_size; - cpp::Atomic *lock; cpp::Atomic *inbox; cpp::Atomic *outbox; Packet *packet; + cpp::Atomic lock[default_port_count] = {0}; + /// Initialize the communication channels. - LIBC_INLINE void reset(uint64_t port_count, uint32_t lane_size, void *lock, - void *inbox, void *outbox, void *packet) { - *this = {port_count, - lane_size, - reinterpret_cast *>(lock), - reinterpret_cast *>(inbox), - reinterpret_cast *>(outbox), - reinterpret_cast(packet)}; + LIBC_INLINE void reset(uint64_t port_count, uint32_t lane_size, void *inbox, + void *outbox, void *packet) { + this->port_count = port_count; + this->lane_size = lane_size; + this->inbox = reinterpret_cast *>(inbox); + this->outbox = reinterpret_cast *>(outbox); + this->packet = reinterpret_cast(packet); } /// The length of the packet is flexible because the server needs to look up diff --git a/libc/startup/gpu/amdgpu/start.cpp b/libc/startup/gpu/amdgpu/start.cpp --- a/libc/startup/gpu/amdgpu/start.cpp +++ b/libc/startup/gpu/amdgpu/start.cpp @@ -15,8 +15,6 @@ namespace __llvm_libc { -static cpp::Atomic lock[rpc::default_port_count] = {0}; - extern "C" uintptr_t __init_array_start[]; extern "C" uintptr_t __init_array_end[]; extern "C" uintptr_t __fini_array_start[]; @@ -44,8 +42,8 @@ // We need to set up the RPC client first in case any of the constructors // require it. __llvm_libc::rpc::client.reset(__llvm_libc::rpc::default_port_count, - __llvm_libc::gpu::get_lane_size(), - &__llvm_libc::lock, in, out, buffer); + __llvm_libc::gpu::get_lane_size(), in, out, + buffer); // We want the fini array callbacks to be run after other atexit // callbacks are run. So, we register them before running the init diff --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp --- a/libc/startup/gpu/nvptx/start.cpp +++ b/libc/startup/gpu/nvptx/start.cpp @@ -15,8 +15,6 @@ namespace __llvm_libc { -static cpp::Atomic lock[rpc::default_port_count] = {0}; - extern "C" { // Nvidia's 'nvlink' linker does not provide these symbols. We instead need // to manually create them and update the globals in the loader implememtation. @@ -48,8 +46,8 @@ // We need to set up the RPC client first in case any of the constructors // require it. __llvm_libc::rpc::client.reset(__llvm_libc::rpc::default_port_count, - __llvm_libc::gpu::get_lane_size(), - &__llvm_libc::lock, in, out, buffer); + __llvm_libc::gpu::get_lane_size(), in, out, + buffer); // We want the fini array callbacks to be run after other atexit // callbacks are run. So, we register them before running the init diff --git a/libc/utils/gpu/loader/Server.h b/libc/utils/gpu/loader/Server.h --- a/libc/utils/gpu/loader/Server.h +++ b/libc/utils/gpu/loader/Server.h @@ -19,9 +19,6 @@ static __llvm_libc::rpc::Server server; -static __llvm_libc::cpp::Atomic - lock[__llvm_libc::rpc::default_port_count] = {0}; - /// Queries the RPC client at least once and performs server-side work if there /// are any active requests. void handle_server() { diff --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp --- a/libc/utils/gpu/loader/amdgpu/Loader.cpp +++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp @@ -359,8 +359,7 @@ hsa_amd_agents_allow_access(1, &dev_agent, nullptr, buffer); // Initialize the RPC server's buffer for host-device communication. - server.reset(port_size, wavefront_size, &lock, server_inbox, server_outbox, - buffer); + server.reset(port_size, wavefront_size, server_inbox, server_outbox, buffer); // Obtain a queue with the minimum (power of two) size, used to send commands // to the HSA runtime and launch execution on the device. diff --git a/libc/utils/gpu/loader/nvptx/Loader.cpp b/libc/utils/gpu/loader/nvptx/Loader.cpp --- a/libc/utils/gpu/loader/nvptx/Loader.cpp +++ b/libc/utils/gpu/loader/nvptx/Loader.cpp @@ -260,8 +260,7 @@ handle_error("Failed to allocate memory the RPC client / server."); // Initialize the RPC server's buffer for host-device communication. - server.reset(port_size, warp_size, &lock, server_inbox, server_outbox, - buffer); + server.reset(port_size, warp_size, server_inbox, server_outbox, buffer); LaunchParameters single_threaded_params = {1, 1, 1, 1, 1, 1}; // Call the kernel to