EXSWCPHIPT-42: Changes to HIP RTC Framework implementation (#2732)
- Removed ifdef from hipTestContext class
- Fix potential race condition in hipTest::launchRTCKernel()
- Improve documentation
- Move moduleUnloading to main() instead of explicitly calling it on every test
- Fix code formating
- Fix segmentation fault caused by using catch2 macro after catch2 is destroyed
[ROCm/hip-tests commit: a0296bd614]
이 커밋은 다음에 포함됨:
@@ -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} $<TARGET_OBJECTS:Main_Object> $<TARGET_OBJECTS:KERNELS>)
|
||||
add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $<TARGET_OBJECTS:Main_Object> $<TARGET_OBJECTS:KERNELS>)
|
||||
else ()
|
||||
add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $<TARGET_OBJECTS:Main_Object>)
|
||||
add_executable(${_NAME} EXCLUDE_FROM_ALL ${_TEST_SRC} $<TARGET_OBJECTS:Main_Object>)
|
||||
if(HIP_PLATFORM STREQUAL "amd")
|
||||
target_link_libraries(${_NAME} hiprtc)
|
||||
else()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <cstdlib>
|
||||
#include <hip_test_common.hh>
|
||||
#include <picojson.h>
|
||||
#include <fstream>
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ THE SOFTWARE.
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include "hip_test_context.hh"
|
||||
|
||||
@@ -218,7 +219,6 @@ static inline void printInfo() {
|
||||
template <typename... Typenames, typename... Args>
|
||||
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<std::string> kernelTypenames{std::string(HipTest::getTypeName<Typenames>())...};
|
||||
std::string kernelExpression = reconstructExpression(kernelName, kernelTypenames);
|
||||
|
||||
if (testContext.getFunction(kernelExpression) == nullptr) {
|
||||
hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)};
|
||||
std::vector<char> compiledCode{getKernelCode(rtcProgram)};
|
||||
static std::mutex mutex{};
|
||||
{
|
||||
std::lock_guard<std::mutex> lockGuard(mutex);
|
||||
if (testContext.getFunction(kernelExpression) == nullptr) {
|
||||
hiprtcProgram rtcProgram{compileRTC(kernelName, kernelExpression)};
|
||||
std::vector<char> 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);
|
||||
|
||||
@@ -87,5 +87,4 @@ static_cast<const float*>(A_d), static_cast<const float*>(B_d), C_d, N);
|
||||
HIP_CHECK(hipEventDestroy(stop));
|
||||
|
||||
HipTest::checkVectorADD(A_h, B_h, C_h, N, true);
|
||||
TestContext::get().cleanContext();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
새 이슈에서 참조
사용자 차단