@@ -626,9 +626,9 @@ struct AMDGPUSignalTy {
626626 }
627627
628628 // / Wait until the signal gets a zero value.
629- Error wait (const uint64_t ActiveTimeout = 0 , RPCServerTy *RPCServer = nullptr ,
629+ Error wait (const uint64_t ActiveTimeout = 0 ,
630630 GenericDeviceTy *Device = nullptr ) const {
631- if (ActiveTimeout && !RPCServer ) {
631+ if (ActiveTimeout) {
632632 hsa_signal_value_t Got = 1 ;
633633 Got = hsa_signal_wait_scacquire (HSASignal, HSA_SIGNAL_CONDITION_EQ, 0 ,
634634 ActiveTimeout, HSA_WAIT_STATE_ACTIVE);
@@ -637,14 +637,11 @@ struct AMDGPUSignalTy {
637637 }
638638
639639 // If there is an RPC device attached to this stream we run it as a server.
640- uint64_t Timeout = RPCServer ? 8192 : UINT64_MAX;
641- auto WaitState = RPCServer ? HSA_WAIT_STATE_ACTIVE : HSA_WAIT_STATE_BLOCKED;
640+ uint64_t Timeout = UINT64_MAX;
641+ auto WaitState = HSA_WAIT_STATE_BLOCKED;
642642 while (hsa_signal_wait_scacquire (HSASignal, HSA_SIGNAL_CONDITION_EQ, 0 ,
643- Timeout, WaitState) != 0 ) {
644- if (RPCServer && Device)
645- if (auto Err = RPCServer->runServer (*Device))
646- return Err;
647- }
643+ Timeout, WaitState) != 0 )
644+ ;
648645 return Plugin::success ();
649646 }
650647
@@ -1053,11 +1050,6 @@ struct AMDGPUStreamTy {
10531050 // / operation that was already finalized in a previous stream sycnhronize.
10541051 uint32_t SyncCycle;
10551052
1056- // / A pointer associated with an RPC server running on the given device. If
1057- // / RPC is not being used this will be a null pointer. Otherwise, this
1058- // / indicates that an RPC server is expected to be run on this stream.
1059- RPCServerTy *RPCServer;
1060-
10611053 // / Mutex to protect stream's management.
10621054 mutable std::mutex Mutex;
10631055
@@ -1237,9 +1229,6 @@ struct AMDGPUStreamTy {
12371229 // / Deinitialize the stream's signals.
12381230 Error deinit () { return Plugin::success (); }
12391231
1240- // / Attach an RPC server to this stream.
1241- void setRPCServer (RPCServerTy *Server) { RPCServer = Server; }
1242-
12431232 // / Push a asynchronous kernel to the stream. The kernel arguments must be
12441233 // / placed in a special allocation for kernel args and must keep alive until
12451234 // / the kernel finalizes. Once the kernel is finished, the stream will release
@@ -1267,10 +1256,30 @@ struct AMDGPUStreamTy {
12671256 if (auto Err = Slots[Curr].schedReleaseBuffer (KernelArgs, MemoryManager))
12681257 return Err;
12691258
1259+ // If we are running an RPC server we want to wake up the server thread
1260+ // whenever there is a kernel running and let it sleep otherwise.
1261+ if (Device.getRPCServer ())
1262+ Device.Plugin .getRPCServer ().Thread ->notify ();
1263+
12701264 // Push the kernel with the output signal and an input signal (optional)
1271- return Queue->pushKernelLaunch (Kernel, KernelArgs, NumThreads, NumBlocks,
1272- GroupSize, StackSize, OutputSignal,
1273- InputSignal);
1265+ if (auto Err = Queue->pushKernelLaunch (Kernel, KernelArgs, NumThreads,
1266+ NumBlocks, GroupSize, StackSize,
1267+ OutputSignal, InputSignal))
1268+ return Err;
1269+
1270+ // Register a callback to indicate when the kernel is complete.
1271+ if (Device.getRPCServer ()) {
1272+ if (auto Err = Slots[Curr].schedCallback (
1273+ [](void *Data) -> llvm::Error {
1274+ GenericPluginTy &Plugin =
1275+ *reinterpret_cast <GenericPluginTy *>(Data);
1276+ Plugin.getRPCServer ().Thread ->finish ();
1277+ return Error::success ();
1278+ },
1279+ &Device.Plugin ))
1280+ return Err;
1281+ }
1282+ return Plugin::success ();
12741283 }
12751284
12761285 // / Push an asynchronous memory copy between pinned memory buffers.
@@ -1480,8 +1489,8 @@ struct AMDGPUStreamTy {
14801489 return Plugin::success ();
14811490
14821491 // Wait until all previous operations on the stream have completed.
1483- if (auto Err = Slots[ last ()]. Signal -> wait (StreamBusyWaitMicroseconds,
1484- RPCServer , &Device))
1492+ if (auto Err =
1493+ Slots[ last ()]. Signal -> wait (StreamBusyWaitMicroseconds , &Device))
14851494 return Err;
14861495
14871496 // Reset the stream and perform all pending post actions.
@@ -3025,7 +3034,7 @@ AMDGPUStreamTy::AMDGPUStreamTy(AMDGPUDeviceTy &Device)
30253034 : Agent(Device.getAgent()), Queue(nullptr ),
30263035 SignalManager (Device.getSignalManager()), Device(Device),
30273036 // Initialize the std::deque with some empty positions.
3028- Slots(32 ), NextSlot(0 ), SyncCycle(0 ), RPCServer( nullptr ),
3037+ Slots(32 ), NextSlot(0 ), SyncCycle(0 ),
30293038 StreamBusyWaitMicroseconds(Device.getStreamBusyWaitMicroseconds()),
30303039 UseMultipleSdmaEngines(Device.useMultipleSdmaEngines()) {}
30313040
@@ -3378,10 +3387,6 @@ Error AMDGPUKernelTy::launchImpl(GenericDeviceTy &GenericDevice,
33783387 if (auto Err = AMDGPUDevice.getStream (AsyncInfoWrapper, Stream))
33793388 return Err;
33803389
3381- // If this kernel requires an RPC server we attach its pointer to the stream.
3382- if (GenericDevice.getRPCServer ())
3383- Stream->setRPCServer (GenericDevice.getRPCServer ());
3384-
33853390 // Only COV5 implicitargs needs to be set. COV4 implicitargs are not used.
33863391 if (ImplArgs &&
33873392 getImplicitArgsSize () == sizeof (hsa_utils::AMDGPUImplicitArgsTy)) {
0 commit comments