diff --git a/projects/hip-tests/catch/external/Catch2/cmake/Catch2/Catch.cmake b/projects/hip-tests/catch/external/Catch2/cmake/Catch2/Catch.cmake index 603dc1b994..868ccfa739 100644 --- a/projects/hip-tests/catch/external/Catch2/cmake/Catch2/Catch.cmake +++ b/projects/hip-tests/catch/external/Catch2/cmake/Catch2/Catch.cmake @@ -204,9 +204,9 @@ function(hip_add_exe_to_target) ) # Create shared lib of all tests if(NOT RTC_TESTING) - add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $ $) + add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $ $) else () - add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $) + add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $) if(HIP_PLATFORM STREQUAL "amd") target_link_libraries(${_NAME} hiprtc) else() diff --git a/projects/hip-tests/catch/hipTestMain/hip_test_context.cc b/projects/hip-tests/catch/hipTestMain/hip_test_context.cc index 597813b4c8..ae496d372b 100644 --- a/projects/hip-tests/catch/hipTestMain/hip_test_context.cc +++ b/projects/hip-tests/catch/hipTestMain/hip_test_context.cc @@ -1,3 +1,4 @@ +#include #include #include #include @@ -211,7 +212,10 @@ bool TestContext::parseJsonFile() { void TestContext::cleanContext() { for (auto& pair : compiledKernels) { - REQUIRE(hipSuccess == hipModuleUnload(pair.second.module)); + hipError_t error = hipModuleUnload(pair.second.module); + if (error != hipSuccess) { + throw std::runtime_error("Unable to unload rtc module"); + } } } diff --git a/projects/hip-tests/catch/hipTestMain/main.cc b/projects/hip-tests/catch/hipTestMain/main.cc index 886aa7a8dc..ea3bb9bd23 100644 --- a/projects/hip-tests/catch/hipTestMain/main.cc +++ b/projects/hip-tests/catch/hipTestMain/main.cc @@ -9,5 +9,8 @@ int main(int argc, char** argv) { std::cout << "HIP_SKIP_THIS_TEST" << std::endl; return 0; } - return Catch::Session().run(argc, argv); + int out = Catch::Session().run(argc, argv); + TestContext::get().cleanContext(); + return out; + } diff --git a/projects/hip-tests/catch/include/hip_test_rtc.hh b/projects/hip-tests/catch/include/hip_test_rtc.hh index 0860ae51db..0f862840bb 100644 --- a/projects/hip-tests/catch/include/hip_test_rtc.hh +++ b/projects/hip-tests/catch/include/hip_test_rtc.hh @@ -31,6 +31,7 @@ THE SOFTWARE. #include #include #include +#include #include "hip/hip_runtime_api.h" #include "hip_test_context.hh" @@ -218,7 +219,6 @@ static inline void printInfo() { template void launchRTCKernel(std::string (*getKernelName)(), dim3 numBlocks, dim3 numThreads, std::uint32_t memPerBlock, hipStream_t stream, Args&&... packedArgs) { - printInfo(); TestContext& testContext = TestContext::get(); std::string kernelName = (*getKernelName)(); @@ -226,25 +226,29 @@ void launchRTCKernel(std::string (*getKernelName)(), dim3 numBlocks, dim3 numThr std::vector kernelTypenames{std::string(HipTest::getTypeName())...}; std::string kernelExpression = reconstructExpression(kernelName, kernelTypenames); - if (testContext.getFunction(kernelExpression) == nullptr) { - hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)}; - std::vector compiledCode{getKernelCode(rtcProgram)}; + static std::mutex mutex{}; + { + std::lock_guard lockGuard(mutex); + if (testContext.getFunction(kernelExpression) == nullptr) { + hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)}; + std::vector compiledCode{getKernelCode(rtcProgram)}; - hipModule_t module; + hipModule_t module; - REQUIRE(hipSuccess == hipModuleLoadData(&module, compiledCode.data())); + REQUIRE(hipSuccess == hipModuleLoadData(&module, compiledCode.data())); hipFunction_t kernelFunction; - const char* loweredName; - REQUIRE(HIPRTC_SUCCESS == - hiprtcGetLoweredName(rtcProgram, kernelExpression.c_str(), &loweredName)); - REQUIRE(hipSuccess == hipModuleGetFunction(&kernelFunction, module, loweredName)); + const char* loweredName; + REQUIRE(HIPRTC_SUCCESS == + hiprtcGetLoweredName(rtcProgram, kernelExpression.c_str(), &loweredName)); + REQUIRE(hipSuccess == hipModuleGetFunction(&kernelFunction, module, loweredName)); - /* After obtaining the kernelFunction, the program is no longer needed. So it can be destroyed */ - REQUIRE(HIPRTC_SUCCESS == hiprtcDestroyProgram(&rtcProgram)); + /* After obtaining the kernelFunction, the program is no longer needed. So it can be destroyed */ + REQUIRE(HIPRTC_SUCCESS == hiprtcDestroyProgram(&rtcProgram)); - testContext.trackRtcState(kernelExpression, module, kernelFunction); + testContext.trackRtcState(kernelExpression, module, kernelFunction); + } } hipFunction_t kernelFunction = testContext.getFunction(kernelExpression); diff --git a/projects/hip-tests/catch/unit/event/Unit_hipEventRecord.cc b/projects/hip-tests/catch/unit/event/Unit_hipEventRecord.cc index d2f13d6e12..408f802d41 100644 --- a/projects/hip-tests/catch/unit/event/Unit_hipEventRecord.cc +++ b/projects/hip-tests/catch/unit/event/Unit_hipEventRecord.cc @@ -87,5 +87,4 @@ static_cast(A_d), static_cast(B_d), C_d, N); HIP_CHECK(hipEventDestroy(stop)); HipTest::checkVectorADD(A_h, B_h, C_h, N, true); - TestContext::get().cleanContext(); } diff --git a/projects/hip-tests/catch/unit/memory/hipHostMalloc.cc b/projects/hip-tests/catch/unit/memory/hipHostMalloc.cc index 39a2bb6719..f0b1fafe8d 100644 --- a/projects/hip-tests/catch/unit/memory/hipHostMalloc.cc +++ b/projects/hip-tests/catch/unit/memory/hipHostMalloc.cc @@ -144,7 +144,6 @@ TEST_CASE("Unit_hipHostMalloc_Basic") { HIP_CHECK(hipHostFree(A_h)); HIP_CHECK(hipHostFree(B_h)); HIP_CHECK(hipHostFree(C_h)); - TestContext::get().cleanContext(); } } /* @@ -182,7 +181,6 @@ TEST_CASE("Unit_hipHostMalloc_NonCoherent") { SYNC_STREAM, ptrType); CheckHostPointer(numElements, A, hipEventReleaseToSystem, SYNC_EVENT, ptrType); - TestContext::get().cleanContext(); } /*