diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-08-28 19:03:39 (GMT) |
---|---|---|
committer | Zack Galbreath <zack.galbreath@kitware.com> | 2021-06-07 19:25:33 (GMT) |
commit | b50bfc89131e55685aa41146254b37d26049b4d5 (patch) | |
tree | e6ed45ba63b75decf4c9436fac6139174850370b /Tests/HIP/TryCompile | |
parent | ff0d2858e1e47af8e849318b411b1fbd8579a053 (diff) | |
download | CMake-b50bfc89131e55685aa41146254b37d26049b4d5.zip CMake-b50bfc89131e55685aa41146254b37d26049b4d5.tar.gz CMake-b50bfc89131e55685aa41146254b37d26049b4d5.tar.bz2 |
HIP: Add language to CMake
Diffstat (limited to 'Tests/HIP/TryCompile')
-rw-r--r-- | Tests/HIP/TryCompile/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/HIP/TryCompile/device_function.hip | 17 | ||||
-rw-r--r-- | Tests/HIP/TryCompile/main.hip | 8 |
3 files changed, 39 insertions, 0 deletions
diff --git a/Tests/HIP/TryCompile/CMakeLists.txt b/Tests/HIP/TryCompile/CMakeLists.txt new file mode 100644 index 0000000..f3bb3bf --- /dev/null +++ b/Tests/HIP/TryCompile/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.18) +project (TryCompile HIP) + +#Goal for this example: +# Verify try_compile with HIP language works +set(CMAKE_HIP_STANDARD 14) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +try_compile(result "${CMAKE_CURRENT_BINARY_DIR}" + SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/device_function.hip" + COPY_FILE "${CMAKE_CURRENT_BINARY_DIR}/device_function.o") + +add_executable(HIPOnlyTryCompile main.hip) +target_link_libraries(HIPOnlyTryCompile "${CMAKE_CURRENT_BINARY_DIR}/device_function.o") diff --git a/Tests/HIP/TryCompile/device_function.hip b/Tests/HIP/TryCompile/device_function.hip new file mode 100644 index 0000000..7c1205e --- /dev/null +++ b/Tests/HIP/TryCompile/device_function.hip @@ -0,0 +1,17 @@ +#include <system_error> +#include <hip/hip_runtime_api.h> + +static __global__ void fake_hip_kernel() +{ +} + +int __host__ try_compile_hip_func(int x) +{ + + fake_hip_kernel<<<1, 1>>>(); + bool valid = (hipSuccess == hipGetLastError()); + if (!valid) { + throw std::system_error(ENODEV, std::generic_category(), "no hip device"); + } + return x * x; +} diff --git a/Tests/HIP/TryCompile/main.hip b/Tests/HIP/TryCompile/main.hip new file mode 100644 index 0000000..091dca3 --- /dev/null +++ b/Tests/HIP/TryCompile/main.hip @@ -0,0 +1,8 @@ +int __host__ try_compile_hip_func(int x); + +int main(int argc, char** argv) +{ + try_compile_hip_func(int(42)); + + return 0; +} |