From 053e0e59f3803f1334a99efda5feb105c1b3ddd3 Mon Sep 17 00:00:00 2001 From: Jaydeep Patel Date: Tue, 27 Feb 2024 08:40:17 +0000 Subject: [PATCH] SWDEV-447525 - Tests for maxSize Mem pool props. Change-Id: If0ce1bafa8101da8b1856fe9175737cdb82a2b86 [ROCm/hip-tests commit: bd760c481816af8685926aea1ec795f172352784] --- .../stream/mem_pools_performance_common.hh | 1 + .../catch/unit/memory/hipMemPoolApi.cc | 1 + .../catch/unit/memory/hipMemPoolCreate.cc | 53 +++++++++++++++++++ .../catch/unit/memory/mempool_common.hh | 2 +- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/projects/hip-tests/catch/performance/stream/mem_pools_performance_common.hh b/projects/hip-tests/catch/performance/stream/mem_pools_performance_common.hh index b6f6f4b489..94b51be887 100644 --- a/projects/hip-tests/catch/performance/stream/mem_pools_performance_common.hh +++ b/projects/hip-tests/catch/performance/stream/mem_pools_performance_common.hh @@ -44,6 +44,7 @@ static hipMemPoolProps CreateMemPoolProps(const int device_id, const hipMemAlloc device_id }, nullptr, + 0, {0} }; diff --git a/projects/hip-tests/catch/unit/memory/hipMemPoolApi.cc b/projects/hip-tests/catch/unit/memory/hipMemPoolApi.cc index 927899f1b7..957d7749fc 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemPoolApi.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemPoolApi.cc @@ -39,6 +39,7 @@ constexpr hipMemPoolProps kPoolProps = { 0 }, nullptr, + 0, {0} }; diff --git a/projects/hip-tests/catch/unit/memory/hipMemPoolCreate.cc b/projects/hip-tests/catch/unit/memory/hipMemPoolCreate.cc index 57a3db7f45..4b06f53261 100644 --- a/projects/hip-tests/catch/unit/memory/hipMemPoolCreate.cc +++ b/projects/hip-tests/catch/unit/memory/hipMemPoolCreate.cc @@ -91,3 +91,56 @@ TEST_CASE("Unit_hipMemPoolCreate_Negative_Parameter") { pool_props.location.id = 0; } } + +TEST_CASE("Unit_hipMemPoolCreate_With_maxSize") { + int mem_pool_support = 0; + HIP_CHECK(hipDeviceGetAttribute(&mem_pool_support, hipDeviceAttributeMemoryPoolsSupported, 0)); + if (!mem_pool_support) { + SUCCEED("Runtime doesn't support Memory Pool. Skip the test case."); + return; + } + hipMemPoolProps pool_props; + pool_props.allocType = hipMemAllocationTypePinned; + pool_props.handleTypes = hipMemHandleTypeNone; + pool_props.location.type = hipMemLocationTypeDevice; + pool_props.location.id = 0; + pool_props.win32SecurityAttributes = nullptr; + pool_props.maxSize = 1024 * 1024 * 1024; + memset(pool_props.reserved, 0, sizeof(pool_props.reserved)); + + float *A = nullptr, *B = nullptr; + hipStream_t stream; + HIP_CHECK(hipStreamCreate(&stream)); + hipMemPool_t mem_pool = nullptr; + HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props)); + HIP_CHECK(hipMallocFromPoolAsync (reinterpret_cast(&A), 1024 * 1024 * 512, mem_pool, stream)); + HIP_CHECK_ERROR(hipMallocFromPoolAsync (reinterpret_cast(&B), 1024 * 1024 * 513, mem_pool, stream), hipErrorMemoryAllocation); + HIP_CHECK(hipMemPoolDestroy(mem_pool)); + HIP_CHECK(hipStreamDestroy(stream)); +} + +TEST_CASE("Unit_hipMemPoolCreate_Without_maxSize") { + int mem_pool_support = 0; + HIP_CHECK(hipDeviceGetAttribute(&mem_pool_support, hipDeviceAttributeMemoryPoolsSupported, 0)); + if (!mem_pool_support) { + SUCCEED("Runtime doesn't support Memory Pool. Skip the test case."); + return; + } + hipMemPoolProps pool_props; + pool_props.allocType = hipMemAllocationTypePinned; + pool_props.handleTypes = hipMemHandleTypeNone; + pool_props.location.type = hipMemLocationTypeDevice; + pool_props.location.id = 0; + pool_props.win32SecurityAttributes = nullptr; + memset(pool_props.reserved, 0, sizeof(pool_props.reserved)); + + float *A = nullptr, *B = nullptr; + hipStream_t stream; + HIP_CHECK(hipStreamCreate(&stream)); + hipMemPool_t mem_pool = nullptr; + HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props)); + HIP_CHECK(hipMallocFromPoolAsync (reinterpret_cast(&A), 1024 * 1024 * 512, mem_pool, stream)); + HIP_CHECK(hipMallocFromPoolAsync (reinterpret_cast(&B), 1024 * 1024 * 513, mem_pool, stream)); + HIP_CHECK(hipMemPoolDestroy(mem_pool)); + HIP_CHECK(hipStreamDestroy(stream)); +} diff --git a/projects/hip-tests/catch/unit/memory/mempool_common.hh b/projects/hip-tests/catch/unit/memory/mempool_common.hh index 6e0dcc98bb..e92b5efded 100644 --- a/projects/hip-tests/catch/unit/memory/mempool_common.hh +++ b/projects/hip-tests/catch/unit/memory/mempool_common.hh @@ -24,7 +24,7 @@ namespace { constexpr hipMemPoolProps kPoolProps = { - hipMemAllocationTypePinned, hipMemHandleTypeNone, {hipMemLocationTypeDevice, 0}, nullptr, {0}}; + hipMemAllocationTypePinned, hipMemHandleTypeNone, {hipMemLocationTypeDevice, 0}, nullptr,0, {0}}; constexpr auto wait_ms = 500; } // anonymous namespace