From 47e514c2b3630e5b7399e74d4c55a07b485b3216 Mon Sep 17 00:00:00 2001 From: Luca Terracciano Date: Thu, 11 Sep 2025 10:39:06 +0200 Subject: [PATCH] refactor: rpc engine requestRPC() accepts instance ids as parameter. getReturnValue() does not take an instance argument anymore --- examples/RPCEngine/README.rst | 2 +- examples/RPCEngine/source/include/RPCTest.hpp | 2 +- examples/topology/distributed/README.rst | 4 ++-- .../distributed/source/include/coordinator.hpp | 4 ++-- include/hicr/core/memorySpace.hpp | 2 +- include/hicr/frontends/RPCEngine/README.rst | 2 +- include/hicr/frontends/RPCEngine/RPCEngine.hpp | 11 ++++------- 7 files changed, 12 insertions(+), 15 deletions(-) diff --git a/examples/RPCEngine/README.rst b/examples/RPCEngine/README.rst index 09f5ec06..f591a599 100644 --- a/examples/RPCEngine/README.rst +++ b/examples/RPCEngine/README.rst @@ -63,7 +63,7 @@ The RPC is invoked by the root instance, the other instances listen to incoming if (currentInstance->isRootInstance()) { for (auto &instance : im.getInstances()) - if (instance != currentInstance) rpcEngine.requestRPC(*instance, "Test RPC"); + if (instance != currentInstance) rpcEngine.requestRPC(instance->getId(), "Test RPC"); } else rpcEngine.listen(); diff --git a/examples/RPCEngine/source/include/RPCTest.hpp b/examples/RPCEngine/source/include/RPCTest.hpp index 8f5922fe..995b78db 100644 --- a/examples/RPCEngine/source/include/RPCTest.hpp +++ b/examples/RPCEngine/source/include/RPCTest.hpp @@ -46,7 +46,7 @@ void RPCTestFc(HiCR::CommunicationManager &cm, if (currentInstance->isRootInstance()) { for (auto &instance : im.getInstances()) - if (instance != currentInstance) rpcEngine.requestRPC(*instance, "Test RPC"); + if (instance != currentInstance) rpcEngine.requestRPC(instance->getId(), "Test RPC"); } else rpcEngine.listen(); diff --git a/examples/topology/distributed/README.rst b/examples/topology/distributed/README.rst index 63152d9d..d5fb721e 100644 --- a/examples/topology/distributed/README.rst +++ b/examples/topology/distributed/README.rst @@ -78,14 +78,14 @@ The Root instance requests the topology from all the other instances, merge them // Invoke RPC for (const auto &instance : instances) - if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(*instance, TOPOLOGY_RPC_NAME); + if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(instance->getId(), TOPOLOGY_RPC_NAME); // Getting return values from the RPCs containing each of the worker's topology for (const auto &instance : instances) if (instance == coordinator) { // Getting return value as a memory slot - auto returnValue = rpcEngine.getReturnValue(*instance); + auto returnValue = rpcEngine.getReturnValue(); // Receiving raw serialized topology information from the worker std::string serializedTopology = (char *)returnValue->getPointer(); diff --git a/examples/topology/distributed/source/include/coordinator.hpp b/examples/topology/distributed/source/include/coordinator.hpp index d2d2fabe..ec1c2523 100644 --- a/examples/topology/distributed/source/include/coordinator.hpp +++ b/examples/topology/distributed/source/include/coordinator.hpp @@ -34,14 +34,14 @@ void coordinatorFc(HiCR::frontend::RPCEngine &rpcEngine) // Printing instance information and invoking a simple RPC if its not ourselves for (const auto &instance : instances) - if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(*instance, TOPOLOGY_RPC_NAME); + if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(instance->getId(), TOPOLOGY_RPC_NAME); // Getting return values from the RPCs containing each of the worker's topology for (const auto &instance : instances) if (instance != coordinator) { // Getting return value as a memory slot - auto returnValue = rpcEngine.getReturnValue(*instance); + auto returnValue = rpcEngine.getReturnValue(); // Receiving raw serialized topology information from the worker std::string serializedTopology = (char *)returnValue->getPointer(); diff --git a/include/hicr/core/memorySpace.hpp b/include/hicr/core/memorySpace.hpp index 0d000363..19b52f14 100644 --- a/include/hicr/core/memorySpace.hpp +++ b/include/hicr/core/memorySpace.hpp @@ -155,7 +155,7 @@ class MemorySpace _size = input[key].get(); // Deserializing usage -- do not fail if unspecified - key = "Usage"; + key = "Usage"; _usage = 0; if (input.contains(key) && input[key].is_number_unsigned()) _usage = input[key].get(); } diff --git a/include/hicr/frontends/RPCEngine/README.rst b/include/hicr/frontends/RPCEngine/README.rst index 2e4b167c..74b5d23f 100644 --- a/include/hicr/frontends/RPCEngine/README.rst +++ b/include/hicr/frontends/RPCEngine/README.rst @@ -93,7 +93,7 @@ The RPC caller can then wait for the reception of the return value by specifying instanceManager.launchRPC(*someInstance, RPC1_TARGET_ID); // Getting return value - auto returnValue = *(int *)instanceManager.getReturnValue(*someInstance); + auto returnValue = *(int *)instanceManager.getReturnValue(); // Printing return value printf("Obtained return value: %d\n", returnValue); diff --git a/include/hicr/frontends/RPCEngine/RPCEngine.hpp b/include/hicr/frontends/RPCEngine/RPCEngine.hpp index c990cf0b..b7552d5b 100644 --- a/include/hicr/frontends/RPCEngine/RPCEngine.hpp +++ b/include/hicr/frontends/RPCEngine/RPCEngine.hpp @@ -208,14 +208,12 @@ class RPCEngine /** * Function to request the execution of a remote function in a remote HiCR instance - * \param[in] RPCName The name of the RPC to run - * \param[in] instance Instance on which to run the RPC + * \param[in] targetInstanceId Instance ID of where the rpc is to be executed + * \param[in] RPCName RPC Name * \param[in] argument An optional numerical argument to provide to the RPC */ - virtual void requestRPC(HiCR::Instance &instance, const std::string &RPCName, const HiCR::frontend::RPCEngine::RPCArgument_t argument = 0) + virtual void requestRPC(HiCR::Instance::instanceId_t targetInstanceId, const std::string &RPCName, const HiCR::frontend::RPCEngine::RPCArgument_t argument = 0) { - const auto targetInstanceId = instance.getId(); - // Creating message payload RPCPayload_t RPCPayload; RPCPayload.index = getRPCTargetIndexFromString(RPCName); @@ -254,10 +252,9 @@ class RPCEngine /** * Function to get a return value from a remote instance that ran an RPC - * \param[in] instance Instance from which to read the return value. An RPC request should be sent to that instance before calling this function. * \return A pointer to a newly allocated local memory slot containing the return value */ - __INLINE__ std::shared_ptr getReturnValue(HiCR::Instance &instance) const + __INLINE__ std::shared_ptr getReturnValue() const { // Calling the backend-specific implementation of the listen function while (_returnValueConsumerChannel->isEmpty());