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-118 - Implement tests for hipFuncGetAttribute #61

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 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
580df9d
Create common code for module tests
music-dino Dec 7, 2022
4575966
EXSWHTEC-112 - Implement tests for hipModuleGetFunction
music-dino Dec 7, 2022
346cc62
EXSWHTEC-118 - Implement tests for hipFuncGetAttribute
mirza-halilcevic Dec 9, 2022
40d3102
EXSWHTEC-118 - Disable failing tests on AMD.
mirza-halilcevic Dec 13, 2022
e347b31
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 16, 2022
73b6e5b
Merge remote-tracking branch 'origin/hipModuleGetFunction_tests' into…
mirza-halilcevic Dec 18, 2022
a7fb978
Merge remote-tracking branch 'upstream/develop' into hipFuncGetAttrib…
mirza-halilcevic Dec 18, 2022
6a4e9ef
EXSWHTEC-118 - Disable test case in json due to defect.
mirza-halilcevic Mar 20, 2023
3398391
Merge remote-tracking branch 'origin/develop' into hipFuncGetAttribut…
mirza-halilcevic Jun 28, 2023
5fe59b6
Merge branch 'develop' into hipFuncGetAttribute_tests
rakesroy Jun 28, 2023
e83ba57
Merge remote-tracking branch 'origin/develop' into hipFuncGetAttribut…
mirza-halilcevic Dec 17, 2023
a90537f
Merge branch 'develop' into hipFuncGetAttribute_tests
mirza-halilcevic Dec 17, 2023
550e03e
Merge branch 'develop' into hipFuncGetAttribute_tests
mirza-halilcevic Dec 28, 2023
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
2 changes: 2 additions & 0 deletions catch/hipTestMain/config/config_amd_linux
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
"Unit_deviceAllocation_InOneThread_AccessInAllThreads",
"=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===",
"Unit_hiprtc_stdheaders",
"NOTE: The following test is disabled due to defect - EXSWHTEC-245",
"Unit_hipFuncGetAttribute_Negative_Parameters",
"Unit_hipMemAddressFree_negative",
"Unit_hipMemAddressReserve_AlignmentTest",
"Unit_hipMemAddressReserve_Negative",
Expand Down
2 changes: 2 additions & 0 deletions catch/hipTestMain/config/config_amd_windows
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@
"Unit_Layered2DTexture_Check_DeviceBufferToFromLayered2DArray - float4",
"=== Patch which removes the typetraits implementation from std namespace in hiprtc is reverted ===",
"Unit_hiprtc_stdheaders",
"NOTE: The following test is disabled due to defect - EXSWHTEC-245",
"Unit_hipFuncGetAttribute_Negative_Parameters",
"Unit_hipMemAddressFree_negative",
"Unit_hipMemAddressReserve_AlignmentTest",
"Unit_hipMemAddressReserve_Negative",
Expand Down
6 changes: 6 additions & 0 deletions catch/include/utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@ inline bool DeviceAttributesSupport(const int device, Attributes... attributes)
};
return (... && DeviceAttributeSupport(device, attributes));
}

inline int GetDeviceAttribute(const int device, const hipDeviceAttribute_t attr) {
int value = 0;
HIP_CHECK(hipDeviceGetAttribute(&value, attr, device));
return value;
}
1 change: 1 addition & 0 deletions catch/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ add_subdirectory(vector_types)
add_subdirectory(atomics)
add_subdirectory(p2p)
add_subdirectory(gcc)
add_subdirectory(vector_types)

if(HIP_PLATFORM STREQUAL "amd")
add_subdirectory(callback)
Expand Down
30 changes: 26 additions & 4 deletions catch/unit/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@
# SOFTWARE.

# Common Tests - Test independent of all platforms
if(HIP_PLATFORM MATCHES "amd")
set(TEST_SRC
hipExtModuleLaunchKernel.cc
hip_module_common.cc
hipModuleGetFunction.cc
hipFuncGetAttribute.cc
)

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/get_function_module.code
COMMAND ${CMAKE_CXX_COMPILER} --genco --std=c++17 ${CMAKE_CURRENT_SOURCE_DIR}/get_function_module.cc -o get_function_module.code
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/get_function_module.cc)
add_custom_target(get_function_module ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/get_function_module.code)

if(HIP_PLATFORM MATCHES "amd")
set(TEST_SRC
${TEST_SRC}
hipExtModuleLaunchKernel.cc)

# Note to pass arch use format like -DOFFLOAD_ARCH_STR="--offload-arch=gfx900 --offload-arch=gfx906"
# having space at the start/end of OFFLOAD_ARCH_STR can cause build failures

Expand Down Expand Up @@ -100,14 +111,25 @@ add_custom_target(copiousArgKernel17.code
-I${CMAKE_CURRENT_SOURCE_DIR}/../../../../include/
-I${CMAKE_CURRENT_SOURCE_DIR}/../../include --rocm-path=${ROCM_PATH})
endif()
endif()

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 COMMON_SHARED_SRC ${COMMON_SHARED_SRC})
TEST_TARGET_NAME build_tests
LINKER_LIBS ${RTCLIB}
COMMON_SHARED_SRC ${COMMON_SHARED_SRC})

add_dependencies(ModuleTest get_function_module)

if(HIP_PLATFORM MATCHES "amd")
add_dependencies(build_tests copyKernel.code copyKernel.s)
if(UNIX)
add_dependencies(build_tests copiousArgKernel.code copiousArgKernel0.code copiousArgKernel1.code copiousArgKernel2.code
copiousArgKernel3.code copiousArgKernel16.code copiousArgKernel17.code)
endif()
endif()
endif()
28 changes: 28 additions & 0 deletions catch/unit/module/get_function_module.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
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/hip_runtime_api.h>

extern "C" {
__global__ void GlobalKernel() {}

__device__ void DeviceKernel() {}
}
96 changes: 96 additions & 0 deletions catch/unit/module/hipFuncGetAttribute.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
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>
#include <utils.hh>

static hipModule_t GetModule() {
HIP_CHECK(hipFree(nullptr));
static const auto mg = ModuleGuard::LoadModule("get_function_module.code");
return mg.module();
}

TEST_CASE("Unit_hipFuncGetAttribute_Positive_Basic") {
hipFunction_t kernel = GetKernel(GetModule(), "GlobalKernel");

int value;

SECTION("binaryVersion") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_BINARY_VERSION, kernel));
#if HT_NVIDIA
const auto major = GetDeviceAttribute(0, hipDeviceAttributeComputeCapabilityMajor);
const auto minor = GetDeviceAttribute(0, hipDeviceAttributeComputeCapabilityMinor);
REQUIRE(value == major * 10 + minor);
#elif HT_AMD
REQUIRE(value > 0);
#endif
}

SECTION("cacheModeCA") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA, kernel));
REQUIRE((value == 0 || value == 1));
}

SECTION("maxThreadsPerBlock") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK, kernel));
REQUIRE(value == GetDeviceAttribute(0, hipDeviceAttributeMaxThreadsPerBlock));
}

SECTION("numRegs") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_NUM_REGS, kernel));
REQUIRE(value >= 0);
}

SECTION("ptxVersion") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_PTX_VERSION, kernel));
REQUIRE(value > 0);
}

SECTION("sharedSizeBytes") {
HIP_CHECK(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES, kernel));
REQUIRE(value <= GetDeviceAttribute(0, hipDeviceAttributeMaxSharedMemoryPerBlock));
}
}

TEST_CASE("Unit_hipFuncGetAttribute_Negative_Parameters") {
hipFunction_t kernel = GetKernel(GetModule(), "GlobalKernel");

int value;

SECTION("value == nullptr") {
HIP_CHECK_ERROR(hipFuncGetAttribute(nullptr, HIP_FUNC_ATTRIBUTE_BINARY_VERSION, kernel),
hipErrorInvalidValue);
}

SECTION("invalid attribute") {
HIP_CHECK_ERROR(hipFuncGetAttribute(&value, static_cast<hipFunction_attribute>(-1), kernel),
hipErrorInvalidValue);
}

SECTION("hfunc == nullptr") {
HIP_CHECK_ERROR(hipFuncGetAttribute(&value, HIP_FUNC_ATTRIBUTE_BINARY_VERSION, nullptr),
hipErrorInvalidResourceHandle);
}
}
74 changes: 74 additions & 0 deletions catch/unit/module/hipModuleGetFunction.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
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>

static hipModule_t GetModule() {
HIP_CHECK(hipFree(nullptr));
static const auto mg = ModuleGuard::LoadModule("get_function_module.code");
return mg.module();
}

TEST_CASE("Unit_hipModuleGetFunction_Positive_Basic") {
hipFunction_t kernel = nullptr;
HIP_CHECK(hipModuleGetFunction(&kernel, GetModule(), "GlobalKernel"));
REQUIRE(kernel != nullptr);
}

TEST_CASE("Unit_hipModuleGetFunction_Negative_Parameters") {
hipFunction_t kernel = nullptr;

SECTION("function == nullptr") {
HIP_CHECK_ERROR(hipModuleGetFunction(nullptr, GetModule(), "GlobalKernel"),
hipErrorInvalidValue);
}

// Disabled on AMD due to defect - EXSWHTEC-154
#if HT_NVIDIA
mirza-halilcevic marked this conversation as resolved.
Show resolved Hide resolved
SECTION("module == nullptr") {
HIP_CHECK_ERROR(hipModuleGetFunction(&kernel, nullptr, "GlobalKernel"),
hipErrorInvalidResourceHandle);
}
#endif

SECTION("kname == nullptr") {
HIP_CHECK_ERROR(hipModuleGetFunction(&kernel, GetModule(), nullptr), hipErrorInvalidValue);
}

// Disabled on AMD due to defect - EXSWHTEC-155
#if HT_NVIDIA
SECTION("kname == empty string") {
HIP_CHECK_ERROR(hipModuleGetFunction(&kernel, GetModule(), ""), hipErrorInvalidValue);
}
#endif

SECTION("kname == non existent kernel") {
HIP_CHECK_ERROR(hipModuleGetFunction(&kernel, GetModule(), "NonExistentKernel"),
hipErrorNotFound);
}

SECTION("kname == __device__ kernel") {
HIP_CHECK_ERROR(hipModuleGetFunction(&kernel, GetModule(), "DeviceKernel"), hipErrorNotFound);
}
}
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