Skip to content

Commit c84e8de

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 c84e8de

File tree

3 files changed

+98
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)