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