Skip to content
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

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cea96af
SWDEV-355313 - Move catch tests and samples
gargrahul Oct 26, 2022
909e7e4
SWDEV-355313 - Add README
gargrahul Nov 7, 2022
094b9af
SWDEV-355313 - Update amd-staging branch
gargrahul Nov 28, 2022
9daa6d0
SWDEV-355313 - Update README
gargrahul Dec 2, 2022
c49043e
SWDEV-355313 - Update latest code
gargrahul Dec 6, 2022
7a213be
Create common code for module tests
music-dino Dec 7, 2022
580df9d
Create common code for module tests
music-dino Dec 7, 2022
f40fe6a
Merge branch 'module_common' into hipModuleLoad_tests
music-dino Dec 7, 2022
afa2e93
EXSWHTEC-109 - Implement tests for the hipModuleLoad family of APIs a…
music-dino Dec 7, 2022
500b7b8
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 16, 2022
05e34d3
Merge branch 'develop' into hipModuleLoad_tests
mangupta Mar 3, 2023
8686418
EXSWHTEC-109 - Disable build for Windows, add offload arch and output…
music-dino Mar 6, 2023
8390c65
Merge remote-tracking branch 'upstream/develop' into hipModuleLoad_tests
music-dino Apr 18, 2023
27ca3e2
EXSWHTEC-109 - Separate out negative tests that fail on AMD and disab…
music-dino Apr 18, 2023
77b2d58
EXSWHTEC-109 - Separate out negative tests for hipModuleUnload that f…
music-dino Apr 18, 2023
015d7e4
Merge branch 'develop' into hipModuleLoad_tests
music-dino Jun 26, 2023
b261ecf
Merge branch 'develop' into hipModuleLoad_tests
mangupta Jul 10, 2023
afdf15b
Update CMakeLists.txt
mangupta Jul 10, 2023
2fbb319
Update CMakeLists.txt
mangupta Jul 10, 2023
e1f2434
Update CMakeLists.txt
mangupta Jul 10, 2023
a2c575b
Merge remote-tracking branch 'upstream/develop' into hipModuleLoad_tests
mirza-halilcevic Dec 28, 2023
73eedc2
Merge branch 'develop' into hipModuleLoad_tests
mirza-halilcevic Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions catch/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ add_subdirectory(multiThread)
add_subdirectory(compiler)
add_subdirectory(errorHandling)
add_subdirectory(cooperativeGrps)
add_subdirectory(module)
if(HIP_PLATFORM STREQUAL "amd")
#add_subdirectory(clock)
# Vulkan interop APIs currently undefined for Nvidia
Expand Down
25 changes: 25 additions & 0 deletions catch/unit/module/CMakeLists.txt
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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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)
20 changes: 20 additions & 0 deletions catch/unit/module/empty_module.cc
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.
*/
59 changes: 59 additions & 0 deletions catch/unit/module/hipModuleLoad.cc
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new TEST_CAST for this and disable it via json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
67 changes: 67 additions & 0 deletions catch/unit/module/hipModuleLoadData.cc
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
69 changes: 69 additions & 0 deletions catch/unit/module/hipModuleLoadDataEx.cc
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
44 changes: 44 additions & 0 deletions catch/unit/module/hipModuleUnload.cc
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
71 changes: 71 additions & 0 deletions catch/unit/module/hip_module_common.cc
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;
}
Loading