Communicator owns IB contexts

This commit is contained in:
Changho Hwang
2023-04-27 05:01:07 +00:00
parent c24896b62f
commit b0c7e86909
2 changed files with 5 additions and 8 deletions

View File

@@ -15,9 +15,6 @@ namespace mscclpp {
Communicator::Impl::Impl(std::shared_ptr<BaseBootstrap> bootstrap) : bootstrap_(bootstrap) {}
Communicator::Impl::~Impl() {
for (auto& entry : ibContexts) {
delete entry.second;
}
ibContexts.clear();
}
@@ -26,11 +23,10 @@ IbCtx* Communicator::Impl::getIbContext(TransportFlags ibTransport) {
auto it = ibContexts.find(ibTransport);
if (it == ibContexts.end()) {
auto ibDev = getIBDeviceName(ibTransport);
IbCtx* ibCtx = new IbCtx(ibDev);
ibContexts[ibTransport] = ibCtx;
return ibCtx;
ibContexts[ibTransport] = std::make_unique<IbCtx>(ibDev);
return ibContexts[ibTransport].get();
} else {
return it->second;
return it->second.get();
}
}

View File

@@ -7,6 +7,7 @@
#include "proxy.hpp"
#include "ib.hpp"
#include <unordered_map>
#include <memory>
namespace mscclpp {
@@ -15,7 +16,7 @@ class ConnectionBase;
struct Communicator::Impl {
mscclppComm_t comm;
std::vector<std::shared_ptr<ConnectionBase>> connections;
std::unordered_map<TransportFlags, IbCtx*> ibContexts;
std::unordered_map<TransportFlags, std::unique_ptr<IbCtx>> ibContexts;
std::shared_ptr<BaseBootstrap> bootstrap_;
Impl(std::shared_ptr<BaseBootstrap> bootstrap);