|
| 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