// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include #include "../framework.hpp" TEST(GpuUtilsTest, StreamPool) { auto streamPool = mscclpp::gpuStreamPool(); cudaStream_t s; { auto stream1 = streamPool->getStream(); s = stream1; EXPECT_NE(s, nullptr); } { auto stream2 = streamPool->getStream(); EXPECT_EQ(cudaStream_t(stream2), s); } { auto stream3 = streamPool->getStream(); auto stream4 = streamPool->getStream(); EXPECT_NE(cudaStream_t(stream3), cudaStream_t(stream4)); } streamPool->clear(); } TEST(GpuUtilsTest, AllocShared) { auto p1 = mscclpp::detail::gpuCallocShared(); auto p2 = mscclpp::detail::gpuCallocShared(5); } TEST(GpuUtilsTest, AllocUnique) { auto p1 = mscclpp::detail::gpuCallocUnique(); auto p2 = mscclpp::detail::gpuCallocUnique(5); } TEST(GpuUtilsTest, MakeSharedHost) { auto p1 = mscclpp::detail::gpuCallocHostShared(); auto p2 = mscclpp::detail::gpuCallocHostShared(5); } TEST(GpuUtilsTest, MakeUniqueHost) { auto p1 = mscclpp::detail::gpuCallocHostUnique(); auto p2 = mscclpp::detail::gpuCallocHostUnique(5); } TEST(GpuUtilsTest, Memcpy) { const int nElem = 1024; std::vector hostBuff(nElem); for (int i = 0; i < nElem; ++i) { hostBuff[i] = i + 1; } std::vector hostBuffTmp(nElem, 0); auto devBuff = mscclpp::detail::gpuCallocShared(nElem); mscclpp::gpuMemcpy(devBuff.get(), hostBuff.data(), nElem, cudaMemcpyHostToDevice); mscclpp::gpuMemcpy(hostBuffTmp.data(), devBuff.get(), nElem, cudaMemcpyDeviceToHost); for (int i = 0; i < nElem; ++i) { EXPECT_EQ(hostBuff[i], hostBuffTmp[i]); } }