SWDEV-485763 - Fix memory leaks in various unit tests
Fix memory leaks by adding missing destroy calls for events, streams, and graphs at the end of tests. Ensure that every test case executes destroy calls, regardless of whether it passes or fails. Change-Id: I814e35c528d90ed2abb34d77377f1a7fd3f1f11c
이 커밋은 다음에 포함됨:
1 부모
7bb49582db
커밋
9cffda4ebb
33 파일이 변경됨
+142
-38
검색과 일치하는 파일 없음
@@ -105,6 +105,9 @@ static void hipWithoutGraphs(float* inputVec_h, float* inputVec_d,
|
||||
INFO("Time taken for hipWithoutGraphs : "
|
||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(result).count()
|
||||
<< " millisecs ");
|
||||
HIP_CHECK(hipEventDestroy(forkStreamEvent));
|
||||
HIP_CHECK(hipEventDestroy(memsetEvent1));
|
||||
HIP_CHECK(hipEventDestroy(memsetEvent2));
|
||||
HIP_CHECK(hipStreamDestroy(stream1));
|
||||
HIP_CHECK(hipStreamDestroy(stream2));
|
||||
HIP_CHECK(hipStreamDestroy(stream3));
|
||||
|
||||
@@ -208,6 +208,7 @@ void hipGraphClone_Func(bool ModifyOrigGraph = false) {
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
|
||||
for (size_t i= 0; i < NElem; i++) {
|
||||
if (C_h[i] != B_h[i]) {
|
||||
|
||||
@@ -1302,6 +1302,7 @@ static void hipGraphClone_Test_hipGraphEventRecordNodeSetEvent_and_Exec() {
|
||||
nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphLaunch(clonedGraphExec, cg.stream));
|
||||
HIP_CHECK(hipStreamSynchronize(cg.stream));
|
||||
HIP_CHECK(hipGraphExecDestroy(clonedGraphExec));
|
||||
|
||||
// Verify graph execution result
|
||||
HipTest::checkVectorADD(cg.B_h, cg.C_h, cg.A_h, N);
|
||||
@@ -1332,6 +1333,7 @@ static void hipGraphClone_Test_hipGraphEventRecordNodeSetEvent_and_Exec() {
|
||||
HipTest::checkVectorADD(cg.B_h, cg.C_h, cg.A_h, N);
|
||||
|
||||
HIP_CHECK(hipEventDestroy(event_end2));
|
||||
HIP_CHECK(hipGraphExecDestroy(clonedGraphExec));
|
||||
}
|
||||
SECTION("Verify hipGraphEventRecordNodeSetEvent & event_end->event_end3") {
|
||||
hipEvent_t event_end3;
|
||||
@@ -1414,9 +1416,9 @@ static void hipGraphClone_Test_hipGraphEventRecordNodeSetEvent_and_Exec() {
|
||||
HipTest::checkVectorADD(cg.B_h, cg.C_h, cg.A_h, N);
|
||||
|
||||
HIP_CHECK(hipEventDestroy(event_end5));
|
||||
HIP_CHECK(hipGraphExecDestroy(clonedGraphExec));
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(clonedGraphExec));
|
||||
HIP_CHECK(hipGraphDestroy(clonedGraph));
|
||||
HIP_CHECK(hipGraphDestroy(childgraph));
|
||||
HIP_CHECK(hipEventDestroy(event_start));
|
||||
@@ -1518,6 +1520,9 @@ static void hipGraphClone_Test_hipGraphEventWaitNodeSetEvent_and_Exec() {
|
||||
HIP_CHECK(hipGraphEventRecordNodeSetEvent(event_rec_node, event_2));
|
||||
HIP_CHECK(hipGraphEventWaitNodeSetEvent(event_wait_node, event_2));
|
||||
|
||||
// Destroy clonedGraphExec before instantating a new one
|
||||
HIP_CHECK(hipGraphExecDestroy(clonedGraphExec));
|
||||
|
||||
// Instantiate and launch the graph
|
||||
HIP_CHECK(hipGraphInstantiate(&clonedGraphExec, clonedGraph,
|
||||
nullptr, nullptr, 0));
|
||||
@@ -2126,4 +2131,3 @@ TEST_CASE("Unit_hipGraphChild_hipUserObject_hipGraphUserObject") {
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ TEST_CASE("Unit_hipGraph_BasicCyclic1") {
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
REQUIRE(hipErrorInvalidValue == hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,13 +84,15 @@ TEST_CASE("Unit_hipGraph_BasicCyclic2") {
|
||||
HIP_CHECK(hipGraphRemoveDependencies(graph, &emptyNode3, &emptyNode1, 1));
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests basic functionality of cycle detection in hipGraph APIs by
|
||||
* Adding manual empty nodes
|
||||
* Cyclic graph, cycle formation first, Remove edge causes disconnected graph which is still
|
||||
* Cyclic graph, cycle formation first, Remove edge causes disconnected graph which is still
|
||||
* cyclic
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraph_BasicCyclic3") {
|
||||
@@ -115,6 +118,7 @@ TEST_CASE("Unit_hipGraph_BasicCyclic3") {
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
REQUIRE(hipErrorInvalidValue == hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -284,6 +284,7 @@ static void hipGraphDebugDotPrint_Functional(const char* fName,
|
||||
free(mem_h);
|
||||
HIP_CHECK(hipFree(mem_d));
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIP_CHECK(hipEventDestroy(event));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipGraphDestroy(childGraph));
|
||||
|
||||
@@ -182,6 +182,7 @@ TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative") {
|
||||
}
|
||||
HipTest::freeArrays<int>(A_d, B_d, nullptr,
|
||||
A_h, B_h, nullptr, false);
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
}
|
||||
|
||||
|
||||
@@ -181,14 +181,14 @@ TEST_CASE("Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Negative_Parameters") {
|
||||
SECTION("Changing src allocation device") {
|
||||
if (HipTest::getDeviceCount() < 2) {
|
||||
HipTest::HIP_SKIP_TEST("Test requires two connected GPUs");
|
||||
return;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
LinearAllocGuard<int> new_var(LinearAllocs::hipMalloc, sizeof(int));
|
||||
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParamsToSymbol(
|
||||
graph_exec, node, SYMBOL(int_device_var), new_var.ptr(),
|
||||
sizeof(*new_var.ptr()), 0, static_cast<hipMemcpyKind>(-1)),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
LinearAllocGuard<int> new_var(LinearAllocs::hipMalloc, sizeof(int));
|
||||
HIP_CHECK_ERROR(hipGraphExecMemcpyNodeSetParamsToSymbol(
|
||||
graph_exec, node, SYMBOL(int_device_var), new_var.ptr(),
|
||||
sizeof(*new_var.ptr()), 0, static_cast<hipMemcpyKind>(-1)),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graph_exec));
|
||||
|
||||
@@ -167,13 +167,13 @@ TEST_CASE("Unit_hipGraphExecMemsetNodeSetParams_Negative_Parameters") {
|
||||
SECTION("Changing dst allocation device") {
|
||||
if (HipTest::getDeviceCount() < 2) {
|
||||
HipTest::HIP_SKIP_TEST("Test requires two connected GPUs");
|
||||
return;
|
||||
} else {
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
LinearAllocGuard<int> new_alloc(LinearAllocs::hipMalloc, 4 * sizeof(int));
|
||||
params.dst = new_alloc.ptr();
|
||||
HIP_CHECK_ERROR(hipGraphExecMemsetNodeSetParams(graph_exec, node, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
HIP_CHECK(hipSetDevice(1));
|
||||
LinearAllocGuard<int> new_alloc(LinearAllocs::hipMalloc, 4 * sizeof(int));
|
||||
params.dst = new_alloc.ptr();
|
||||
HIP_CHECK_ERROR(hipGraphExecMemsetNodeSetParams(graph_exec, node, ¶ms),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graph_exec));
|
||||
|
||||
@@ -108,7 +108,6 @@ TEST_CASE("Unit_hipGraphExecUpdate_Negative_TypeChange") {
|
||||
dependencies.push_back(memsetNode);
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphCreate(&graph2, 0));
|
||||
HIP_CHECK(hipStreamCreate(&streamForGraph));
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpy_A, graph2, nullptr, 0, A_d, A_h, Nbytes,
|
||||
hipMemcpyHostToDevice));
|
||||
// graphExec was created before memcpyTemp was added to graph.
|
||||
@@ -488,6 +487,7 @@ TEST_CASE("Unit_hipGraphExecUpdate_Negative_Functional_CountDiffer_2") {
|
||||
#else
|
||||
REQUIRE(hipSuccess == ret);
|
||||
#endif
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec2));
|
||||
HIP_CHECK(hipGraphDestroy(graph2));
|
||||
}
|
||||
SECTION("When A node is deleted in GraphExec but not its pair from Graph") {
|
||||
@@ -506,6 +506,7 @@ TEST_CASE("Unit_hipGraphExecUpdate_Negative_Functional_CountDiffer_2") {
|
||||
#endif
|
||||
REQUIRE(NULL == hErrorNode_out);
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec3));
|
||||
HIP_CHECK(hipGraphDestroy(graph3));
|
||||
}
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
|
||||
@@ -386,6 +386,8 @@ static void checkGraphEventcontinuousKernelCall(const unsigned int kNumNode) {
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N);
|
||||
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIP_CHECK(hipEventDestroy(eventstart));
|
||||
HIP_CHECK(hipEventDestroy(eventend));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
@@ -483,6 +485,9 @@ static void checkGraphEventcontinuousKernelCallIn2Blocks(
|
||||
HipTest::checkVectorSUB(A_h, B_h, C_h, N);
|
||||
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIP_CHECK(hipEventDestroy(eventstart));
|
||||
HIP_CHECK(hipEventDestroy(eventmid));
|
||||
HIP_CHECK(hipEventDestroy(eventend));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
@@ -582,6 +587,7 @@ static void hipGraph_PerfCheck_hipGraphExecKernelNodeSetParams(
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec, stream));
|
||||
HIP_CHECK(hipStreamSynchronize(stream));
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
|
||||
// Verify graph execution result
|
||||
HipTest::checkVectorADD<int>(A_h, B_h, C_h, N);
|
||||
@@ -2519,7 +2525,7 @@ static void hipGraph_PerfCheck_hipGraphExecUpdate(const hipStream_t& stream) {
|
||||
* ------------------------
|
||||
* - Validate hipGraph performance with doorbell set.
|
||||
* - DEBUG_CLR_GRAPH_PACKET_CAPTURE
|
||||
* 1) Added 2 nodes of MemCpy & a Kernel node and copy back result using memcpy
|
||||
* 1) Added 2 nodes of MemCpy & a Kernel node and copy back result using memcpy
|
||||
and Instantiate graph & update new graph with similar node structure with
|
||||
api hipGraphExecUpdate and verify the result, the updated node should reflect.
|
||||
i) Check with Multi device case.
|
||||
@@ -2667,7 +2673,7 @@ static void hipGraph_PerfCheck_hipGraphExecUpdate_kernel_inLoop(
|
||||
* ------------------------
|
||||
* - Validate hipGraph performance with doorbell set.
|
||||
* - DEBUG_CLR_GRAPH_PACKET_CAPTURE
|
||||
* 1) Added 2 nodes of MemCpy & a Kernel node in sequence and copy back result using memcpy
|
||||
* 1) Added 2 nodes of MemCpy & a Kernel node in sequence and copy back result using memcpy
|
||||
and Instantiate graph & update new graph with similar node structure with
|
||||
api hipGraphExecUpdate and verify the result, the updated node should reflect.
|
||||
i) Check with Multi device case.
|
||||
|
||||
@@ -19,8 +19,9 @@ THE SOFTWARE.
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_checkers.hh>
|
||||
|
||||
#include <hip_test_kernels.hh>
|
||||
|
||||
|
||||
|
||||
#include "graph_dependency_common.hh"
|
||||
|
||||
@@ -307,6 +308,7 @@ TEST_CASE("Unit_hipGraphRemoveDependencies_Positive_ChangeComputeFunc") {
|
||||
REQUIRE(false == bMismatch);
|
||||
// Destroy
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
}
|
||||
|
||||
@@ -372,6 +372,7 @@ TEST_CASE("Unit_hipGraphRemoveDependencies_ChangeComputeFunc") {
|
||||
REQUIRE(false == bMismatch);
|
||||
// Destroy
|
||||
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
}
|
||||
@@ -459,4 +460,4 @@ TEST_CASE("Unit_hipGraphRemoveDependencies_Negative") {
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipEventDestroy(event_end));
|
||||
HIP_CHECK(hipEventDestroy(event_start));
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,8 @@ static void hipTestWithGraph() {
|
||||
delete[] out_h;
|
||||
HIP_CHECK(hipFree(in_d));
|
||||
HIP_CHECK(hipFree(out_d));
|
||||
HIP_CHECK(hipGraphExecDestroy(instance));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
static void hipTestWithoutGraph() {
|
||||
@@ -143,6 +145,7 @@ static void hipTestWithoutGraph() {
|
||||
delete[] out_h;
|
||||
HIP_CHECK(hipFree(in_d));
|
||||
HIP_CHECK(hipFree(out_d));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ THE SOFTWARE.
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_kernels.hh>
|
||||
|
||||
|
||||
#include "stream_capture_common.hh" // NOLINT
|
||||
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
@@ -218,7 +218,6 @@ static void interStrmEventSyncCapture(const hipStream_t& stream1, const hipStrea
|
||||
EventsGuard events_guard(1);
|
||||
hipEvent_t event = events_guard[0];
|
||||
|
||||
HIP_CHECK(hipEventCreate(&event));
|
||||
HIP_CHECK(hipStreamBeginCapture(stream1, hipStreamCaptureModeGlobal));
|
||||
HIP_CHECK(hipEventRecord(event, stream1));
|
||||
HIP_CHECK(hipStreamWaitEvent(stream2, event, 0));
|
||||
|
||||
@@ -969,7 +969,6 @@ TEST_CASE("Unit_hipStreamBeginCaptureToGraph_StateTesting") {
|
||||
HIP_CHECK(hipStreamCreate(&stream2));
|
||||
HIP_CHECK(hipEventCreate(&e));
|
||||
hipStreamCaptureStatus captureStatus = hipStreamCaptureStatusNone;
|
||||
HIP_CHECK(hipStreamCreate(&stream1));
|
||||
HIP_CHECK(hipGraphCreate(&graph, 0));
|
||||
HIP_CHECK(hipStreamIsCapturing(stream1, &captureStatus));
|
||||
REQUIRE(captureStatus == hipStreamCaptureStatusNone);
|
||||
|
||||
@@ -149,6 +149,7 @@ void validateStreamCaptureInfo(hipStream_t mstream) {
|
||||
|
||||
HIP_CHECK(hipStreamSynchronize(streamForLaunch));
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForLaunch));
|
||||
HIP_CHECK(hipStreamDestroy(stream1));
|
||||
@@ -610,6 +611,7 @@ TEST_CASE("Unit_hipStreamGetCaptureInfo_Nullstream_CaptureInfo") {
|
||||
REQUIRE(C_h[i] == D_h[i]);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
@@ -618,4 +620,4 @@ TEST_CASE("Unit_hipStreamGetCaptureInfo_Nullstream_CaptureInfo") {
|
||||
free(A_h);
|
||||
free(C_h);
|
||||
free(D_h);
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,7 @@ void validateStreamCaptureInfoV2(hipStream_t mstream) {
|
||||
|
||||
HIP_CHECK(hipStreamSynchronize(streamForLaunch));
|
||||
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(streamForLaunch));
|
||||
HIP_CHECK(hipStreamDestroy(stream1));
|
||||
@@ -277,4 +278,4 @@ TEST_CASE("Unit_hipStreamGetCaptureInfo_v2_ParamValidation") {
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
}
|
||||
}
|
||||
@@ -425,6 +425,7 @@ TEST_CASE("Unit_hipStreamIsCapturing_ChkNullStrmStatus") {
|
||||
D_h[i] = A_h[i] * A_h[i];
|
||||
REQUIRE(C_h[i] == D_h[i]);
|
||||
}
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec));
|
||||
HIP_CHECK(hipGraphDestroy(graph));
|
||||
HIP_CHECK(hipStreamDestroy(stream));
|
||||
HIP_CHECK(hipStreamDestroy(streamForGraph));
|
||||
@@ -433,4 +434,4 @@ TEST_CASE("Unit_hipStreamIsCapturing_ChkNullStrmStatus") {
|
||||
free(A_h);
|
||||
free(C_h);
|
||||
free(D_h);
|
||||
}
|
||||
}
|
||||
새 이슈에서 참조
사용자 차단