Files
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

168 lines
4.8 KiB
C++

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <hipdnn_flatbuffers_sdk/flatbuffer_utilities/EngineConfigWrapper.hpp>
#include <hipdnn_plugin_sdk/EngineManager.hpp>
#include <hipdnn_plugin_sdk/PluginException.hpp>
#include <hipdnn_test_sdk/utilities/MockEngineConfig.hpp>
#include <hipdnn_test_sdk/utilities/MockGraph.hpp>
using namespace hipdnn_plugin_sdk;
using namespace hipdnn_test_sdk::utilities;
using ::testing::NiceMock;
using ::testing::Return;
// Define test handle, settings, and execution context structs for testing
struct TestHandle
{
};
struct TestSettings
{
};
struct TestContext
{
};
namespace
{
// Test engine that inherits from IEngine with configurable behavior
class TestEngine : public IEngine<TestHandle, TestSettings, TestContext>
{
public:
TestEngine(int64_t engineId, bool applicable, size_t workspaceSize = 1024)
: _id(engineId)
, _applicable(applicable)
, _workspaceSize(workspaceSize)
{
}
int64_t id() const override
{
return _id;
}
bool isApplicable(
TestHandle& /*handle*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/) const override
{
return _applicable;
}
void getDetails(TestHandle& /*handle*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/,
hipdnnPluginConstData_t& /*detailsOut*/) const override
{
}
size_t getMaxWorkspaceSize(
const TestHandle& /*handle*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IEngineConfig& /*engineConfig*/)
const override
{
return _workspaceSize;
}
void initializeExecutionContext(
const TestHandle& /*handle*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IGraph& /*opGraph*/,
const hipdnn_flatbuffers_sdk::flatbuffer_utilities::IEngineConfig& /*engineConfig*/,
TestContext& /*executionContext*/) const override
{
}
private:
int64_t _id;
bool _applicable;
size_t _workspaceSize;
};
// Define type alias for readability
using TestEngineManager = EngineManager<TestHandle, TestSettings, TestContext>;
std::unique_ptr<TestEngine>
createTestEngine(int64_t engineId, bool applicable, size_t workspaceSize = 1024)
{
return std::make_unique<TestEngine>(engineId, applicable, workspaceSize);
}
} // namespace
TEST(TestEngineManager, InitiallyHasNoEngines)
{
const TestEngineManager manager;
auto engineIds = manager.getAllEngineIds();
EXPECT_TRUE(engineIds.empty());
}
TEST(TestEngineManager, AddEngineRegistersEngine)
{
TestEngineManager manager;
manager.addEngine(createTestEngine(1, true));
auto engineIds = manager.getAllEngineIds();
ASSERT_EQ(engineIds.size(), 1u);
EXPECT_EQ(engineIds[0], 1);
}
TEST(TestEngineManager, AddMultipleEngines)
{
TestEngineManager manager;
manager.addEngine(createTestEngine(1, true));
manager.addEngine(createTestEngine(2, false));
manager.addEngine(createTestEngine(3, true));
auto engineIds = manager.getAllEngineIds();
EXPECT_EQ(engineIds.size(), 3u);
}
TEST(TestEngineManager, GetApplicableEngineIdsFiltersCorrectly)
{
TestEngineManager manager;
manager.addEngine(createTestEngine(1, true));
manager.addEngine(createTestEngine(2, false));
manager.addEngine(createTestEngine(3, true));
TestHandle handle;
const NiceMock<MockGraph> mockGraph;
auto applicableIds = manager.getApplicableEngineIds(handle, mockGraph);
EXPECT_EQ(applicableIds.size(), 2u);
EXPECT_TRUE(std::find(applicableIds.begin(), applicableIds.end(), 1) != applicableIds.end());
EXPECT_TRUE(std::find(applicableIds.begin(), applicableIds.end(), 3) != applicableIds.end());
EXPECT_TRUE(std::find(applicableIds.begin(), applicableIds.end(), 2) == applicableIds.end());
}
TEST(TestEngineManager, GetWorkspaceSizeReturnsEngineWorkspace)
{
TestEngineManager manager;
manager.addEngine(createTestEngine(1, true, 2048));
const TestHandle handle;
const NiceMock<MockGraph> mockGraph;
const NiceMock<MockEngineConfig> mockConfig;
ON_CALL(mockConfig, engineId()).WillByDefault(Return(1));
auto workspaceSize = manager.getMaxWorkspaceSize(handle, mockGraph, mockConfig);
EXPECT_EQ(workspaceSize, 2048u);
}
TEST(TestEngineManager, GetWorkspaceSizeThrowsForUnknownEngine)
{
TestEngineManager manager;
manager.addEngine(createTestEngine(1, true));
const TestHandle handle;
const NiceMock<MockGraph> mockGraph;
const NiceMock<MockEngineConfig> mockConfig;
ON_CALL(mockConfig, engineId()).WillByDefault(Return(999));
EXPECT_THROW(manager.getMaxWorkspaceSize(handle, mockGraph, mockConfig), HipdnnPluginException);
}