From 6cc48567ac89131e68a42f0bfb3c4bf38c344448 Mon Sep 17 00:00:00 2001 From: Jean-Luc Fattebert Date: Wed, 20 Apr 2022 16:28:11 -0400 Subject: [PATCH] Add simple test to verify OpenMP offload Verify simple OpenMP loop running on device, to check OpenMP offload working --- tests/C-tests/CMakeLists.txt | 11 +++++++++++ tests/C-tests/test_openmp_offload.c | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/C-tests/test_openmp_offload.c diff --git a/tests/C-tests/CMakeLists.txt b/tests/C-tests/CMakeLists.txt index aac64d0ef..855366881 100644 --- a/tests/C-tests/CMakeLists.txt +++ b/tests/C-tests/CMakeLists.txt @@ -1,5 +1,16 @@ include_directories(${PROJECT_SOURCE_DIR}/src/C-interface) +if(BML_OMP_OFFLOAD) + add_executable(test-openmp_offload test_openmp_offload.c) + target_link_libraries(test-openmp_offload bml ${LINK_LIBRARIES}) + set_target_properties(test-openmp_offload + PROPERTIES + COMPILE_FLAGS ${OpenMP_C_FLAGS} + LINK_FLAGS ${OpenMP_C_FLAGS}) + add_test(openmp_offload ${BML_NONMPI_PRECOMMAND} ${BML_NONMPI_PRECOMMAND_ARGS} + ${CMAKE_CURRENT_BINARY_DIR}/test-openmp_offload) +endif() + set(SOURCES_TYPED add_matrix_typed.c adjacency_matrix_typed.c diff --git a/tests/C-tests/test_openmp_offload.c b/tests/C-tests/test_openmp_offload.c new file mode 100644 index 000000000..c85136c57 --- /dev/null +++ b/tests/C-tests/test_openmp_offload.c @@ -0,0 +1,17 @@ +#include + +int +main( + int argc, + char **argv) +{ + int is_device = 1; + +#pragma omp target map(from : is_device) + { + is_device = omp_is_initial_device(); + } + + // returns 0 if executed on device, 1 otherwise + return is_device; +}