diff --git a/catch/unit/module/CMakeLists.txt b/catch/unit/module/CMakeLists.txt index 3f891d974..a1fe3d253 100644 --- a/catch/unit/module/CMakeLists.txt +++ b/catch/unit/module/CMakeLists.txt @@ -85,8 +85,13 @@ if(HIP_PLATFORM MATCHES "amd") set(TEST_SRC ${TEST_SRC} hipExtModuleLaunchKernel.cc - hipHccModuleLaunchKernel.cc - hipGetProcAddressModuleApis.cc) + hipHccModuleLaunchKernel.cc) + +if(BUILD_SHARED_LIBS) + set(TEST_SRC + ${TEST_SRC} + hipGetProcAddressModuleApis.cc) +endif() add_custom_target(empty_module.code COMMAND ${CMAKE_CXX_COMPILER} --genco ${OFFLOAD_ARCH_STR} diff --git a/catch/unit/module/hipExtModuleLaunchKernel.cc b/catch/unit/module/hipExtModuleLaunchKernel.cc index 4faf712d9..c04d641d6 100644 --- a/catch/unit/module/hipExtModuleLaunchKernel.cc +++ b/catch/unit/module/hipExtModuleLaunchKernel.cc @@ -261,13 +261,12 @@ TEST_CASE("Unit_hipExtModuleLaunchKernel_UniformWorkGroup") { TEST_CASE("Unit_hipExtModuleLaunchKernel_Positive_Parameters") { ModuleLaunchKernelPositiveParameters(); - + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); SECTION("Pass only start event") { hipEvent_t start_event = nullptr; HIP_CHECK(hipEventCreate(&start_event)); const auto kernel = GetKernel(mg.module(), "NOPKernel"); - HIP_CHECK(hipExtModuleLaunchKernel(kernel, 1, 1, 1, 1, 1, 1, 0, nullptr, - nullptr, nullptr, + HIP_CHECK(hipExtModuleLaunchKernel(kernel, 1, 1, 1, 1, 1, 1, 0, nullptr, nullptr, nullptr, start_event, nullptr)); HIP_CHECK(hipDeviceSynchronize()); HIP_CHECK(hipEventQuery(start_event)); diff --git a/catch/unit/module/hipModuleLaunchCooperativeKernel.cc b/catch/unit/module/hipModuleLaunchCooperativeKernel.cc index 92924d88a..dd66b04af 100644 --- a/catch/unit/module/hipModuleLaunchCooperativeKernel.cc +++ b/catch/unit/module/hipModuleLaunchCooperativeKernel.cc @@ -50,6 +50,7 @@ THE SOFTWARE. * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernel_Positive_Basic") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; @@ -89,6 +90,7 @@ TEST_CASE("Unit_hipModuleLaunchCooperativeKernel_Positive_Basic") { * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernel_Positive_Parameters") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; @@ -124,6 +126,7 @@ TEST_CASE("Unit_hipModuleLaunchCooperativeKernel_Positive_Parameters") { * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernel_Negative_Parameters") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; diff --git a/catch/unit/module/hipModuleLaunchCooperativeKernelMultiDevice.cc b/catch/unit/module/hipModuleLaunchCooperativeKernelMultiDevice.cc index e9f2389ce..d9740b13c 100644 --- a/catch/unit/module/hipModuleLaunchCooperativeKernelMultiDevice.cc +++ b/catch/unit/module/hipModuleLaunchCooperativeKernelMultiDevice.cc @@ -49,6 +49,7 @@ THE SOFTWARE. * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernelMultiDevice_Positive_Basic") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; @@ -106,6 +107,7 @@ TEST_CASE("Unit_hipModuleLaunchCooperativeKernelMultiDevice_Positive_Basic") { * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernelMultiDevice_Negative_Parameters") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; @@ -229,6 +231,7 @@ TEST_CASE("Unit_hipModuleLaunchCooperativeKernelMultiDevice_Negative_Parameters" * - HIP_VERSION >= 5.5 */ TEST_CASE("Unit_hipModuleLaunchCooperativeKernelMultiDevice_Negative_MultiKernelSameDevice") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); if (!DeviceAttributesSupport(0, hipDeviceAttributeCooperativeLaunch)) { HipTest::HIP_SKIP_TEST("CooperativeLaunch not supported"); return; diff --git a/catch/unit/module/hip_module_common.cc b/catch/unit/module/hip_module_common.cc index 2cdb250b3..fbd3e486e 100644 --- a/catch/unit/module/hip_module_common.cc +++ b/catch/unit/module/hip_module_common.cc @@ -33,6 +33,11 @@ ModuleGuard ModuleGuard::LoadModule(const char* fname) { return ModuleGuard{module}; } +ModuleGuard ModuleGuard::InitModule(const char* fname) { + HIP_CHECK(hipFree(nullptr)); + return LoadModule(fname); +} + ModuleGuard ModuleGuard::LoadModuleDataFile(const char* fname) { const auto loaded_module = LoadModuleIntoBuffer(fname); hipModule_t module = nullptr; diff --git a/catch/unit/module/hip_module_common.hh b/catch/unit/module/hip_module_common.hh index 41b153b3a..165edd272 100644 --- a/catch/unit/module/hip_module_common.hh +++ b/catch/unit/module/hip_module_common.hh @@ -34,6 +34,8 @@ class ModuleGuard { static ModuleGuard LoadModule(const char* fname); + static ModuleGuard InitModule(const char* fname); + static ModuleGuard LoadModuleDataFile(const char* fname); static ModuleGuard LoadModuleDataRTC(const char* code); diff --git a/catch/unit/module/hip_module_launch_kernel_common.hh b/catch/unit/module/hip_module_launch_kernel_common.hh index b5dc9f772..c9c679b9f 100644 --- a/catch/unit/module/hip_module_launch_kernel_common.hh +++ b/catch/unit/module/hip_module_launch_kernel_common.hh @@ -27,18 +27,12 @@ THE SOFTWARE. #include #include -inline ModuleGuard InitModule() { - HIP_CHECK(hipFree(nullptr)); - return ModuleGuard::LoadModule("launch_kernel_module.code"); -} - -inline ModuleGuard mg{InitModule()}; - using ExtModuleLaunchKernelSig = hipError_t(hipFunction_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t, size_t, hipStream_t, void**, void**, hipEvent_t, hipEvent_t, uint32_t); template void ModuleLaunchKernelPositiveBasic() { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); SECTION("Kernel with no arguments") { hipFunction_t f = GetKernel(mg.module(), "NOPKernel"); HIP_CHECK(func(f, 1, 1, 1, 1, 1, 1, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0u)); @@ -81,6 +75,7 @@ template void ModuleLaunchKernelPositiveParamet const auto LaunchNOPKernel = [=](unsigned int gridDimX, unsigned int gridDimY, unsigned int gridDimZ, unsigned int blockDimX, unsigned int blockDimY, unsigned int blockDimZ) { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); hipFunction_t f = GetKernel(mg.module(), "NOPKernel"); HIP_CHECK(func(f, gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ, 0, nullptr, nullptr, nullptr, nullptr, nullptr, 0u)); @@ -120,6 +115,7 @@ template void ModuleLaunchKernelPositiveParamet template void ModuleLaunchKernelNegativeParameters( bool extLaunch = false) { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); hipFunction_t f = GetKernel(mg.module(), "NOPKernel"); hipError_t expectedErrorLaunchParam = (extLaunch == true) ? hipErrorInvalidConfiguration : hipErrorInvalidValue; @@ -213,6 +209,7 @@ template void ModuleLaunchKernelNegativeParamet } SECTION("Passing kernel_args and extra simultaneously") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); hipFunction_t f = GetKernel(mg.module(), "Kernel42"); LinearAllocGuard result_dev(LinearAllocs::hipMalloc, sizeof(int)); int* result_ptr = result_dev.ptr(); @@ -230,6 +227,7 @@ template void ModuleLaunchKernelNegativeParamet } SECTION("Invalid extra") { + auto mg = ModuleGuard::InitModule("launch_kernel_module.code"); hipFunction_t f = GetKernel(mg.module(), "Kernel42"); void* extra[0] = {}; HIP_CHECK_ERROR(func(f, 1, 1, 1, 1, 1, 1, 0, nullptr, nullptr, extra, nullptr, nullptr, 0u),