Skip to content

Commit 0298b50

Browse files
committed
Add unit tests for hipMemGetDefaultMemPool API
This change adds 2 new tests: - Unit_hipMemGetDefaultMemPool_Negative - Unit_hipMemGetDefaultMemPool_Basic Signed-off-by: Sebastian Luzynski <sebastian.luzynski@amd.com>
1 parent ff370e7 commit 0298b50

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

projects/hip-tests/catch/config/configs/unit/memory.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,3 +1242,5 @@ memory:
12421242
Unit_hipMemGetMemPool_Basic: *level_2
12431243
Unit_hipMemSetMemPool_Negative: *level_2
12441244
Unit_hipMemSetMemPool_Basic: *level_2
1245+
Unit_hipMemGetDefaultMemPool_Negative: *level_2
1246+
Unit_hipMemGetDefaultMemPool_Basic: *level_2

projects/hip-tests/catch/unit/memory/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ set(TEST_SRC
211211
hipFreeMipmappedArray.cc
212212
hipHostAlloc.cc
213213
hipMemSetMemPool.cc
214-
hipMemGetMemPool.cc)
214+
hipMemGetMemPool.cc
215+
hipMemGetDefaultMemPool.cc)
215216

216217
if(HIP_PLATFORM MATCHES "amd")
217218
set(TEST_SRC
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright (c) 2026 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
Permission is hereby granted, free of intge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
*/
22+
23+
#include <hip_test_common.hh>
24+
#include "mempool_common.hh"
25+
26+
/**
27+
* @addtogroup hipMemGetDefaultMemPool hipMemGetDefaultMemPool
28+
* @{
29+
* @ingroup MemoryTest
30+
* `hipError_t hipMemGetDefaultMemPool(hipMemPool_t* memPool, hipMemLocation* location,
31+
hipMemAllocationType type)` -
32+
* Gets the default memory pool for the location and allocation type.
33+
*/
34+
35+
TEST_CASE("Unit_hipMemGetDefaultMemPool_Negative") {
36+
int dev;
37+
HIP_CHECK(hipGetDevice(&dev));
38+
39+
hipMemPool_t memPool;
40+
hipMemLocation location{};
41+
location.id = dev;
42+
location.type = hipMemLocationTypeDevice;
43+
hipMemAllocationType allocationType = hipMemAllocationTypePinned;
44+
45+
SECTION("Invalid memPool") {
46+
HIP_CHECK_ERROR(hipMemGetDefaultMemPool(nullptr, &location, allocationType),
47+
hipErrorInvalidValue);
48+
}
49+
50+
SECTION("Invalid location") {
51+
HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, nullptr, allocationType),
52+
hipErrorInvalidValue);
53+
54+
location.id = -1;
55+
HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, allocationType),
56+
hipErrorInvalidValue);
57+
58+
location.id = dev;
59+
location.type = hipMemLocationTypeNone;
60+
HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, allocationType),
61+
hipErrorInvalidValue);
62+
}
63+
64+
SECTION("Invalid allocation type") {
65+
HIP_CHECK_ERROR(hipMemGetDefaultMemPool(&memPool, &location, hipMemAllocationTypeInvalid),
66+
hipErrorInvalidValue);
67+
}
68+
}
69+
70+
TEST_CASE("Unit_hipMemGetDefaultMemPool_Basic") {
71+
int dev;
72+
HIP_CHECK(hipGetDevice(&dev));
73+
74+
hipMemLocation location{};
75+
location.id = dev;
76+
location.type = hipMemLocationTypeDevice;
77+
78+
SECTION("Pinned") {
79+
auto alloc_type = hipMemAllocationTypePinned;
80+
hipMemPool_t memPool;
81+
hipMemPool_t deviceMemPool;
82+
83+
84+
HIP_CHECK(hipMemGetDefaultMemPool(&memPool, &location, alloc_type));
85+
REQUIRE(memPool != nullptr);
86+
HIP_CHECK(hipDeviceGetDefaultMemPool(&deviceMemPool, dev));
87+
REQUIRE(deviceMemPool != nullptr);
88+
REQUIRE(memPool == deviceMemPool);
89+
}
90+
91+
SECTION("Managed") {
92+
auto alloc_type = hipMemAllocationTypeManaged;
93+
hipMemPool_t memPool;
94+
HIP_CHECK(hipMemGetDefaultMemPool(&memPool, &location, alloc_type));
95+
REQUIRE(memPool != nullptr);
96+
}
97+
}

0 commit comments

Comments
 (0)