Skip to content
Open
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: 11 additions & 1 deletion examples/deploy/deploy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions include/deployr/deployr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -89,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();

Expand Down Expand Up @@ -126,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();
}
Expand Down
38 changes: 14 additions & 24 deletions include/deployr/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -63,38 +70,21 @@ class Engine
hwloc_topology_init(&_hwlocTopology);

// Initializing HWLoc-based host (CPU) topology manager
auto hwlocTopologyManager = std::make_unique<HiCR::backend::hwloc::TopologyManager>(&_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<HiCR::backend::ascend::TopologyManager>();

// 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<HiCR::backend::pthreads::ComputeManager>();

// 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*();

// Instantiating RPC engine
_rpcEngine = std::make_unique<HiCR::frontend::RPCEngine>(*_communicationManager, *_instanceManager, *_memoryManager, *_computeManager, RPCMemorySpace, RPCComputeResource);

// Initializing RPC engine
_rpcEngine->initialize();
_rpcEngine->initialize();
}

/**
Expand Down Expand Up @@ -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<std::unique_ptr<HiCR::TopologyManager>> _topologyManagers;
std::vector<HiCR::TopologyManager *> _topologyManagers;

/// Storage for compute manager
std::unique_ptr<HiCR::backend::pthreads::ComputeManager> _computeManager;
Expand Down
22 changes: 13 additions & 9 deletions include/deployr/engines/cloudrMPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,29 @@ class CloudR final : public deployr::Engine

__INLINE__ void initialize(int *pargc, char ***pargv, std::function<void()> 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<void()> _deploymentFc;

HiCR::backend::cloudr::InstanceManager *_cloudrInstanceManager;
std::function<void()> _deploymentFc;
};

} // namespace deployr::engine
Loading