SWDEV-1 - Merge github PRs to amd-staging
Change-Id: I2944a63ddc2eec8dc1403d9790ffffbaec343385
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
if(HIP_PLATFORM MATCHES "nvidia")
|
||||
set(TEST_SRC
|
||||
assert.cc
|
||||
)
|
||||
hip_add_exe_to_target(NAME AssertionTest
|
||||
TEST_SRC ${TEST_SRC}
|
||||
TEST_TARGET_NAME build_tests
|
||||
LINKER_LIBS nvrtc)
|
||||
elseif(HIP_PLATFORM MATCHES "amd")
|
||||
set(TEST_SRC
|
||||
static_assert.cc
|
||||
assert.cc
|
||||
)
|
||||
hip_add_exe_to_target(NAME AssertionTest
|
||||
TEST_SRC ${TEST_SRC}
|
||||
TEST_TARGET_NAME build_tests
|
||||
LINKER_LIBS hiprtc)
|
||||
endif()
|
||||
|
||||
# Below tests fail in PSDB
|
||||
#add_test(NAME Unit_StaticAssert_Positive_Basic
|
||||
# COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../compileAndCaptureOutput.py
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR} ${HIP_PLATFORM} ${HIP_PATH}
|
||||
# static_assert_kernels_positive.cc 2)
|
||||
#
|
||||
#add_test(NAME Unit_StaticAssert_Negative_Basic
|
||||
# COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/../compileAndCaptureOutput.py
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR} ${HIP_PLATFORM} ${HIP_PATH}
|
||||
# static_assert_kernels_negative.cc 2)
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
Copyright (c) 2023 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 <csetjmp>
|
||||
#include <csignal>
|
||||
|
||||
/**
|
||||
* @addtogroup assert assert
|
||||
* @{
|
||||
* @ingroup DeviceLanguageTest
|
||||
* `void assert(int expression)` -
|
||||
* Stops the kernel execution if expression is equal to zero.
|
||||
*/
|
||||
|
||||
jmp_buf env_ignore_abort;
|
||||
volatile int abort_raised_flag = 0;
|
||||
|
||||
void on_sigabrt(int signum) {
|
||||
signal(signum, SIG_DFL);
|
||||
abort_raised_flag = 1;
|
||||
longjmp(env_ignore_abort, 1);
|
||||
}
|
||||
|
||||
void try_and_catch_abort(void (*func)()) {
|
||||
if (!setjmp(env_ignore_abort)) {
|
||||
signal(SIGABRT, &on_sigabrt);
|
||||
(*func)();
|
||||
signal(SIGABRT, SIG_DFL);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void AssertPassKernel(int* x) {
|
||||
const int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
*x = tid;
|
||||
// expected always to be true
|
||||
assert(tid >= 0);
|
||||
}
|
||||
|
||||
__global__ void AssertFailKernel(int* x) {
|
||||
const int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
*x = tid;
|
||||
// expected to fail for the even thread indices
|
||||
assert(tid % 2 == 1);
|
||||
}
|
||||
|
||||
template <bool should_abort> void LaunchAssertKernel() {
|
||||
const int num_blocks = 2;
|
||||
const int num_threads = 16;
|
||||
int *d_a;
|
||||
HIP_CHECK(hipMalloc(&d_a, sizeof(int)));
|
||||
|
||||
if constexpr (should_abort) {
|
||||
AssertFailKernel<<<num_blocks, num_threads, 0, 0>>>(d_a);
|
||||
#if HT_AMD
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
#else
|
||||
HIP_CHECK_ERROR(hipDeviceSynchronize(), hipErrorAssert);
|
||||
#endif
|
||||
} else {
|
||||
AssertPassKernel<<<num_blocks, num_threads, 0, 0>>>(d_a);
|
||||
HIP_CHECK(hipDeviceSynchronize());
|
||||
}
|
||||
|
||||
HIP_CHECK(hipFree(d_a));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Launches kernels with asserts that have an expression equal to 1.
|
||||
* - Expects that SIGABRT is not raised and kernels have executed successfully.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/assertion/assert.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_Assert_Positive_Basic_KernelPass") {
|
||||
try_and_catch_abort(&LaunchAssertKernel<false>);
|
||||
REQUIRE(abort_raised_flag == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Launches kernels with asserts that have an expression equal to 0.
|
||||
* - Expects that SIGABRT is raised and kernels have been stopped on AMD.
|
||||
* - The HIP runtime also aborts the host code, so this test case uses signal handlers
|
||||
* to avoid host code abortion.
|
||||
* - Expects that `hipErrorAssert` is returned from `hipDeviceSynchronize` on NVIDIA.
|
||||
* - The host code is not aborted.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/assertion/assert.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_Assert_Positive_Basic_KernelFail") {
|
||||
try_and_catch_abort(&LaunchAssertKernel<true>);
|
||||
#if HT_AMD
|
||||
REQUIRE(abort_raised_flag == 1);
|
||||
#else
|
||||
REQUIRE(abort_raised_flag == 0);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (c) 2023 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 "static_assert_kernels_rtc.hh"
|
||||
|
||||
/**
|
||||
* @addtogroup static_assert static_assert
|
||||
* @{
|
||||
* @ingroup DeviceLanguageTest
|
||||
* `void static_assert(constexpr expression, const char* message)` -
|
||||
* Stops the compilation if expression is equal to zero, and displays the specified message.
|
||||
*/
|
||||
|
||||
void StaticAssertWrapper(const char* program_source) {
|
||||
hiprtcProgram program{};
|
||||
|
||||
HIPRTC_CHECK(
|
||||
hiprtcCreateProgram(&program, program_source, "static_assert_rtc.cc", 0, nullptr, nullptr));
|
||||
hiprtcResult result{hiprtcCompileProgram(program, 0, nullptr)};
|
||||
|
||||
// Get the compile log and count compiler error messages
|
||||
size_t log_size{};
|
||||
HIPRTC_CHECK(hiprtcGetProgramLogSize(program, &log_size));
|
||||
std::string log(log_size, ' ');
|
||||
HIPRTC_CHECK(hiprtcGetProgramLog(program, log.data()));
|
||||
int error_count{0};
|
||||
|
||||
int expected_error_count{2};
|
||||
std::string error_message{"error:"};
|
||||
|
||||
size_t n_pos = log.find(error_message, 0);
|
||||
while (n_pos != std::string::npos) {
|
||||
++error_count;
|
||||
n_pos = log.find(error_message, n_pos + 1);
|
||||
}
|
||||
|
||||
HIPRTC_CHECK(hiprtcDestroyProgram(&program));
|
||||
HIPRTC_CHECK_ERROR(result, HIPRTC_ERROR_COMPILATION);
|
||||
REQUIRE(error_count == expected_error_count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Compiles kernels with static_assert calls:
|
||||
* -# Expected that static_assert passes and compilation is successful.
|
||||
* -# Expected that static_assert fails and compilation has errors.
|
||||
* - Uses RTC to perform compilation.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/assertion/static_assert.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_StaticAssert_Positive_Basic_RTC") { StaticAssertWrapper(kStaticAssert_Positive); }
|
||||
|
||||
/**
|
||||
* Test Description
|
||||
* ------------------------
|
||||
* - Passes invalidly formed expressions to static_assert calls.
|
||||
* - Uses expressions that are not constexpr and values that are not known during compilation.
|
||||
* - Uses RTC to perform compilation.
|
||||
* Test source
|
||||
* ------------------------
|
||||
* - unit/assertion/static_assert.cc
|
||||
* Test requirements
|
||||
* ------------------------
|
||||
* - HIP_VERSION >= 5.2
|
||||
*/
|
||||
TEST_CASE("Unit_StaticAssert_Negative_Basic_RTC") { StaticAssertWrapper(kStaticAssert_Negative); }
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2023 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>
|
||||
|
||||
__global__ void StaticAssertErrorKernel1() {
|
||||
const int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
static_assert(tid % 2 == 1, "[StaticAssertErrorKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertErrorKernel2() {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
static_assert(++tid > 2, "[StaticAssertErrorKernel2]");
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (c) 2023 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>
|
||||
|
||||
__global__ void StaticAssertPassKernel1() {
|
||||
static_assert(sizeof(int) < sizeof(long), "[StaticAssertPassKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertPassKernel2() { static_assert(10 > 5, "[StaticAssertPassKernel2]"); }
|
||||
|
||||
__global__ void StaticAssertFailKernel1() {
|
||||
static_assert(sizeof(int) > sizeof(long), "[StaticAssertFailKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertFailKernel2() { static_assert(10 < 5, "[StaticAssertFailKernel2]"); }
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
Positive and negative kernels used for the static_assert Test Cases that are using RTC.
|
||||
*/
|
||||
|
||||
static constexpr auto kStaticAssert_Positive{
|
||||
R"(
|
||||
__global__ void StaticAssertPassKernel1() {
|
||||
static_assert(sizeof(int) < sizeof(long), "[StaticAssertPassKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertPassKernel2() {
|
||||
static_assert(10 > 5, "[StaticAssertPassKernel2]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertFailKernel1() {
|
||||
static_assert(sizeof(int) > sizeof(long), "[StaticAssertFailKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertFailKernel2() {
|
||||
static_assert(10 < 5, "[StaticAssertFailKernel2]");
|
||||
}
|
||||
)"};
|
||||
|
||||
static constexpr auto kStaticAssert_Negative{
|
||||
R"(
|
||||
__global__ void StaticAssertErrorKernel1() {
|
||||
const int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
static_assert(tid % 2 == 1, "[StaticAssertErrorKernel1]");
|
||||
}
|
||||
|
||||
__global__ void StaticAssertErrorKernel2() {
|
||||
int tid = threadIdx.x + blockIdx.x * blockDim.x;
|
||||
static_assert(++tid > 2, "[StaticAssertErrorKernel2]");
|
||||
}
|
||||
)"};
|
||||
Reference in New Issue
Block a user