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

[External]Add OpenACC Validation and Verification testsuite #38

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions External/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ add_subdirectory(Povray)
add_subdirectory(SPEC)
add_subdirectory(skidmarks10)
add_subdirectory(sollve_vv)
add_subdirectory(OpenACCV_V)
70 changes: 70 additions & 0 deletions External/OpenACCV_V/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# OpenACCV&V Validation & Verification Suite
# https://github.com/OpenACCUserGroup/OpenACCV-V

include(External)

option(TEST_SUITE_FORCE_ALL "Execute all OpenACC V&V tests, even those known to be unsupported by Clang" OFF)

set(TEST_SUITE_OFFLOADING_FLAGS --offload-arch=native CACHE STRING "Compiler arguments for offloading")
set(TEST_SUITE_OFFLOADING_LDFLAGS --offload-arch=native CACHE STRING "Linker arguments for offloading")

function (add_OpenACC_vv LANG)
if (NOT OpenACC_${LANG}_FOUND)
message(FATAL_ERROR "OpenACC for ${LANG} not found")
return ()
endif ()
if ("${LANG}" STREQUAL "C")
set(_langext ".c")
elseif ("${LANG}" STREQUAL "CXX")
set(_langext ".cpp")
elseif ("${LANG}" STREQUAL "Fortran")
set(_langext ".F90")
else ()
message(FATAL_ERROR "Unsupported languge ${LANG}")
endif ()

file(GLOB_RECURSE _tests_sources RELATIVE "${TEST_SUITE_OpenACCVV_ROOT}/Tests" "${TEST_SUITE_OpenACCVV_ROOT}/Tests/*${_langext}" )
foreach (_file IN LISTS _tests_sources)
get_filename_component(_ext "${_file}" EXT)
get_filename_component(_basename "${_file}" NAME_WE)
get_filename_component(_directory "${_file}" DIRECTORY)
string(REPLACE "." "" _ext "${_ext}")
set(_name "acctargetvv-${_basename}.${_ext}")

llvm_test_run()

llvm_test_executable(${_name} "${TEST_SUITE_OpenACCVV_ROOT}/Tests/${_file}")

target_link_libraries(${_name} PUBLIC OpenACC::OpenACC_${_lang} m)

# Add -fopenacc to linker command line; for some reason this is not done by target_link_libraries.
target_link_options(${_name} PRIVATE ${OpenACC_${LANG}_FLAGS})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this comment isn't accurate, right? It is adding the openacc-language flags, not the -fopenacc? Or where are the OpenACC_C_flags and OpenACC_CXX_flags set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my fault - you were right before

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"OpenACC_C_flags "and "OpenACC_CXX_flags" are set in cmake. Check out the official FindOpenACC documentation at the following website: https://cmake.org/cmake/help/latest/module/FindOpenACC.html

But my error, currently find_package(OpenACC), only NVHPC, PGI, GNU and Cray compilers are supported, We cannot use this method to see if the current llvm supports OpenACC. "OpenACC_C_flags "and "OpenACC_CXX_flags" are currently invalid

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangxin0321 Is there a way around? Or we have to make an issue with cmake?


# CMake's find_package(OpenACC) currently does not not introspect flags necessary for offloading.
target_compile_options(${_name} PUBLIC ${TEST_SUITE_OFFLOADING_FLAGS})
target_link_options(${_name} PUBLIC ${TEST_SUITE_OFFLOADING_LDFLAGS})
endforeach ()
endfunction ()


llvm_externals_find(TEST_SUITE_OpenACCVV_ROOT "OpenACCV_V" "OpenACC Offloading Validation & Verification Suite")

if(TEST_SUITE_OpenACCVV_ROOT AND NOT TEST_SUITE_BENCHMARKING_ONLY)
if(${CMAKE_VERSION} VERSION_LESS 3.25)
message(STATUS "The cmake version must be at least 3.25 to perform OpenACC tests")
else()
find_package(OpenACC)
endif()
if(OpenACC_FOUND)
message(STATUS "Adding OpenACC Offloading Validiation & Verification")
else()
message(STATUS "NOT using OpenACC Validiation & Verification because OpenACC was not found")
return()
endif()

foreach (_lang in C CXX Fortran)
if(CMAKE_${_lang}_COMPILER)
add_OpenACC_vv(${_lang})
endif()
endforeach ()
endif ()
52 changes: 52 additions & 0 deletions External/OpenACCV_V/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
OpenACC Validation & Verification Suite
https://github.com/OpenACCUserGroup/OpenACCV-V

This directory contains a CMakeLists.txt for the OpenACC
Validation and Verification Suite so it can be built as part
of the LLVM test-suite. Its sources are not part of the test-suite but
have to be fetched separately from https://github.com/OpenACCUserGroup/OpenACCV-V

The sources are expected either in ${TEST_SUITE_OpenACCVV_ROOT} or
where TEST_SUITE_OpenACCVV_ROOT is CMake configure variables. If none of
them are set, it will look into
${CMAKE_SOURCE_DIR}/Extern/External/OpenACC_vv where
CMAKE_SOURCE_DIR is the root directory of the test-suite sources.

The CMakeLists.txt will search for all C 、C++ and Fortran source files of the
OpenACC V&V suite, compile and run them. That is, running llvm-lit
(or "make check") will require a compatible accelerator on the running
machine.

OpenACC support is autodetected by CMake, but clang requires additional
flags to enable offloading. An example run is:

$ cd /path/to/llvm-test-suit
$ mkdir build
$ cd build
$ cmake -GNinja -DTEST_SUITE_FORTRAN=ON \
-DTEST_SUITE_BENCHMARKING_ONLY=OFF \
-DTEST_SUITE_RUN_BENCHMARKS=ON \
-DTEST_SUITE_COLLECT_STATS=OFF \
-DTEST_SUITE_SUBDIRS="External/OpenACCV_V" \
-DCMAKE_BUILD_TYPE=Release \
-DTEST_SUITE_OpenACCVV_ROOT=/path/to/OpenACCV_V \
-DTEST_SUITE_COLLECT_CODE_SIZE=OFF \
-DTEST_SUITE_LIT=${HOME}/path/to/llvm-project/build/bin/llvm-lit \
-DCMAKE_C_COMPILER=${HOME}/install/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=${HOME}/install/llvm/bin/clang++ \
-DCMAKE_Fortran_COMPILER=${HOME}/install/llvm/bin/flang \
-DTEST_SUITE_OFFLOADING_FLAGS="-fopenacc;-lm;-foffload='-lm';" \
-DTEST_SUITE_OFFLOADING_LDFLAGS="-fopenacc;-lm;-foffload='-lm';" \
../

To make:
$ LD_LIBRARY_PATH=${HOME}/install/llvm-project/release/lib
$ ninja check

To run:
The test results are saved in the reule file
$ llvm-lit -svj1 --shuffle --xunit-xml-output=result-xunit.xml .

Attention:
Because find_package(OpenACC) is used in this test case, attempting to execute this test case requires cmake version >= 3.25
take a closer look at FindOpenACC in cmake:https://cmake.org/cmake/help/latest/module/FindOpenACC.html