SWDEV-311271 - [catch2][dtest] Adding test for mempool and stream ordered memory APIs
Change-Id: Iddeb111e4b512bfc7422abc8e784b0a8e8fb133d
이 커밋은 다음에 포함됨:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
@@ -17,7 +17,6 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include "mempool_common.hh"
|
||||
|
||||
#include <resource_guards.hh>
|
||||
#include <utils.hh>
|
||||
|
||||
@@ -48,18 +47,12 @@ static void MemPoolSetGetAttribute(const hipMemPool_t mempool, const hipMemPoolA
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetGetAttribute_Positive_Default") {
|
||||
const auto device = GENERATE(range(0, HipTest::getDeviceCount()));
|
||||
|
||||
int mem_pool_support = 0;
|
||||
HIP_CHECK(
|
||||
hipDeviceGetAttribute(&mem_pool_support, hipDeviceAttributeMemoryPoolsSupported, device));
|
||||
if (!mem_pool_support) {
|
||||
SUCCEED("Runtime doesn't support Memory Pool. Skip the test case.");
|
||||
return;
|
||||
}
|
||||
checkMempoolSupported(device)
|
||||
|
||||
const auto mempool_type = GENERATE(MemPools::dev_default, MemPools::created);
|
||||
MemPoolGuard mempool(mempool_type, device);
|
||||
@@ -87,18 +80,12 @@ TEST_CASE("Unit_hipMemPoolSetGetAttribute_Positive_Default") {
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetGetAttribute_Positive_MemBasic") {
|
||||
const auto device = GENERATE(range(0, HipTest::getDeviceCount()));
|
||||
|
||||
int mem_pool_support = 0;
|
||||
HIP_CHECK(
|
||||
hipDeviceGetAttribute(&mem_pool_support, hipDeviceAttributeMemoryPoolsSupported, device));
|
||||
if (!mem_pool_support) {
|
||||
SUCCEED("Runtime doesn't support Memory Pool. Skip the test case.");
|
||||
return;
|
||||
}
|
||||
checkMempoolSupported(device)
|
||||
|
||||
const auto mempool_type = GENERATE(MemPools::dev_default, MemPools::created);
|
||||
MemPoolGuard mempool(mempool_type, device);
|
||||
@@ -128,18 +115,13 @@ TEST_CASE("Unit_hipMemPoolSetGetAttribute_Positive_MemBasic") {
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetAttribute_Opportunistic") {
|
||||
int device_id = 0;
|
||||
HIP_CHECK(hipSetDevice(device_id));
|
||||
|
||||
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;
|
||||
}
|
||||
checkMempoolSupported(device_id)
|
||||
|
||||
MemPoolGuard mempool(MemPools::created, device_id);
|
||||
|
||||
@@ -349,18 +331,13 @@ TEST_CASE("Unit_hipMemPoolSetAttribute_Opportunistic") {
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetAttribute_EventDependencies") {
|
||||
int device_id = 0;
|
||||
HIP_CHECK(hipSetDevice(device_id));
|
||||
|
||||
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;
|
||||
}
|
||||
checkMempoolSupported(device_id)
|
||||
|
||||
MemPoolGuard mempool(MemPools::created, device_id);
|
||||
|
||||
@@ -494,12 +471,12 @@ TEST_CASE("Unit_hipMemPoolSetAttribute_EventDependencies") {
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetAttribute_Negative_Parameters") {
|
||||
int device_id = 0;
|
||||
HIP_CHECK(hipSetDevice(device_id));
|
||||
|
||||
checkMempoolSupported(device_id)
|
||||
MemPoolGuard mempool(MemPools::dev_default, device_id);
|
||||
|
||||
hipMemPoolAttr attr = hipMemPoolReuseFollowEventDependencies;
|
||||
@@ -536,6 +513,62 @@ TEST_CASE("Unit_hipMemPoolSetAttribute_Negative_Parameters") {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local function to reset hipMemPoolAttrReservedMemHigh and hipMemPoolAttrUsedMemHigh.
|
||||
*/
|
||||
static void resetHighValue(hipMemPool_t &memPool) {
|
||||
uint64_t value = 0;
|
||||
HIP_CHECK(hipMemPoolSetAttribute(memPool, hipMemPoolAttrReservedMemHigh,
|
||||
&value));
|
||||
HIP_CHECK(hipMemPoolSetAttribute(memPool, hipMemPoolAttrUsedMemHigh,
|
||||
&value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Reset hipMemPoolAttrReservedMemHigh and hipMemPoolAttrUsedMemHigh values
|
||||
* and validate their values.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolSetAttribute_ResetMemHighAttr") {
|
||||
checkMempoolSupported(0)
|
||||
// Create mempool
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
constexpr int N = 1 << 14;
|
||||
size_t byte_size = (N * sizeof(int));
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = 0;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
// Reset High Attributes
|
||||
resetHighValue(mem_pool);
|
||||
|
||||
// Allocate from mempool
|
||||
int *A_d;
|
||||
HIP_CHECK(hipMallocFromPoolAsync(reinterpret_cast<void**>(&A_d),
|
||||
byte_size, mem_pool, 0));
|
||||
// Deallocate
|
||||
HIP_CHECK(hipFreeAsync(A_d, 0));
|
||||
HIP_CHECK(hipStreamSynchronize(0));
|
||||
// Reset High Attributes
|
||||
resetHighValue(mem_pool);
|
||||
// Validate usage statistics
|
||||
uint64_t valueReservedHighAfterReset = 0, valueUsedHighAfterReset = 0;
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, hipMemPoolAttrReservedMemHigh,
|
||||
&valueReservedHighAfterReset));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, hipMemPoolAttrUsedMemHigh,
|
||||
&valueUsedHighAfterReset));
|
||||
REQUIRE(valueReservedHighAfterReset == 0);
|
||||
REQUIRE(valueUsedHighAfterReset == 0);
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
}
|
||||
|
||||
/**
|
||||
* End doxygen group hipMemPoolSetAttribute.
|
||||
* @}
|
||||
@@ -562,12 +595,12 @@ TEST_CASE("Unit_hipMemPoolSetAttribute_Negative_Parameters") {
|
||||
* - /unit/memory/hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.0
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_Negative_Parameters") {
|
||||
int device_id = 0;
|
||||
HIP_CHECK(hipSetDevice(device_id));
|
||||
|
||||
checkMempoolSupported(device_id)
|
||||
MemPoolGuard mempool(MemPools::dev_default, device_id);
|
||||
|
||||
|
||||
@@ -588,3 +621,392 @@ TEST_CASE("Unit_hipMemPoolGetAttribute_Negative_Parameters") {
|
||||
HIP_CHECK_ERROR(hipMemPoolGetAttribute(mempool.mempool(), attr, nullptr), hipErrorInvalidValue);
|
||||
}
|
||||
}
|
||||
|
||||
constexpr int iterations = 20;
|
||||
static int reservedHighExp = 0;
|
||||
static int usedHighExp = 0;
|
||||
|
||||
struct mempoolUsgStat {
|
||||
uint64_t reservedMem;
|
||||
uint64_t reservedMemHigh;
|
||||
uint64_t usedMem;
|
||||
uint64_t usedMemHigh;
|
||||
};
|
||||
|
||||
/**
|
||||
* Local function to fetch usage statistics.
|
||||
*/
|
||||
static void getUsageStatistics(hipMemPool_t &memPool, struct mempoolUsgStat *stat) {
|
||||
HIP_CHECK(hipMemPoolGetAttribute(memPool, hipMemPoolAttrReservedMemCurrent,
|
||||
&(stat->reservedMem)));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(memPool, hipMemPoolAttrReservedMemHigh,
|
||||
&(stat->reservedMemHigh)));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(memPool, hipMemPoolAttrUsedMemCurrent,
|
||||
&(stat->usedMem)));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(memPool, hipMemPoolAttrUsedMemHigh,
|
||||
&(stat->usedMemHigh)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Local function to get default mempool attribute values.
|
||||
*/
|
||||
static bool checkDefaultAttributeValues(hipMemPoolAttr attr, int dev) {
|
||||
// Create mempool in current device
|
||||
uint64_t ui64_setValue = 0;
|
||||
int i32_setValue = 0;
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = dev;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
if (attr == hipMemPoolAttrReleaseThreshold) {
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, attr, &ui64_setValue));
|
||||
REQUIRE(ui64_setValue == 0);
|
||||
} else {
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, attr, &i32_setValue));
|
||||
REQUIRE(i32_setValue == 1);
|
||||
}
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local function to set mempool attribute values and validate
|
||||
* by getting the values.
|
||||
*/
|
||||
static bool checkhipMemPoolSetAttribute(hipMemPoolAttr attr, int dev) {
|
||||
// Create mempool in current device
|
||||
uint64_t ui64_setValue = 0;
|
||||
int i32_setValue = 0;
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = dev;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
if (attr == hipMemPoolAttrReleaseThreshold) {
|
||||
uint64_t val = UINT64_MAX;
|
||||
HIP_CHECK(hipMemPoolSetAttribute(mem_pool, attr, &val));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, attr, &ui64_setValue));
|
||||
REQUIRE(ui64_setValue == val);
|
||||
} else {
|
||||
int val = 0;
|
||||
HIP_CHECK(hipMemPoolSetAttribute(mem_pool, attr, &val));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool, attr, &i32_setValue));
|
||||
REQUIRE(i32_setValue == val);
|
||||
}
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate hipMemPoolGetAttribute() by setting hipMemPoolSetAttribute().
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_SetGet") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
for (int dev = 0; dev < numDevices; dev++) {
|
||||
checkMempoolSupported(dev)
|
||||
REQUIRE(true == checkhipMemPoolSetAttribute(
|
||||
hipMemPoolAttrReleaseThreshold, dev));
|
||||
REQUIRE(true == checkhipMemPoolSetAttribute(
|
||||
hipMemPoolReuseFollowEventDependencies, dev));
|
||||
REQUIRE(true == checkhipMemPoolSetAttribute(
|
||||
hipMemPoolReuseAllowOpportunistic, dev));
|
||||
REQUIRE(true == checkhipMemPoolSetAttribute(
|
||||
hipMemPoolReuseAllowInternalDependencies, dev));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate hipMemPoolAttrUsedMemCurrent value.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_UsedMem") {
|
||||
checkMempoolSupported(0)
|
||||
constexpr int N = 1 << 14;
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = 0;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
size_t byte_size = (N * sizeof(int));
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
// Get hipMemPoolAttrUsedMemCurrent value for mem_pool when no memory
|
||||
// is allocated from this pool.
|
||||
SECTION("Check created mempool") {
|
||||
uint64_t val = 0;
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrUsedMemCurrent, &val));
|
||||
REQUIRE(val == 0);
|
||||
int *A_d;
|
||||
// Allocate memory on dev0 from mem_pool.
|
||||
HIP_CHECK(hipMallocFromPoolAsync(reinterpret_cast<void**>(&A_d),
|
||||
byte_size, mem_pool, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Get hipMemPoolAttrUsedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrUsedMemCurrent, &val));
|
||||
REQUIRE(val == byte_size);
|
||||
// Free memory back to memory pool.
|
||||
HIP_CHECK(hipFreeAsync(reinterpret_cast<void*>(A_d), stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Again get hipMemPoolAttrUsedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrUsedMemCurrent, &val));
|
||||
REQUIRE(val == 0);
|
||||
}
|
||||
SECTION("Check default mempool") {
|
||||
hipMemPool_t mem_pool_default = nullptr;
|
||||
// assign default mem pool to device
|
||||
HIP_CHECK(hipDeviceGetDefaultMemPool(&mem_pool_default, 0));
|
||||
uint64_t valInitital = 0, valPostAlloc = 0, valPostFree = 0;
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool_default,
|
||||
hipMemPoolAttrUsedMemCurrent, &valInitital));
|
||||
int *A_d;
|
||||
// Allocate memory on dev0 from mem_pool.
|
||||
HIP_CHECK(hipMallocAsync(reinterpret_cast<void**>(&A_d),
|
||||
byte_size, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Get hipMemPoolAttrUsedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool_default,
|
||||
hipMemPoolAttrUsedMemCurrent, &valPostAlloc));
|
||||
uint64_t expVal = byte_size;
|
||||
expVal = expVal + valInitital;
|
||||
REQUIRE(valPostAlloc == expVal);
|
||||
// Free memory back to memory pool.
|
||||
HIP_CHECK(hipFreeAsync(reinterpret_cast<void*>(A_d), stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Again get hipMemPoolAttrUsedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool_default,
|
||||
hipMemPoolAttrUsedMemCurrent, &valPostFree));
|
||||
REQUIRE(valPostFree == valInitital);
|
||||
}
|
||||
SECTION("Default memory pool allocation") {
|
||||
uint64_t val = 0;
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrUsedMemCurrent, &val));
|
||||
REQUIRE(val == 0);
|
||||
int *A_d;
|
||||
// Allocate memory on dev0 from mem_pool.
|
||||
HIP_CHECK(hipMallocAsync(reinterpret_cast<void**>(&A_d),
|
||||
byte_size, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Get hipMemPoolAttrUsedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrUsedMemCurrent, &val));
|
||||
REQUIRE(val == 0);
|
||||
// Free memory back to memory pool.
|
||||
HIP_CHECK(hipFreeAsync(reinterpret_cast<void*>(A_d), stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
}
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate hipMemPoolAttrReservedMemCurrent value.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_ReservedMem") {
|
||||
checkMempoolSupported(0)
|
||||
constexpr int N = 1 << 14;
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = 0;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
uint64_t val = 0;
|
||||
// Verify that at the beginning mempool contains at least
|
||||
// 0 memory reserved.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrReservedMemCurrent, &val));
|
||||
REQUIRE(val >= 0);
|
||||
size_t byte_size = (N * sizeof(int));
|
||||
hipStream_t stream;
|
||||
HIP_CHECK(hipStreamCreate(&stream));
|
||||
int *A_d;
|
||||
// Allocate memory on dev0 from mem_pool.
|
||||
HIP_CHECK(hipMallocFromPoolAsync(reinterpret_cast<void**>(&A_d),
|
||||
byte_size, mem_pool, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrReservedMemCurrent, &val));
|
||||
REQUIRE(val >= byte_size);
|
||||
// Free memory back to memory pool.
|
||||
HIP_CHECK(hipFreeAsync(reinterpret_cast<void*>(A_d), stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
// Again get hipMemPoolAttrReservedMemCurrent value for mem_pool and validate
|
||||
// its value.
|
||||
HIP_CHECK(hipMemPoolGetAttribute(mem_pool,
|
||||
hipMemPoolAttrReservedMemCurrent, &val));
|
||||
REQUIRE(val >= 0);
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate hipMemPoolAttrReservedMemHigh and hipMemPoolAttrUsedMemHigh value.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_UsageStatistics") {
|
||||
checkMempoolSupported(0)
|
||||
struct mempoolUsgStat stats;
|
||||
// Create mempool
|
||||
hipMemPool_t mem_pool;
|
||||
hipMemPoolProps pool_props{};
|
||||
constexpr int N = 1 << 14;
|
||||
size_t byte_size = (N * sizeof(int));
|
||||
pool_props.allocType = hipMemAllocationTypePinned;
|
||||
pool_props.location.id = 0;
|
||||
pool_props.location.type = hipMemLocationTypeDevice;
|
||||
HIP_CHECK(hipMemPoolCreate(&mem_pool, &pool_props));
|
||||
// Reset and Take Usage Statistics
|
||||
resetHighValue(mem_pool);
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
// Validate usage statistics
|
||||
REQUIRE(stats.reservedMem == stats.reservedMemHigh);
|
||||
REQUIRE(stats.usedMem == 0);
|
||||
REQUIRE(stats.usedMemHigh == 0);
|
||||
|
||||
// Allocate from mempool
|
||||
int *A_d[iterations];
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
HIP_CHECK(hipMallocFromPoolAsync(reinterpret_cast<void**>(&A_d[i]),
|
||||
byte_size, mem_pool, 0));
|
||||
}
|
||||
HIP_CHECK(hipStreamSynchronize(0));
|
||||
// Take Usage Statistics
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
// Validate usage statistics
|
||||
REQUIRE(stats.reservedMem == stats.reservedMemHigh);
|
||||
REQUIRE(stats.usedMem == (iterations*byte_size));
|
||||
REQUIRE(stats.usedMemHigh == (iterations*byte_size));
|
||||
reservedHighExp = stats.reservedMemHigh;
|
||||
usedHighExp = (iterations*byte_size);
|
||||
|
||||
// Deallocate half of the allocations
|
||||
for (int i = 0; i < iterations/2; i++) {
|
||||
HIP_CHECK(hipFreeAsync(A_d[i], 0));
|
||||
}
|
||||
HIP_CHECK(hipStreamSynchronize(0));
|
||||
// Take Usage Statistics
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
// Validate usage statistics
|
||||
REQUIRE(stats.reservedMemHigh == reservedHighExp);
|
||||
REQUIRE(stats.usedMem == (iterations*byte_size - (iterations/2)*byte_size));
|
||||
REQUIRE(stats.usedMemHigh == usedHighExp);
|
||||
|
||||
// Deallocate remaining allocations
|
||||
for (int i = (iterations/2); i < iterations; i++) {
|
||||
HIP_CHECK(hipFreeAsync(A_d[i], 0));
|
||||
}
|
||||
HIP_CHECK(hipStreamSynchronize(0));
|
||||
// Take Usage Statistics
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
// Validate usage statistics
|
||||
REQUIRE(stats.reservedMemHigh == reservedHighExp);
|
||||
REQUIRE(stats.usedMem == 0);
|
||||
REQUIRE(stats.usedMemHigh == usedHighExp);
|
||||
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate hipMalloc does not affect default mempool
|
||||
* statistics.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_hipMalloc_DefMempool") {
|
||||
checkMempoolSupported(0)
|
||||
struct mempoolUsgStat stats;
|
||||
// Create mempool
|
||||
hipMemPool_t mem_pool;
|
||||
constexpr int N = 1 << 14;
|
||||
size_t byte_size = (N * sizeof(int));
|
||||
// Get default mempool
|
||||
HIP_CHECK(hipDeviceGetDefaultMemPool(&mem_pool, 0));
|
||||
// Reset and Take Usage Statistics
|
||||
resetHighValue(mem_pool);
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
uint64_t reservedMemStart, reservedMemHighStart, usedMemStart,
|
||||
usedMemHighStart;
|
||||
reservedMemStart = stats.reservedMem;
|
||||
reservedMemHighStart = stats.reservedMemHigh;
|
||||
usedMemStart = stats.usedMem;
|
||||
usedMemHighStart = stats.usedMemHigh;
|
||||
// Allocate using hipMalloc
|
||||
int *Ad;
|
||||
HIP_CHECK(hipMalloc(&Ad, byte_size));
|
||||
getUsageStatistics(mem_pool, &stats);
|
||||
REQUIRE(reservedMemStart == stats.reservedMem);
|
||||
REQUIRE(reservedMemHighStart == stats.reservedMemHigh);
|
||||
REQUIRE(usedMemStart == stats.usedMem);
|
||||
REQUIRE(usedMemHighStart == stats.usedMemHigh);
|
||||
HIP_CHECK(hipFree(Ad));
|
||||
}
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Validate default attribute values.
|
||||
* ------------------------
|
||||
* - catch\unit\memory\hipMemPoolSetGetAttribute.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 6.2
|
||||
*/
|
||||
TEST_CASE("Unit_hipMemPoolGetAttribute_CheckDefaultValues") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
for (int dev = 0; dev < numDevices; dev++) {
|
||||
checkMempoolSupported(dev)
|
||||
REQUIRE(true == checkDefaultAttributeValues(
|
||||
hipMemPoolAttrReleaseThreshold, dev));
|
||||
REQUIRE(true == checkDefaultAttributeValues(
|
||||
hipMemPoolReuseFollowEventDependencies, dev));
|
||||
REQUIRE(true == checkDefaultAttributeValues(
|
||||
hipMemPoolReuseAllowOpportunistic, dev));
|
||||
REQUIRE(true == checkDefaultAttributeValues(
|
||||
hipMemPoolReuseAllowInternalDependencies, dev));
|
||||
}
|
||||
}
|
||||
|
||||
새 이슈에서 참조
사용자 차단