-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe262f6
commit 3575cfd
Showing
5 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* Copyright 2022 Andrea Bocci, Mehmet Yusufoglu, René Widera, Aurora Perego | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
// Implementation details | ||
#include "alpaka/core/Sycl.hpp" | ||
|
||
//! ALPAKA_THROW_ACC either aborts(terminating the program and creating a core dump) or throws std::runtime_error | ||
//! depending on the Acc. The std::runtime_error exception can be catched in the catch block. | ||
//! | ||
//! For CUDA __trap function is used which triggers std::runtime_error but can be catched during wait not exec. | ||
//! For HIP abort() function is used and calls __builtin_trap() | ||
//! For Sycl assert(false) is not used since it can be disabled -DNDEBUG compile option. abort() is used although it | ||
//! generates a runtime error instead of aborting in GPUs: "Caught synchronous SYCL exception: Unresolved Symbol | ||
//! <abort> -999 (Unknown PI error)." | ||
//! | ||
//! The OpenMP specification mandates that exceptions thrown by some thread must be handled by the same thread. | ||
//! Therefore std::runtime_error thrown by ALPAKA_THROW_ACC aborts the the program for OpenMP backends. If needed | ||
//! the SIGABRT signal can be catched by signal handler. | ||
#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && defined(__CUDA_ARCH__) | ||
# define ALPAKA_THROW_ACC(MSG) \ | ||
{ \ | ||
printf( \ | ||
"alpaka encountered a user-defined error condition while running on the CUDA back-end:\n%s", \ | ||
(MSG)); \ | ||
__trap(); \ | ||
} | ||
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) && defined(__HIP_DEVICE_COMPILE__) | ||
# define ALPAKA_THROW_ACC(MSG) \ | ||
{ \ | ||
printf( \ | ||
"alpaka encountered a user-defined error condition while running on the HIP back-end:\n%s", \ | ||
(MSG)); \ | ||
abort(); \ | ||
} | ||
#elif defined(ALPAKA_ACC_SYCL_ENABLED) && defined(__SYCL_DEVICE_ONLY__) | ||
# define ALPAKA_THROW_ACC(MSG) \ | ||
{ \ | ||
printf( \ | ||
"alpaka encountered a user-defined error condition while running on the SYCL back-end:\n%s", \ | ||
(MSG)); \ | ||
abort(); \ | ||
} | ||
#else | ||
# define ALPAKA_THROW_ACC(MSG) \ | ||
{ \ | ||
printf("alpaka encountered a user-defined error condition:\n%s", (MSG)); \ | ||
throw std::runtime_error(MSG); \ | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright 2014-2020 Benjamin Worpitz, Axel Huebl, Jan Stephan | ||
# SPDX-License-Identifier: MPL-2.0 | ||
# | ||
|
||
set(_TARGET_NAME "runtimeTest") | ||
|
||
append_recursive_files_add_to_src_group("src/" "src/" "cpp" _FILES_SOURCE) | ||
|
||
alpaka_add_executable( | ||
${_TARGET_NAME} | ||
${_FILES_SOURCE}) | ||
target_link_libraries( | ||
${_TARGET_NAME} | ||
PRIVATE common) | ||
|
||
set_target_properties(${_TARGET_NAME} PROPERTIES FOLDER "test/unit") | ||
target_compile_definitions(${_TARGET_NAME} PRIVATE "-DTEST_UNIT_RUNTIME") | ||
|
||
add_test(NAME ${_TARGET_NAME} COMMAND ${_TARGET_NAME} ${_alpaka_TEST_OPTIONS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* Copyright 2022 René Widera, Mehmet Yusufoglu, Andrea Bocci | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
#include <alpaka/core/RuntimeMacros.hpp> | ||
#include <alpaka/test/acc/TestAccs.hpp> | ||
#include <alpaka/test/queue/Queue.hpp> | ||
|
||
#include <catch2/catch_template_test_macros.hpp> | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
class KernelWithThrow | ||
{ | ||
public: | ||
template<typename TAcc> | ||
ALPAKA_FN_ACC auto operator()(TAcc const& acc) const -> void | ||
{ | ||
using Idx = alpaka::Idx<TAcc>; | ||
using Dim = alpaka::Dim<TAcc>; | ||
using Vec = alpaka::Vec<Dim, Idx>; | ||
Vec const globalThreadIdx = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc); | ||
if(globalThreadIdx == Vec::zeros()) | ||
{ | ||
// Throw abort or std::runtime_error depending on acc type | ||
ALPAKA_THROW_ACC("Exception thrown by the kernel."); | ||
} | ||
alpaka::syncBlockThreads(acc); | ||
} | ||
}; | ||
|
||
template<typename T, typename Acc> | ||
void checkThrow(std::string const& expectedErrStr) | ||
{ | ||
if constexpr(alpaka::accMatchesTags<Acc, T>) | ||
{ | ||
using Idx = alpaka::Idx<Acc>; | ||
using Dim = alpaka::Dim<Acc>; | ||
using Vec = alpaka::Vec<Dim, Idx>; | ||
using Queue = alpaka::Queue<Acc, alpaka::Blocking>; | ||
|
||
auto const platformAcc = alpaka::Platform<Acc>{}; | ||
auto const devAcc = alpaka::getDevByIdx(platformAcc, 0); | ||
|
||
Queue queue(devAcc); | ||
auto const workDiv = alpaka::WorkDivMembers<Dim, Idx>{Vec{8}, Vec{1}, Vec{1}}; | ||
|
||
try | ||
{ | ||
alpaka::exec<Acc>(queue, workDiv, KernelWithThrow{}); | ||
// Cuda can catch exceptions which were thrown at kernel during the wait(); therefore wait is added. | ||
alpaka::wait(queue); | ||
} | ||
catch(std::runtime_error& e) | ||
{ | ||
std::string const errorStr{e.what()}; | ||
printf("The error str catched: %s \n", errorStr.c_str()); | ||
printf("The expected str in error str: %s \n", expectedErrStr.c_str()); | ||
|
||
auto const found = errorStr.find(expectedErrStr); | ||
CHECK(found != std::string::npos); | ||
} | ||
catch(std::exception& e) | ||
{ | ||
FAIL(std::string("Wrong exception type thrown in kernel:") + e.what()); | ||
} | ||
} | ||
} | ||
|
||
using TestAccs = alpaka::test::EnabledAccs<alpaka::DimInt<1u>, std::uint32_t>; | ||
|
||
TEMPLATE_LIST_TEST_CASE("ThrowForCpuThreadAndSerial", "[runtime]", TestAccs) | ||
{ | ||
using Acc = TestType; | ||
// Test runtime-error exceptions. | ||
checkThrow<alpaka::TagCpuThreads, Acc>("Exception thrown by the kernel"); | ||
checkThrow<alpaka::TagCpuSerial, Acc>("Exception thrown by the kernel"); | ||
} | ||
|
||
TEMPLATE_LIST_TEST_CASE("ThrowForGpuBackend", "[runtime]", TestAccs) | ||
{ | ||
using Acc = TestType; | ||
// Test runtime-error exceptions. | ||
checkThrow<alpaka::TagGpuCudaRt, Acc>("cudaErrorLaunchFailure"); | ||
} |