diff --git a/projects/hip-tests/catch/multiproc/hipMallocConcurrencyMproc.cc b/projects/hip-tests/catch/multiproc/hipMallocConcurrencyMproc.cc index 9018f694a2..d13a31949d 100644 --- a/projects/hip-tests/catch/multiproc/hipMallocConcurrencyMproc.cc +++ b/projects/hip-tests/catch/multiproc/hipMallocConcurrencyMproc.cc @@ -103,6 +103,14 @@ static bool validateMemoryOnGPU(int gpu, bool concurOnOneGPU = false) { HIP_CHECK(hipSetDevice(gpu)); HIP_CHECK(hipMemGetInfo(&prevAvl, &prevTot)); HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false); + HIP_CHECK(hipMemGetInfo(&curAvl, &curTot)); + + if (!concurOnOneGPU && (prevAvl < curAvl || prevTot != curTot)) { + //In concurrent calls on one GPU, we cannot verify leaking in this way + printf("%s : Memory allocation mismatch observed." + "Possible memory leak.\n", __func__); + TestPassed &= false; + } unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N); @@ -122,9 +130,17 @@ static bool validateMemoryOnGPU(int gpu, bool concurOnOneGPU = false) { TestPassed = false; } + HIP_CHECK(hipMemGetInfo(&prevAvl, &prevTot)); HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); HIP_CHECK(hipMemGetInfo(&curAvl, &curTot)); + if (!concurOnOneGPU && (curAvl < prevAvl || prevTot != curTot)) { + // In concurrent calls on one GPU, we cannot verify leaking in this way + UNSCOPED_INFO("validateMemoryOnGPU : Memory allocation mismatch observed." + << "Possible memory leak."); + TestPassed = false; + } + if (!concurOnOneGPU && (prevAvl != curAvl || prevTot != curTot)) { // In concurrent calls on one GPU, we cannot verify leaking in this way printf( @@ -200,7 +216,7 @@ TEST_CASE("Unit_hipMalloc_ChildConcurrencyMultiGpu") { } else if (!pid) { // Child process bool TestPassedChild = false; - TestPassedChild = validateMemoryOnGPU(gpu); + TestPassedChild = validateMemoryOnGPU(gpu, true); if (TestPassedChild) { exit(resSuccess); // child exit with success status diff --git a/projects/hip-tests/catch/unit/memory/hipMallocConcurrency.cc b/projects/hip-tests/catch/unit/memory/hipMallocConcurrency.cc index 647d38d99d..1283284022 100644 --- a/projects/hip-tests/catch/unit/memory/hipMallocConcurrency.cc +++ b/projects/hip-tests/catch/unit/memory/hipMallocConcurrency.cc @@ -203,6 +203,14 @@ static bool validateMemoryOnGpuMThread(int gpu, bool concurOnOneGPU = false) { HIPCHECK(hipSetDevice(gpu)); HIPCHECK(hipMemGetInfo(&prevAvl, &prevTot)); HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false); + HIPCHECK(hipMemGetInfo(&curAvl, &curTot)); + + if (!concurOnOneGPU && (prevAvl < curAvl || prevTot != curTot)) { + //In concurrent calls on one GPU, we cannot verify leaking in this way + printf("%s : Memory allocation mismatch observed." + "Possible memory leak.\n", __func__); + TestPassed &= false; + } unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N); @@ -221,9 +229,17 @@ static bool validateMemoryOnGpuMThread(int gpu, bool concurOnOneGPU = false) { TestPassed = false; } + HIPCHECK(hipMemGetInfo(&prevAvl, &prevTot)); HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false); HIPCHECK(hipMemGetInfo(&curAvl, &curTot)); + if (!concurOnOneGPU && (curAvl < prevAvl || prevTot != curTot)) { + // In concurrent calls on one GPU, we cannot verify leaking in this way + UNSCOPED_INFO("validateMemoryOnGPU : Memory allocation mismatch observed." + << "Possible memory leak."); + TestPassed = false; + } + if (!concurOnOneGPU && (prevAvl != curAvl || prevTot != curTot)) { // In concurrent calls on one GPU, we cannot verify leaking in this way UNSCOPED_INFO( @@ -291,7 +307,7 @@ static bool regressAllocInLoopMthread(int gpu) { * Thread func to regress alloc and check data consistency */ static void threadFunc(int gpu) { - g_thTestPassed = regressAllocInLoopMthread(gpu) && validateMemoryOnGpuMThread(gpu); + g_thTestPassed = regressAllocInLoopMthread(gpu) && validateMemoryOnGpuMThread(gpu, true); UNSCOPED_INFO("thread execution status on gpu" << gpu << ":" << g_thTestPassed.load()); }