-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EXSWHTEC-109 - Implement tests for the hipModuleLoad family of APIs and hipModuleUnload #20
Changes from 11 commits
cea96af
909e7e4
094b9af
9daa6d0
c49043e
7a213be
580df9d
f40fe6a
afa2e93
500b7b8
05e34d3
8686418
8390c65
27ca3e2
77b2d58
015d7e4
b261ecf
afdf15b
2fbb319
e1f2434
a2c575b
73eedc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
set(TEST_SRC | ||
hip_module_common.cc | ||
hipModuleLoad.cc | ||
hipModuleLoadData.cc | ||
hipModuleLoadDataEx.cc | ||
hipModuleUnload.cc | ||
) | ||
|
||
configure_file(not_a_module.txt not_a_module.txt) | ||
|
||
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/empty_module.code | ||
COMMAND ${CMAKE_CXX_COMPILER} --genco --std=c++17 ${CMAKE_CURRENT_SOURCE_DIR}/empty_module.cc -o empty_module.code | ||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/empty_module.cc) | ||
add_custom_target(empty_module ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/empty_module.code) | ||
|
||
if(HIP_PLATFORM MATCHES "amd") | ||
set(RTCLIB "hiprtc") | ||
else() | ||
set(RTCLIB "nvrtc") | ||
endif() | ||
hip_add_exe_to_target(NAME ModuleTest | ||
TEST_SRC ${TEST_SRC} | ||
TEST_TARGET_NAME build_tests | ||
LINKER_LIBS ${RTCLIB}) | ||
add_dependencies(ModuleTest empty_module) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include <hip_test_common.hh> | ||
#include <hip/hip_runtime_api.h> | ||
|
||
TEST_CASE("Unit_hipModuleLoad_Positive_Basic") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module = nullptr; | ||
HIP_CHECK(hipModuleLoad(&module, "empty_module.code")); | ||
REQUIRE(module != nullptr); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
} | ||
|
||
TEST_CASE("Unit_hipModuleLoad_Negative_Parameters") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module; | ||
|
||
SECTION("module == nullptr") { | ||
HIP_CHECK_ERROR(hipModuleLoad(nullptr, "empty_module.code"), hipErrorInvalidValue); | ||
} | ||
|
||
SECTION("fname == nullptr") { | ||
HIP_CHECK_ERROR(hipModuleLoad(&module, nullptr), hipErrorInvalidValue); | ||
} | ||
|
||
SECTION("fname == empty string") { | ||
HIP_CHECK_ERROR(hipModuleLoad(&module, ""), hipErrorInvalidValue); | ||
} | ||
|
||
SECTION("fname == non existent file") { | ||
HIP_CHECK_ERROR(hipModuleLoad(&module, "non existent file"), hipErrorFileNotFound); | ||
} | ||
|
||
// Disabled for AMD due to defect - EXSWHTEC-151 | ||
#if HT_NVIDIA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a new TEST_CAST for this and disable it via json. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requested change has been implemented. |
||
SECTION("Load from a file that is not a module") { | ||
HIP_CHECK_ERROR(hipModuleLoad(&module, "not_a_module.txt"), hipErrorInvalidImage); | ||
} | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include "hip_module_common.hh" | ||
|
||
#include <hip_test_common.hh> | ||
#include <hip/hip_runtime_api.h> | ||
|
||
|
||
TEST_CASE("Unit_hipModuleLoadData_Positive_Basic") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module = nullptr; | ||
|
||
SECTION("Load compiled module from file") { | ||
const auto loaded_module = LoadModuleIntoBuffer("empty_module.code"); | ||
HIP_CHECK(hipModuleLoadData(&module, loaded_module.data())); | ||
REQUIRE(module != nullptr); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
} | ||
|
||
SECTION("Load RTCd module") { | ||
const auto rtc = CreateRTCCharArray(R"(extern "C" __global__ void kernel() {})"); | ||
HIP_CHECK(hipModuleLoadData(&module, rtc.data())); | ||
REQUIRE(module != nullptr); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
} | ||
} | ||
|
||
TEST_CASE("Unit_hipModuleLoadData_Negative_Parameters") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module; | ||
|
||
SECTION("module == nullptr") { | ||
const auto loaded_module = LoadModuleIntoBuffer("empty_module.code"); | ||
HIP_CHECK_ERROR(hipModuleLoadData(nullptr, loaded_module.data()), hipErrorInvalidValue); | ||
LoadModuleIntoBuffer("empty_module.code"); | ||
} | ||
|
||
SECTION("image == nullptr") { | ||
HIP_CHECK_ERROR(hipModuleLoadData(&module, nullptr), hipErrorInvalidValue); | ||
} | ||
|
||
// Disabled for AMD due to defect - EXSWHTEC-153 | ||
#if HT_NVIDIA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requested change has been implemented. |
||
SECTION("image == empty string") { | ||
HIP_CHECK_ERROR(hipModuleLoadData(&module, ""), hipErrorInvalidImage); | ||
} | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include "hip_module_common.hh" | ||
|
||
#include <hip_test_common.hh> | ||
#include <hip/hip_runtime_api.h> | ||
|
||
|
||
TEST_CASE("Unit_hipModuleLoadDataEx_Positive_Basic") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module = nullptr; | ||
|
||
SECTION("Load compiled module from file") { | ||
const auto loaded_module = LoadModuleIntoBuffer("empty_module.code"); | ||
HIP_CHECK(hipModuleLoadDataEx(&module, loaded_module.data(), 0, nullptr, nullptr)); | ||
REQUIRE(module != nullptr); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
} | ||
|
||
SECTION("Load RTCd module") { | ||
const auto rtc = CreateRTCCharArray(R"(extern "C" __global__ void kernel() {})"); | ||
HIP_CHECK(hipModuleLoadDataEx(&module, rtc.data(), 0, nullptr, nullptr)); | ||
REQUIRE(module != nullptr); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
} | ||
} | ||
|
||
TEST_CASE("Unit_hipModuleLoadDataEx_Negative_Parameters") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
hipModule_t module = nullptr; | ||
|
||
SECTION("module == nullptr") { | ||
const auto loaded_module = LoadModuleIntoBuffer("empty_module.code"); | ||
HIP_CHECK_ERROR(hipModuleLoadDataEx(nullptr, loaded_module.data(), 0, nullptr, nullptr), | ||
hipErrorInvalidValue); | ||
LoadModuleIntoBuffer("empty_module.code"); | ||
} | ||
|
||
SECTION("image == nullptr") { | ||
HIP_CHECK_ERROR(hipModuleLoadDataEx(&module, nullptr, 0, nullptr, nullptr), | ||
hipErrorInvalidValue); | ||
} | ||
|
||
// Disabled for AMD due to defect - EXSWHTEC-153 | ||
#if HT_NVIDIA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requested change has been implemented. |
||
SECTION("image == empty string") { | ||
HIP_CHECK_ERROR(hipModuleLoadDataEx(&module, "", 0, nullptr, nullptr), hipErrorInvalidImage); | ||
} | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include <hip_test_common.hh> | ||
#include <hip/hip_runtime_api.h> | ||
|
||
TEST_CASE("Unit_hipModuleUnload_Negative_Parameters") { | ||
HIP_CHECK(hipFree(nullptr)); | ||
|
||
// Disabled for AMD due to defect - EXSWHTEC-152 | ||
#if HT_NVIDIA | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requested change has been implemented. |
||
SECTION("module == nullptr") { | ||
HIP_CHECK_ERROR(hipModuleUnload(nullptr), hipErrorInvalidResourceHandle); | ||
} | ||
#endif | ||
|
||
// Causes CUDA to segfault | ||
#if HT_AMD | ||
SECTION("Double unload") { | ||
hipModule_t module = nullptr; | ||
HIP_CHECK(hipModuleLoad(&module, "empty_module.code")); | ||
HIP_CHECK(hipModuleUnload(module)); | ||
HIP_CHECK_ERROR(hipModuleUnload(module), hipErrorNotFound); | ||
} | ||
#endif | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include "hip_module_common.hh" | ||
|
||
#include <experimental/filesystem> | ||
#include <fstream> | ||
|
||
#include <hip_test_common.hh> | ||
#include <hip/hiprtc.h> | ||
|
||
ModuleGuard ModuleGuard::LoadModule(const char* fname) { | ||
hipModule_t module = nullptr; | ||
HIP_CHECK(hipModuleLoad(&module, fname)); | ||
return ModuleGuard{module}; | ||
} | ||
|
||
ModuleGuard ModuleGuard::LoadModuleDataFile(const char* fname) { | ||
const auto loaded_module = LoadModuleIntoBuffer(fname); | ||
hipModule_t module = nullptr; | ||
HIP_CHECK(hipModuleLoadData(&module, loaded_module.data())); | ||
return ModuleGuard{module}; | ||
} | ||
|
||
ModuleGuard ModuleGuard::LoadModuleDataRTC(const char* code) { | ||
const auto rtc = CreateRTCCharArray(code); | ||
hipModule_t module = nullptr; | ||
HIP_CHECK(hipModuleLoadData(&module, rtc.data())); | ||
return ModuleGuard{module}; | ||
} | ||
|
||
// Load module into buffer instead of mapping file to avoid platform specific mechanisms | ||
std::vector<char> LoadModuleIntoBuffer(const char* path_string) { | ||
std::experimental::filesystem::path p(path_string); | ||
const auto file_size = std::experimental::filesystem::file_size(p); | ||
std::ifstream f(p, std::ios::binary | std::ios::in); | ||
REQUIRE(f); | ||
std::vector<char> empty_module(file_size); | ||
REQUIRE(f.read(empty_module.data(), file_size)); | ||
return empty_module; | ||
} | ||
|
||
std::vector<char> CreateRTCCharArray(const char* src) { | ||
hiprtcProgram prog; | ||
HIPRTC_CHECK(hiprtcCreateProgram(&prog, src, "prog", 0, nullptr, nullptr)); | ||
HIPRTC_CHECK(hiprtcCompileProgram(prog, 0, nullptr)); | ||
size_t code_size = 0; | ||
HIPRTC_CHECK(hiprtcGetCodeSize(prog, &code_size)); | ||
std::vector<char> code(code_size, '\0'); | ||
HIPRTC_CHECK(hiprtcGetCode(prog, code.data())); | ||
HIPRTC_CHECK(hiprtcDestroyProgram(&prog)); | ||
return code; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
genco does not work properly on windows yet. you will need to exclude this test building on windows. additionally you are missing specifying the offload arch & output path for building the code object. see unit/deviceLib/CMakeLists.txt for an example of how to do it for all of the above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested changes have been implemented, please proceed.