diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux index ecf54c652a..4710326f76 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_linux +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_linux @@ -875,6 +875,8 @@ "Unit_Device_remquo_Accuracy_Positive - double", "Unit_Device_modf_Accuracy_Positive - float", "Unit_Device_modf_Accuracy_Positive - double", + "=== SWDEV-450255 & SWDEV-449527 ===", + "Unit_RTC_LinkAddFile_Negative", "=== Below tests cause timeout in stress test of 09/02/24 ===", "Unit_Device___half2half2_Accuracy_Positive", "Unit_Device_make_half2_Accuracy_Positive", diff --git a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows index ba3447dc60..a10edd2be8 100644 --- a/projects/hip-tests/catch/hipTestMain/config/config_amd_windows +++ b/projects/hip-tests/catch/hipTestMain/config/config_amd_windows @@ -1430,6 +1430,8 @@ "Unit_atomicCAS_system_Positive_Host_And_Peer_GPUs - int", "Unit_atomicCAS_system_Positive_Host_And_Peer_GPUs - unsigned int", "Unit_atomicCAS_system_Positive_Host_And_Peer_GPUs - unsigned long long", + "=== SWDEV-450255 & SWDEV-449527 ===", + "Unit_RTC_LinkAddFile_Negative", "=== SWDEV-453453 : Below tests failed in stress test on 22/03/24 ===", "Unit_hipDeviceGetGraphMemAttribute_Functional", "Unit_hipDeviceGetGraphMemAttribute_Functional_Multi_Device", diff --git a/projects/hip-tests/catch/unit/rtc/linker.cc b/projects/hip-tests/catch/unit/rtc/linker.cc index cd3af5089d..3ecc376500 100644 --- a/projects/hip-tests/catch/unit/rtc/linker.cc +++ b/projects/hip-tests/catch/unit/rtc/linker.cc @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,6 +7,7 @@ #include #include +#include #include #include #include @@ -47,12 +49,12 @@ TEST_CASE("Unit_RTC_LinkerAPI_Negative") { } } -TEST_CASE("Unit_RTC_LinkerAPI") { +std::vector createBitcodeFromSource(const char* src, const char* name, int num_options, + const char** options) { hiprtcProgram program; - HIPRTC_CHECK(hiprtcCreateProgram(&program, src, "saxpy", 0, nullptr, nullptr)); + HIPRTC_CHECK(hiprtcCreateProgram(&program, src, name, 0, nullptr, nullptr)); - const char* options[]{"-fgpu-rdc"}; - HIPRTC_CHECK(hiprtcCompileProgram(program, 1, options)); + HIPRTC_CHECK(hiprtcCompileProgram(program, num_options, options)); size_t codesize = 0; HIPRTC_CHECK(hiprtcGetBitcodeSize(program, &codesize)); @@ -62,6 +64,13 @@ TEST_CASE("Unit_RTC_LinkerAPI") { HIPRTC_CHECK(hiprtcDestroyProgram(&program)); + return code; +} + +TEST_CASE("Unit_RTC_LinkerAPI") { + const char* options[]{"-fgpu-rdc"}; + std::vector code = createBitcodeFromSource(src, "saxpy", 1, options); + const char* isaopts[] = {"-mllvm", "-inline-threshold=1", "-mllvm", "-inlinehint-threshold=1"}; std::vector jit_options = {HIPRTC_JIT_IR_TO_ISA_OPT_EXT, HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT}; @@ -128,3 +137,64 @@ TEST_CASE("Unit_RTC_LinkerAPI") { REQUIRE(fabs(a * hX[i] + hY[i] - hOut[i]) <= fabs(hOut[i]) * 1e-6); } } + +TEST_CASE("Unit_RTC_LinkAddFile_Negative") { + static constexpr hiprtcJITInputType input_type = HIPRTC_JIT_INPUT_LLVM_BITCODE; + static constexpr const char* file_name = "bitcode_file"; + + SECTION("link add file - incorrect hiprtcLinkState") { + hiprtcLinkState linkstate; + REQUIRE(hiprtcLinkAddFile(linkstate, input_type, file_name, 0, nullptr, nullptr) == + HIPRTC_ERROR_PROGRAM_CREATION_FAILURE); + } + + SECTION("link add file - nullptr hiprtcLinkState") { + REQUIRE(hiprtcLinkAddFile(nullptr, input_type, file_name, 0, nullptr, nullptr) == + HIPRTC_ERROR_INVALID_INPUT); + } + + SECTION("link add file - incorrect input type") { + hiprtcLinkState linkstate{}; + HIPRTC_CHECK(hiprtcLinkCreate(0, nullptr, nullptr, &linkstate)); + hiprtcJITInputType incorrect_input_type = HIPRTC_JIT_INPUT_NVVM; + REQUIRE(hiprtcLinkAddFile(linkstate, incorrect_input_type, file_name, 0, nullptr, nullptr) == + HIPRTC_ERROR_INVALID_INPUT); + HIPRTC_CHECK(hiprtcLinkDestroy(linkstate)); + } + + SECTION("link add file - file does not exists") { + hiprtcLinkState linkstate{}; + HIPRTC_CHECK(hiprtcLinkCreate(0, nullptr, nullptr, &linkstate)); + REQUIRE(hiprtcLinkAddFile(linkstate, input_type, file_name, 0, nullptr, nullptr) == + HIPRTC_ERROR_PROGRAM_CREATION_FAILURE); + HIPRTC_CHECK(hiprtcLinkDestroy(linkstate)); + } +} + +TEST_CASE("Unit_RTC_LinkAddFile_Default") { + // Create bitcode and save it to file + const char* options[]{"-fgpu-rdc"}; + std::vector code = createBitcodeFromSource(src, "saxpy", 1, options); + static constexpr const char* file_name = "bitcode_file"; + std::ofstream file(file_name, std::ios::binary); + REQUIRE(file.is_open()); + file.write(code.data(), code.size()); + file.close(); + + // Create link with options + const char* isaopts[] = {"-mllvm", "-inline-threshold=1", "-mllvm", "-inlinehint-threshold=1"}; + std::vector jit_options = {HIPRTC_JIT_IR_TO_ISA_OPT_EXT, + HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT}; + size_t isaoptssize = 4; + const void* lopts[] = {(void*)isaopts, (void*)(isaoptssize)}; + hiprtcLinkState linkstate; + HIPRTC_CHECK(hiprtcLinkCreate(jit_options.size(), jit_options.data(), (void**)lopts, &linkstate)); + REQUIRE(hiprtcLinkAddFile(linkstate, HIPRTC_JIT_INPUT_LLVM_BITCODE, file_name, 0, nullptr, nullptr) == + HIPRTC_SUCCESS); + + // Cleanup + HIPRTC_CHECK(hiprtcLinkDestroy(linkstate)); + if (fs::exists(file_name)) { + REQUIRE(fs::remove(file_name)); + } +}