CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
203 lines
5.0 KiB
C++
203 lines
5.0 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <thread>
|
|
#include <vector>
|
|
|
|
#include <hipdnn_plugin_sdk/EngineManager.hpp>
|
|
#include <hipdnn_plugin_sdk/EnginePluginTypeTraits.hpp>
|
|
#include <hipdnn_plugin_sdk/SharedContainerManager.hpp>
|
|
|
|
using namespace hipdnn_plugin_sdk;
|
|
|
|
namespace
|
|
{
|
|
|
|
// Define test handle, settings, and execution context structs for testing
|
|
struct TestHandle
|
|
{
|
|
};
|
|
|
|
struct TestSettings
|
|
{
|
|
};
|
|
|
|
struct TestContext
|
|
{
|
|
};
|
|
|
|
// Define type alias for readability
|
|
using TestEngineManager = EngineManager<TestHandle, TestSettings, TestContext>;
|
|
|
|
// Test container that tracks initialization and meets requirements
|
|
class TestContainer
|
|
{
|
|
public:
|
|
TestContainer()
|
|
: _engineManager(std::make_unique<TestEngineManager>())
|
|
{
|
|
instanceCount++;
|
|
}
|
|
|
|
~TestContainer()
|
|
{
|
|
instanceCount--;
|
|
}
|
|
|
|
static uint32_t
|
|
copyEngineIds(int64_t* /*engineIds*/, uint32_t /*maxEngines*/, uint32_t& numEngines)
|
|
{
|
|
numEngines = 0;
|
|
return 0;
|
|
}
|
|
|
|
TestEngineManager& getEngineManager()
|
|
{
|
|
return *_engineManager;
|
|
}
|
|
|
|
static int instanceCount;
|
|
|
|
private:
|
|
std::unique_ptr<TestEngineManager> _engineManager;
|
|
};
|
|
|
|
int TestContainer::instanceCount = 0;
|
|
|
|
} // namespace
|
|
|
|
TEST(TestSharedContainerManager, CreatesContainerOnFirstCall)
|
|
{
|
|
TestContainer::instanceCount = 0;
|
|
SharedContainerManager<TestContainer> manager;
|
|
|
|
EXPECT_EQ(TestContainer::instanceCount, 0);
|
|
|
|
auto container = manager.getOrCreate();
|
|
EXPECT_NE(container, nullptr);
|
|
EXPECT_EQ(TestContainer::instanceCount, 1);
|
|
}
|
|
|
|
TEST(TestSharedContainerManager, ReturnsSameContainerOnSubsequentCalls)
|
|
{
|
|
TestContainer::instanceCount = 0;
|
|
SharedContainerManager<TestContainer> manager;
|
|
|
|
auto container1 = manager.getOrCreate();
|
|
auto container2 = manager.getOrCreate();
|
|
|
|
EXPECT_EQ(container1.get(), container2.get());
|
|
EXPECT_EQ(TestContainer::instanceCount, 1);
|
|
}
|
|
|
|
TEST(TestSharedContainerManager, RecreatesContainerAfterAllReferencesDropped)
|
|
{
|
|
TestContainer::instanceCount = 0;
|
|
SharedContainerManager<TestContainer> manager;
|
|
|
|
{
|
|
auto container = manager.getOrCreate();
|
|
EXPECT_EQ(TestContainer::instanceCount, 1);
|
|
}
|
|
|
|
// Container should be destroyed now
|
|
EXPECT_EQ(TestContainer::instanceCount, 0);
|
|
|
|
// Getting again should create a new one
|
|
auto newContainer = manager.getOrCreate();
|
|
EXPECT_EQ(TestContainer::instanceCount, 1);
|
|
}
|
|
|
|
TEST(TestSharedContainerManager, ThreadSafeCreation)
|
|
{
|
|
TestContainer::instanceCount = 0;
|
|
SharedContainerManager<TestContainer> manager;
|
|
|
|
std::vector<std::shared_ptr<TestContainer>> containers;
|
|
std::mutex containersMutex;
|
|
|
|
constexpr int K_NUM_THREADS = 10;
|
|
std::vector<std::thread> threads;
|
|
threads.reserve(K_NUM_THREADS);
|
|
|
|
for(int i = 0; i < K_NUM_THREADS; ++i)
|
|
{
|
|
threads.emplace_back([&]() {
|
|
auto container = manager.getOrCreate();
|
|
const std::lock_guard<std::mutex> lock(containersMutex);
|
|
containers.push_back(container);
|
|
});
|
|
}
|
|
|
|
for(auto& thread : threads)
|
|
{
|
|
thread.join();
|
|
}
|
|
|
|
// All threads should have gotten the same container
|
|
EXPECT_EQ(TestContainer::instanceCount, 1);
|
|
EXPECT_EQ(containers.size(), static_cast<size_t>(K_NUM_THREADS));
|
|
|
|
// Verify all containers are the same instance
|
|
for(const auto& container : containers)
|
|
{
|
|
EXPECT_EQ(container.get(), containers[0].get());
|
|
}
|
|
}
|
|
|
|
TEST(TestEnginePluginContainer, ValidContainerPassesCompileTimeValidation)
|
|
{
|
|
// Test that the compile-time validation works for containers meeting requirements
|
|
constexpr bool K_VALID = (validateContainerType<TestContainer>(), true);
|
|
EXPECT_TRUE(K_VALID);
|
|
}
|
|
|
|
namespace
|
|
{
|
|
|
|
// Test handle that meets all requirements for validateHandleType
|
|
struct TestValidHandle
|
|
{
|
|
std::shared_ptr<TestContainer> container;
|
|
|
|
void setStream(hipStream_t /*stream*/) {}
|
|
|
|
TestEngineManager& getEngineManager()
|
|
{
|
|
return container->getEngineManager();
|
|
}
|
|
|
|
void removeEngineDetailsDetachedBuffer(const void* /*ptr*/) {}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST(TestEnginePluginContainer, ValidHandlePassesCompileTimeValidation)
|
|
{
|
|
// Test that the compile-time validation works for handles meeting requirements
|
|
constexpr bool K_VALID = (validateHandleType<TestValidHandle, TestContainer>(), true);
|
|
EXPECT_TRUE(K_VALID);
|
|
}
|
|
|
|
TEST(TestEnginePluginContainer, HandleTypeTraitsDetectContainerMember)
|
|
{
|
|
EXPECT_TRUE((HasContainerMember<TestValidHandle, TestContainer>::value));
|
|
}
|
|
|
|
TEST(TestEnginePluginContainer, HandleTypeTraitsDetectSetStream)
|
|
{
|
|
EXPECT_TRUE((HasSetStream<TestValidHandle>::value));
|
|
}
|
|
|
|
TEST(TestEnginePluginContainer, HandleTypeTraitsDetectGetEngineManager)
|
|
{
|
|
EXPECT_TRUE((HasGetEngineManager<TestValidHandle>::value));
|
|
}
|
|
|
|
TEST(TestEnginePluginContainer, HandleTypeTraitsDetectRemoveEngineDetailsDetachedBuffer)
|
|
{
|
|
EXPECT_TRUE((HasRemoveEngineDetailsDetachedBuffer<TestValidHandle>::value));
|
|
}
|