From 04449bfb0d4673d063bd929e9106b8cd4e139233 Mon Sep 17 00:00:00 2001 From: Luca Terracciano Date: Fri, 27 Jun 2025 11:21:16 +0200 Subject: [PATCH 1/2] feat: topology managers are initialized outside deployer and the subsequently stored in it --- examples/deploy/deploy.cpp | 12 +++++++++++- include/deployr/deployr.hpp | 7 +++++++ include/deployr/engine.hpp | 38 ++++++++++++++----------------------- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/examples/deploy/deploy.cpp b/examples/deploy/deploy.cpp index b00ff5a..48ecab2 100644 --- a/examples/deploy/deploy.cpp +++ b/examples/deploy/deploy.cpp @@ -6,14 +6,24 @@ int main(int argc, char *argv[]) { + // Initialize Hwloc topology object + hwloc_topology_t hwlocTopology; + hwloc_topology_init(&hwlocTopology); + + // Initializing HWLoc-based host (CPU) topology manager + auto topologyManager = HiCR::backend::hwloc::TopologyManager(&hwlocTopology); + // Creating DeployR instance deployr::DeployR deployr; + // Add topology manager + deployr.addTopologyManager(&topologyManager); + // Creating Functions deployr.registerFunction("CoordinatorFc", [&]() { coordinatorFc(deployr); }); deployr.registerFunction("WorkerFc", [&]() { workerFc(deployr); }); - // Initializing DeployR. + // Initializing DeployR. bool isRoot = deployr.initialize(&argc, &argv); // Only one instance (root) configures and runs the deployment diff --git a/include/deployr/deployr.hpp b/include/deployr/deployr.hpp index c0567ad..c805bec 100644 --- a/include/deployr/deployr.hpp +++ b/include/deployr/deployr.hpp @@ -76,6 +76,13 @@ class DeployR final ~DeployR() = default; + /** + * Add topology manager to the engine + * + * @param topologyManager topology manager to add to Engine + */ + __INLINE__ void addTopologyManager(HiCR::TopologyManager *topologyManager) { _engine->addTopologyManager(topologyManager);} + /** * The initialization function for DeployR. * diff --git a/include/deployr/engine.hpp b/include/deployr/engine.hpp index 18eda36..c8de742 100644 --- a/include/deployr/engine.hpp +++ b/include/deployr/engine.hpp @@ -41,6 +41,13 @@ class Engine Engine() = default; virtual ~Engine() = default; + /** + * Add topology manager to the engine + * + * @param topologyManager topology manager to add to Engine + */ + __INLINE__ void addTopologyManager(HiCR::TopologyManager *topologyManager) { _topologyManagers.push_back(topologyManager); } + /** * Gets a collection, ordered by index, of all the detected / created HiCR instances * @@ -63,30 +70,13 @@ class Engine hwloc_topology_init(&_hwlocTopology); // Initializing HWLoc-based host (CPU) topology manager - auto hwlocTopologyManager = std::make_unique(&_hwlocTopology); - - // Adding topology manager to the list - _topologyManagers.push_back(std::move(hwlocTopologyManager)); - -#ifdef _HICR_USE_ASCEND_BACKEND_ - - // Initialize (Ascend's) ACL runtime - aclError err = aclInit(NULL); - if (err != ACL_SUCCESS) HICR_THROW_RUNTIME("Failed to initialize Ascend Computing Language. Error %d", err); - - // Initializing ascend topology manager - auto ascendTopologyManager = std::make_unique(); - - // Adding topology manager to the list - _topologyManagers.push_back(std::move(ascendTopologyManager)); - -#endif // _HICR_USE_ASCEND_BACKEND_ + auto hwlocTopologyManager = HiCR::backend::hwloc::TopologyManager(&_hwlocTopology); // Initializing RPC-related managers _computeManager = std::make_unique(); // Finding the first memory space and compute resource to create our RPC engine - _firstDevice = _topologyManagers.begin().operator*()->queryTopology().getDevices().begin().operator*(); + _firstDevice = hwlocTopologyManager.queryTopology().getDevices().begin().operator*(); auto RPCMemorySpace = _firstDevice->getMemorySpaceList().begin().operator*(); auto RPCComputeResource = _firstDevice->getComputeResourceList().begin().operator*(); @@ -94,7 +84,7 @@ class Engine _rpcEngine = std::make_unique(*_communicationManager, *_instanceManager, *_memoryManager, *_computeManager, RPCMemorySpace, RPCComputeResource); // Initializing RPC engine - _rpcEngine->initialize(); + _rpcEngine->initialize(); } /** @@ -415,16 +405,16 @@ class Engine protected: /// Storage for the distributed engine's communication manager - HiCR::CommunicationManager* _communicationManager; + HiCR::CommunicationManager *_communicationManager; /// The distributed engine's instance manager - HiCR::InstanceManager* _instanceManager; + HiCR::InstanceManager *_instanceManager; /// The distributed engine's memory manager - HiCR::MemoryManager* _memoryManager; + HiCR::MemoryManager *_memoryManager; /// Storage for topology managers - std::vector> _topologyManagers; + std::vector _topologyManagers; /// Storage for compute manager std::unique_ptr _computeManager; From fd8cd6f2269e2f183737c8e5c352385989261ec5 Mon Sep 17 00:00:00 2001 From: Luca Terracciano Date: Fri, 27 Jun 2025 11:26:16 +0200 Subject: [PATCH 2/2] style: format files --- include/deployr/deployr.hpp | 9 ++++----- include/deployr/engines/cloudrMPI.hpp | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/deployr/deployr.hpp b/include/deployr/deployr.hpp index c805bec..5cc713a 100644 --- a/include/deployr/deployr.hpp +++ b/include/deployr/deployr.hpp @@ -81,8 +81,8 @@ class DeployR final * * @param topologyManager topology manager to add to Engine */ - __INLINE__ void addTopologyManager(HiCR::TopologyManager *topologyManager) { _engine->addTopologyManager(topologyManager);} - + __INLINE__ void addTopologyManager(HiCR::TopologyManager *topologyManager) { _engine->addTopologyManager(topologyManager); } + /** * The initialization function for DeployR. * @@ -96,8 +96,7 @@ class DeployR final __INLINE__ bool initialize(int *pargc, char ***pargv) { // Function for deployment after initializing a new instance - auto deploymentFc = [this]() - { + auto deploymentFc = [this]() { // Running deployment function of the engine _engine->deploy(); @@ -133,7 +132,7 @@ class DeployR final // Initializing distributed execution engine _engine->initialize(pargc, pargv, deploymentFc); - + // Return whether this is the root instance or not return _engine->isRootInstance(); } diff --git a/include/deployr/engines/cloudrMPI.hpp b/include/deployr/engines/cloudrMPI.hpp index 1687dc3..3878964 100644 --- a/include/deployr/engines/cloudrMPI.hpp +++ b/include/deployr/engines/cloudrMPI.hpp @@ -21,25 +21,29 @@ class CloudR final : public deployr::Engine __INLINE__ void initialize(int *pargc, char ***pargv, std::function deploymentFc) override { - _deploymentFc = deploymentFc; - _cloudrInstanceManager = new HiCR::backend::cloudr::InstanceManager([this](HiCR::backend::cloudr::InstanceManager* cloudr, int, char**) { _deploymentFc(); return 0; }); + _deploymentFc = deploymentFc; + _cloudrInstanceManager = new HiCR::backend::cloudr::InstanceManager([this](HiCR::backend::cloudr::InstanceManager *cloudr, int, char **) { + _deploymentFc(); + return 0; + }); _cloudrInstanceManager->initialize(pargc, pargv); _instanceManager = _cloudrInstanceManager; _communicationManager = _cloudrInstanceManager->getCommunicationManager().get(); _memoryManager = _cloudrInstanceManager->getMemoryManager().get(); }; - __INLINE__ void finalize() override { - _instanceManager->finalize(); - delete _instanceManager; - } + __INLINE__ void finalize() override + { + _instanceManager->finalize(); + delete _instanceManager; + } __INLINE__ void abort() override { _instanceManager->abort(-1); } private: - - HiCR::backend::cloudr::InstanceManager* _cloudrInstanceManager; - std::function _deploymentFc; + + HiCR::backend::cloudr::InstanceManager *_cloudrInstanceManager; + std::function _deploymentFc; }; } // namespace deployr::engine \ No newline at end of file