From fde891bc76d1b19c5f41e4d77fa1275cbf45e2b4 Mon Sep 17 00:00:00 2001 From: "Dittakavi, Satyanvesh" Date: Mon, 18 Aug 2025 17:27:47 +0530 Subject: [PATCH] SWDEV-514959 - Fix memory leaks in streamperthread tests (#14) Change-Id: I7b133d422f675d45050d7f724d632fa2dc997baf --- catch/unit/streamperthread/hipStreamPerThread_Basic.cc | 8 ++++++-- .../streamperthread/hipStreamPerThread_DeviceReset.cc | 5 ++++- .../streamperthread/hipStreamPerThread_MultiThread.cc | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/catch/unit/streamperthread/hipStreamPerThread_Basic.cc b/catch/unit/streamperthread/hipStreamPerThread_Basic.cc index 51437b453f..0d2ccc961c 100644 --- a/catch/unit/streamperthread/hipStreamPerThread_Basic.cc +++ b/catch/unit/streamperthread/hipStreamPerThread_Basic.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2025 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 @@ -135,4 +135,8 @@ TEST_CASE("Unit_hipStreamPerThread_MemcpyAsync") { for (unsigned int i = 0; i < ele_size; ++i) { REQUIRE(A_h[i] == 123); } -} \ No newline at end of file + + // Clean-up + HIP_CHECK(hipHostFree(A_h)); + HIP_CHECK(hipFree(A_d)); +} diff --git a/catch/unit/streamperthread/hipStreamPerThread_DeviceReset.cc b/catch/unit/streamperthread/hipStreamPerThread_DeviceReset.cc index 9eea33da6d..ca11e50d68 100644 --- a/catch/unit/streamperthread/hipStreamPerThread_DeviceReset.cc +++ b/catch/unit/streamperthread/hipStreamPerThread_DeviceReset.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2025 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 @@ -88,6 +88,9 @@ TEST_CASE("Unit_hipStreamPerThread_DeviceReset_2") { if (status != hipSuccess) return; HIP_CHECK(hipStreamSynchronize(hipStreamPerThread)); + // Host Memory is not destroyed with hipDeviceReset, need to free it + // explicitly to avoid memory leaks + HIP_CHECK(hipHostFree(A_h)); HIP_CHECK(hipDeviceReset()); // After reset all memory objects will be destroyed hence allocating them again diff --git a/catch/unit/streamperthread/hipStreamPerThread_MultiThread.cc b/catch/unit/streamperthread/hipStreamPerThread_MultiThread.cc index ec34c6de77..914cf6acda 100644 --- a/catch/unit/streamperthread/hipStreamPerThread_MultiThread.cc +++ b/catch/unit/streamperthread/hipStreamPerThread_MultiThread.cc @@ -1,5 +1,5 @@ /* -Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2025 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 @@ -34,6 +34,9 @@ static void Copy_to_device() { } HIP_CHECK(hipMemcpyAsync(A_d, A_h, ele_size * sizeof(int), hipMemcpyHostToDevice, hipStreamPerThread)); + // Clean up + HIP_CHECK(hipHostFree(A_h)); + HIP_CHECK(hipFree(A_d)); } /*