|
3 | 3 | // See LICENSE.TXT
|
4 | 4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
5 | 5 |
|
6 |
| -#include "../unified_malloc_framework/common/pool.hpp" |
7 |
| -#include "../unified_malloc_framework/common/provider.hpp" |
8 | 6 | #include "ur_pool_manager.hpp"
|
9 | 7 |
|
10 |
| -#include <uur/fixtures.h> |
| 8 | +#include "../unified_malloc_framework/common/pool.h" |
| 9 | +#include "../unified_malloc_framework/common/provider.h" |
11 | 10 |
|
12 |
| -#include <unordered_set> |
| 11 | +#include <uur/fixtures.h> |
13 | 12 |
|
14 |
| -struct urUsmPoolManagerTest |
| 13 | +struct urUsmPoolDescriptorTest |
15 | 14 | : public uur::urMultiDeviceContextTest,
|
16 | 15 | ::testing::WithParamInterface<ur_usm_pool_handle_t> {};
|
17 | 16 |
|
18 |
| -TEST_P(urUsmPoolManagerTest, poolIsPerContextTypeAndDevice) { |
| 17 | +TEST_P(urUsmPoolDescriptorTest, poolIsPerContextTypeAndDevice) { |
19 | 18 | auto &devices = uur::DevicesEnvironment::instance->devices;
|
20 | 19 | auto poolHandle = this->GetParam();
|
21 | 20 |
|
@@ -49,7 +48,71 @@ TEST_P(urUsmPoolManagerTest, poolIsPerContextTypeAndDevice) {
|
49 | 48 | ASSERT_EQ(sharedPools, devices.size() * 2);
|
50 | 49 | }
|
51 | 50 |
|
52 |
| -INSTANTIATE_TEST_SUITE_P(urUsmPoolManagerTest, urUsmPoolManagerTest, |
| 51 | +INSTANTIATE_TEST_SUITE_P(urUsmPoolDescriptorTest, urUsmPoolDescriptorTest, |
53 | 52 | ::testing::Values(nullptr));
|
54 | 53 |
|
55 | 54 | // TODO: add test with sub-devices
|
| 55 | + |
| 56 | +struct urUsmPoolManagerTest : public uur::urContextTest { |
| 57 | + void SetUp() override { |
| 58 | + UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp()); |
| 59 | + auto [ret, descs] = usm::pool_descriptor::create(nullptr, context); |
| 60 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 61 | + poolDescriptors = descs; |
| 62 | + } |
| 63 | + |
| 64 | + std::vector<usm::pool_descriptor> poolDescriptors; |
| 65 | +}; |
| 66 | + |
| 67 | +TEST_P(urUsmPoolManagerTest, poolManagerPopulate) { |
| 68 | + auto [ret, manager] = usm::pool_manager<usm::pool_descriptor>::create(); |
| 69 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 70 | + |
| 71 | + for (auto &desc : poolDescriptors) { |
| 72 | + // Populate the pool manager |
| 73 | + auto pool = nullPoolCreate(); |
| 74 | + ASSERT_NE(pool, nullptr); |
| 75 | + auto poolUnique = umf::pool_unique_handle_t(pool, umfPoolDestroy); |
| 76 | + ASSERT_NE(poolUnique, nullptr); |
| 77 | + ret = manager.addPool(desc, poolUnique); |
| 78 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 79 | + } |
| 80 | + |
| 81 | + for (auto &desc : poolDescriptors) { |
| 82 | + // Confirm that there is a pool for each descriptor |
| 83 | + auto hPoolOpt = manager.getPool(desc); |
| 84 | + ASSERT_TRUE(hPoolOpt.has_value()); |
| 85 | + ASSERT_NE(hPoolOpt.value(), nullptr); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +TEST_P(urUsmPoolManagerTest, poolManagerInsertExisting) { |
| 90 | + auto [ret, manager] = usm::pool_manager<usm::pool_descriptor>::create(); |
| 91 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 92 | + |
| 93 | + auto desc = poolDescriptors[0]; |
| 94 | + |
| 95 | + auto pool = nullPoolCreate(); |
| 96 | + ASSERT_NE(pool, nullptr); |
| 97 | + auto poolUnique = umf::pool_unique_handle_t(pool, umfPoolDestroy); |
| 98 | + ASSERT_NE(poolUnique, nullptr); |
| 99 | + |
| 100 | + ret = manager.addPool(desc, poolUnique); |
| 101 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 102 | + |
| 103 | + // Inserting an existing key should return an error |
| 104 | + ret = manager.addPool(desc, poolUnique); |
| 105 | + ASSERT_EQ(ret, UR_RESULT_ERROR_INVALID_ARGUMENT); |
| 106 | +} |
| 107 | + |
| 108 | +TEST_P(urUsmPoolManagerTest, poolManagerGetNonexistant) { |
| 109 | + auto [ret, manager] = usm::pool_manager<usm::pool_descriptor>::create(); |
| 110 | + ASSERT_EQ(ret, UR_RESULT_SUCCESS); |
| 111 | + |
| 112 | + for (auto &desc : poolDescriptors) { |
| 113 | + auto hPool = manager.getPool(desc); |
| 114 | + ASSERT_FALSE(hPool.has_value()); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUsmPoolManagerTest); |
0 commit comments