SWDEV-548500 - Resolve memory leaks in memory tests (#1093)
This commit is contained in:
@@ -49,10 +49,8 @@ TEST_CASE("Unit_hipDrvPtrGetAttributes_Negative") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
int* A_d;
|
||||
int* A_Pinned_h;
|
||||
|
||||
HIP_CHECK(hipMalloc(&A_d, Nbytes));
|
||||
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A_Pinned_h), Nbytes, hipHostMallocDefault));
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
unsigned int device_ordinal;
|
||||
int* dev_ptr{nullptr};
|
||||
@@ -94,6 +92,8 @@ TEST_CASE("Unit_hipDrvPtrGetAttributes_Negative") {
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
}
|
||||
|
||||
// Testcase verifies functional scenarios of hipDrvPointerGetAttributes API
|
||||
@@ -104,10 +104,8 @@ TEST_CASE("Unit_hipDrvPtrGetAttributes_Functional") {
|
||||
int numDevices = 0;
|
||||
HIP_CHECK(hipGetDeviceCount(&numDevices));
|
||||
int* A_d;
|
||||
int* A_Pinned_h;
|
||||
|
||||
HIP_CHECK(hipMalloc(&A_d, Nbytes));
|
||||
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A_Pinned_h), Nbytes, hipHostMallocDefault));
|
||||
HIP_CHECK(hipGetDevice(&deviceId));
|
||||
|
||||
SECTION("Passing device attributes to device pointer") {
|
||||
@@ -165,13 +163,20 @@ TEST_CASE("Unit_hipDrvPtrGetAttributes_Functional") {
|
||||
int device_ordinal;
|
||||
void* data[2];
|
||||
int* host_ptr;
|
||||
int* pinned_host_ptr;
|
||||
data[0] = (&host_ptr);
|
||||
data[1] = (&device_ordinal);
|
||||
|
||||
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&pinned_host_ptr), Nbytes, hipHostMallocDefault));
|
||||
|
||||
hipPointer_attribute attributes[] = {HIP_POINTER_ATTRIBUTE_HOST_POINTER,
|
||||
HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL};
|
||||
HIP_CHECK(hipDrvPointerGetAttributes(2, attributes, data,
|
||||
reinterpret_cast<hipDeviceptr_t>(A_Pinned_h)));
|
||||
REQUIRE(host_ptr == A_Pinned_h);
|
||||
reinterpret_cast<hipDeviceptr_t>(pinned_host_ptr)));
|
||||
REQUIRE(host_ptr == pinned_host_ptr);
|
||||
REQUIRE(device_ordinal == deviceId);
|
||||
HIP_CHECK(hipFreeHost(pinned_host_ptr));
|
||||
}
|
||||
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ TEST_CASE("Unit_hipFreeNegativeHost") {
|
||||
auto flag = GENERATE(hipHostRegisterDefault, hipHostRegisterPortable, hipHostRegisterMapped);
|
||||
HIP_CHECK(hipHostRegister((void*)hostPtr, sizeof(char), flag));
|
||||
HIP_CHECK_ERROR(hipHostFree(hostPtr), hipErrorInvalidValue);
|
||||
HIP_CHECK(hipHostUnregister(hostPtr));
|
||||
delete hostPtr;
|
||||
}
|
||||
#if (HT_AMD == 1) && (HT_LINUX == 1)
|
||||
|
||||
@@ -96,7 +96,7 @@ TEST_CASE("Unit_hipFreeHost_Multithreading") {
|
||||
std::vector<unsigned long*> ptrs(10);
|
||||
size_t ptr_size = 1024;
|
||||
|
||||
for (auto ptr : ptrs) {
|
||||
for (auto& ptr : ptrs) {
|
||||
HIP_CHECK(hipHostMalloc(&ptr, ptr_size));
|
||||
}
|
||||
|
||||
|
||||
@@ -240,10 +240,10 @@ TEST_CASE("Unit_hipHostAlloc_Basic") {
|
||||
TEST_CASE("Unit_hipHostAlloc_Default") {
|
||||
int* A = nullptr;
|
||||
HIP_CHECK(hipHostAlloc(reinterpret_cast<void**>(&A), SIZEBYTES, hipHostMallocDefault));
|
||||
const char* ptrType = "default";
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_EVENT, ptrType);
|
||||
std::string kPtrType{"default"};
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_DEVICE, kPtrType);
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_STREAM, kPtrType);
|
||||
CheckHostPointer(NUMELEMENTS, A, 0, SYNC_EVENT, kPtrType);
|
||||
HIP_CHECK(hipHostFree(A));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,12 +42,13 @@ TEST_CASE("Unit_hipHostFree_InvalidMemory") {
|
||||
}
|
||||
|
||||
SECTION("Host registered memory") {
|
||||
const size_t ptr_size = 1024;
|
||||
char* ptr = new char[ptr_size];
|
||||
constexpr size_t kPtrSize = 1024;
|
||||
auto ptr = std::make_unique<char[]>(kPtrSize);
|
||||
auto flag = GENERATE(hipHostRegisterDefault, hipHostRegisterPortable, hipHostRegisterMapped);
|
||||
|
||||
HIP_CHECK(hipHostRegister(ptr, ptr_size, flag));
|
||||
HIP_CHECK_ERROR(hipHostFree(ptr), hipErrorInvalidValue);
|
||||
HIP_CHECK(hipHostRegister(ptr.get(), kPtrSize, flag));
|
||||
HIP_CHECK_ERROR(hipHostFree(ptr.get()), hipErrorInvalidValue);
|
||||
HIP_CHECK(hipHostUnregister(ptr.get()));
|
||||
}
|
||||
|
||||
#if (HT_AMD == 1) && (HT_LINUX == 1)
|
||||
|
||||
@@ -156,6 +156,7 @@ TEST_CASE("Unit_hipHostMalloc_Basic") {
|
||||
HIP_CHECK(hipHostFree(A_h));
|
||||
HIP_CHECK(hipHostFree(B_h));
|
||||
HIP_CHECK(hipHostFree(C_h));
|
||||
HIP_CHECK(hipFree(B_d));
|
||||
}
|
||||
}
|
||||
/*
|
||||
@@ -188,6 +189,7 @@ TEST_CASE("Unit_hipHostMalloc_NonCoherent") {
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
HIP_CHECK(hipFreeHost(A));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -209,6 +211,8 @@ TEST_CASE("Unit_hipHostMalloc_Coherent") {
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType);
|
||||
|
||||
HIP_CHECK(hipFreeHost(A));
|
||||
} else {
|
||||
SUCCEED("Coherence memory allocation failed. Is SVM atomic supported?");
|
||||
}
|
||||
@@ -229,6 +233,7 @@ TEST_CASE("Unit_hipHostMalloc_Default") {
|
||||
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
|
||||
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
|
||||
HIP_CHECK(hipFreeHost(A));
|
||||
}
|
||||
|
||||
TEST_CASE("Unit_hipHostGetDevicePointer_NullCheck") {
|
||||
|
||||
@@ -493,6 +493,7 @@ TEST_CASE("Unit_hipMemAdvise_TstAccessedByFlg") {
|
||||
HIP_CHECK(hipMemAdvise(Hmm, 2 * 4096, hipMemAdviseSetAccessedBy, 0));
|
||||
HIP_CHECK(hipMemRangeGetAttribute(&data, sizeof(int), hipMemRangeAttributeLastPrefetchLocation,
|
||||
Hmm, 2 * 4096));
|
||||
HIP_CHECK(hipFree(Hmm));
|
||||
if (data != -2) {
|
||||
WARN("Didnt get expected value!!\n");
|
||||
REQUIRE(false);
|
||||
@@ -899,6 +900,8 @@ TEST_CASE("Unit_hipMemAdvise_TstSetUnsetPrfrdLoc") {
|
||||
WARN("Didnt receive expected value!!");
|
||||
REQUIRE(false);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipFree(Hmm));
|
||||
} else {
|
||||
SUCCEED(
|
||||
"GPU 0 doesn't support hipDeviceAttributeManagedMemory "
|
||||
|
||||
@@ -114,6 +114,7 @@ TEST_CASE("Unit_hipMemPoolCreate_With_maxSize") {
|
||||
HIP_CHECK(
|
||||
hipMallocFromPoolAsync(reinterpret_cast<void**>(&B), 1024 * 1024 * 513, mem_pool, stream));
|
||||
#endif
|
||||
HIP_CHECK(hipFreeAsync(A, stream));
|
||||
HIP_CHECK(hipMemPoolDestroy(mem_pool));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
@@ -291,13 +291,7 @@ TEST_CASE("Unit_hipMemRangeGetAttributes_NegativeTst") {
|
||||
}
|
||||
REQUIRE(IfTestPassed);
|
||||
|
||||
// The following scenarios have been removed considering the nature of the
|
||||
// api. With Consultation with Maneesh Gupta, the following scenarios
|
||||
// have been removed.
|
||||
// passing numAttributes as 4 while the attributes array has only 2 members
|
||||
// passing numAttributes as 10 while the attributes array has only 2 members
|
||||
// length of the list of dataSizes less than the number of
|
||||
// attributes being probed
|
||||
HIP_CHECK(hipFree(Hmm));
|
||||
} else {
|
||||
SUCCEED(
|
||||
"GPU 0 doesn't support hipDeviceAttributeManagedMemory "
|
||||
|
||||
@@ -209,6 +209,10 @@ TEST_CASE("Unit_hipMemcpyToFromSymbol_SyncAndAsync") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (streamType == StreamTestType::CreatedStream) {
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -189,6 +189,7 @@ TEST_CASE("Unit_hipPointerGetAttribute_BufferID") {
|
||||
HIP_CHECK(hipPointerGetAttribute(&bufid2, HIP_POINTER_ATTRIBUTE_BUFFER_ID,
|
||||
reinterpret_cast<hipDeviceptr_t>(A_d)));
|
||||
REQUIRE(bufid1 != bufid2);
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
}
|
||||
|
||||
/* Allocate host memory and get the device ordinal by calling
|
||||
@@ -240,6 +241,7 @@ TEST_CASE("Unit_hipPointerGetAttribute_MappedMem") {
|
||||
REQUIRE(mallocManaged == 1);
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
HIP_CHECK(hipHostFree(ptr1));
|
||||
HIP_CHECK(hipFree(ptr2));
|
||||
free(A_h);
|
||||
}
|
||||
|
||||
@@ -276,8 +278,6 @@ TEST_CASE("Unit_hipPointerGetAttribute_Negative") {
|
||||
reinterpret_cast<hipDeviceptr_t>(B_d)) == hipErrorInvalidValue);
|
||||
}
|
||||
SECTION("Get Start address of host pointer") {
|
||||
char* A_h;
|
||||
A_h = reinterpret_cast<char*>(malloc(Nbytes));
|
||||
REQUIRE(hipPointerGetAttribute(&data, HIP_POINTER_ATTRIBUTE_RANGE_START_ADDR,
|
||||
reinterpret_cast<hipDeviceptr_t>(A_h)) == hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
@@ -147,4 +147,8 @@ TEST_CASE("Unit_hipPtrGetAttribute_Simple") {
|
||||
HIP_CHECK(hipPointerGetAttribute(&bufId2, HIP_POINTER_ATTRIBUTE_BUFFER_ID,
|
||||
reinterpret_cast<hipDeviceptr_t>(A_Pinned_h)));
|
||||
REQUIRE(bufId1 != bufId2);
|
||||
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
HIP_CHECK(hipHostFree(A_Pinned_h));
|
||||
HIP_CHECK(hipFree(A_Hmm));
|
||||
}
|
||||
|
||||
Verwijs in nieuw issue
Block a user