SWDEV-441602 - Add tests for hiprtcLinkAddFile

Signed-off-by: Sebastian Luzynski <Sebastian.Luzynski@amd.com>
Change-Id: Iae148c3c908e18247624937512908dbb3cbc460c


[ROCm/hip-tests commit: 586f8ad143]
Dieser Commit ist enthalten in:
Sebastian Luzynski
2024-02-21 14:59:00 +00:00
Ursprung e61e3918dc
Commit 53fa7d6d30
3 geänderte Dateien mit 78 neuen und 4 gelöschten Zeilen
@@ -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",
@@ -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",
+74 -4
Datei anzeigen
@@ -1,4 +1,5 @@
#include <hip_test_common.hh>
#include <hip_test_filesystem.hh>
#include <hip/hiprtc.h>
#include <hip/hip_runtime.h>
@@ -6,6 +7,7 @@
#include <cassert>
#include <cstddef>
#include <fstream>
#include <memory>
#include <iostream>
#include <iterator>
@@ -47,12 +49,12 @@ TEST_CASE("Unit_RTC_LinkerAPI_Negative") {
}
}
TEST_CASE("Unit_RTC_LinkerAPI") {
std::vector<char> 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<char> code = createBitcodeFromSource(src, "saxpy", 1, options);
const char* isaopts[] = {"-mllvm", "-inline-threshold=1", "-mllvm", "-inlinehint-threshold=1"};
std::vector<hiprtcJIT_option> 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<char> 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<hiprtcJIT_option> 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));
}
}