mirror of
https://github.com/microsoft/mscclpp.git
synced 2026-05-26 08:01:00 +00:00
Cherry-picked a part of features from #167: now `Communicator::setup()` is unneeded. `Communicator::sendMemory()` conducts the task inline, and `Communicator::recvMemory()` and `Communicator::connect()` conducts the task asynchronously without explicit setup.
40 lines
1.3 KiB
C++
40 lines
1.3 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <mscclpp/core.hpp>
|
|
|
|
class LocalCommunicatorTest : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override {
|
|
bootstrap = std::make_shared<mscclpp::TcpBootstrap>(0, 1);
|
|
bootstrap->initialize(bootstrap->createUniqueId());
|
|
comm = std::make_shared<mscclpp::Communicator>(bootstrap);
|
|
}
|
|
|
|
std::shared_ptr<mscclpp::TcpBootstrap> bootstrap;
|
|
std::shared_ptr<mscclpp::Communicator> comm;
|
|
};
|
|
|
|
TEST_F(LocalCommunicatorTest, RegisterMemory) {
|
|
int dummy[42];
|
|
auto memory = comm->registerMemory(&dummy, sizeof(dummy), mscclpp::NoTransports);
|
|
EXPECT_EQ(memory.data(), &dummy);
|
|
EXPECT_EQ(memory.size(), sizeof(dummy));
|
|
EXPECT_EQ(memory.transports(), mscclpp::NoTransports);
|
|
}
|
|
|
|
TEST_F(LocalCommunicatorTest, SendMemoryToSelf) {
|
|
int dummy[42];
|
|
auto memory = comm->registerMemory(&dummy, sizeof(dummy), mscclpp::NoTransports);
|
|
comm->sendMemoryOnSetup(memory, 0, 0);
|
|
auto memoryFuture = comm->recvMemoryOnSetup(0, 0);
|
|
comm->setup();
|
|
auto sameMemory = memoryFuture.get();
|
|
EXPECT_EQ(sameMemory.data(), memory.data());
|
|
EXPECT_EQ(sameMemory.size(), memory.size());
|
|
EXPECT_EQ(sameMemory.transports(), memory.transports());
|
|
}
|