Skip to content

[OpenMP] Add ompTest library to OpenMP #147381

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions openmp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ There are following check-* make targets for tests.

- ``check-ompt`` (ompt tests under runtime/test/ompt)
- ``check-ompt-multiplex`` (ompt multiplex tests under tools/multiplex/tests)
- ``check-ompt-omptest`` (ompt omptest tests under tools/omptest/tests)
- ``check-libarcher`` (libarcher tests under tools/archer/tests)
- ``check-libomp`` (libomp tests under runtime/test. This includes check-ompt tests too)
- ``check-libomptarget-*`` (libomptarget tests for specific target under libomptarget/test)
Expand Down
116 changes: 116 additions & 0 deletions openmp/tools/omptest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
##===----------------------------------------------------------------------===##
#
# Build OMPT unit testing library: ompTest
#
##===----------------------------------------------------------------------===##

cmake_minimum_required(VERSION 3.22)
project(omptest LANGUAGES CXX)

option(LIBOMPTEST_BUILD_STANDALONE
"Build ompTest 'standalone', i.e. w/o GoogleTest." ${OPENMP_STANDALONE_BUILD})
option(LIBOMPTEST_BUILD_UNITTESTS
"Build ompTest's unit tests , requires GoogleTest." OFF)

# In absence of corresponding OMPT support: exit early
if(NOT ${LIBOMPTARGET_OMPT_SUPPORT})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this make sense here? Or should it be LIBOMP_OMPT_SUPPORT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the right CMake var to key off from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, also noted by @jprotze.
No, not necessarily.
I think with the extended scope of host & device, we might switch to LIBOMP_OMPT_SUPPORT as indirectly suggested by Joachim.

WDYT?
Do we need to actively "hide" some device-related functionalities when LIBOMP_OMPT_SUPPORT=ON and LIBOMPTARGET_OMPT_SUPPORT=OFF?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the question is: can we write assertions that automatically adjust to the set of available callbacks? I.e., if the target callback is not supported, but occurs in a sequence, just ignore such callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about this I'd say:
ompTest would try to register the callbacks, which fails, emits a print and continues:

But now that I re-read, you want the written assertions to be ignored in absence of the corresponding callback, correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

My idea was, that we should be able to write tests which describe the expected callback sequence. Some callbacks are "optional" and will not be triggered with cmake option LIBOMP_OMPT_OPTIONAL=off.
I think it makes sense to allow the test to specify the necessary/optional callbacks (as another assert statement). As a sane default, it probably makes sense to use the mandatory/optional from the standard.

But, if we want to run some target tests also with OMP_OFFLOAD=disabled, the target callbacks should probably be optional (while I'm actually not sure what set_callback reports in this case. Or when compiling without -fopenmp-target?).

return()
endif()

set(OMPTEST_HEADERS
./include/AssertMacros.h
./include/InternalEvent.h
./include/InternalEventCommon.h
./include/Logging.h
./include/OmptAliases.h
./include/OmptAsserter.h
./include/OmptAssertEvent.h
./include/OmptCallbackHandler.h
./include/OmptTester.h
./include/OmptTesterGlobals.h
)

add_library(omptest
SHARED

${OMPTEST_HEADERS}
./src/InternalEvent.cpp
./src/InternalEventOperators.cpp
./src/Logging.cpp
./src/OmptAsserter.cpp
./src/OmptAssertEvent.cpp
./src/OmptCallbackHandler.cpp
./src/OmptTester.cpp
)

# Target: ompTest library
# On (implicit) request of GoogleTest, link against the one provided with LLVM.
if ((NOT LIBOMPTEST_BUILD_STANDALONE) OR LIBOMPTEST_BUILD_UNITTESTS)
# Check if standalone build was requested together with unittests
if (LIBOMPTEST_BUILD_STANDALONE)
# Emit warning: this build actually depends on LLVM's GoogleTest
message(WARNING "LIBOMPTEST_BUILD_STANDALONE and LIBOMPTEST_BUILD_UNITTESTS"
" requested simultaneously.\n"
"Linking against LLVM's GoogleTest library archives.\n"
"Disable LIBOMPTEST_BUILD_UNITTESTS to perform an actual"
" standalone build.")
# Explicitly disable LIBOMPTEST_BUILD_STANDALONE
set(LIBOMPTEST_BUILD_STANDALONE OFF)
endif()

# Use LLVM's gtest library archive
set(GTEST_LIB "${LLVM_BINARY_DIR}/lib/libllvm_gtest.a")
# Link gtest as whole-archive to expose required symbols
set(GTEST_LINK_CMD "-Wl,--whole-archive" ${GTEST_LIB}
"-Wl,--no-whole-archive" LLVMSupport)

# Add GoogleTest-based header
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)

# Add LLVM-provided GoogleTest include directories.
target_include_directories(omptest PRIVATE
${LLVM_THIRD_PARTY_DIR}/unittest/googletest/include)

# TODO: Re-visit ABI breaking checks, disable for now.
target_compile_definitions(omptest PUBLIC
-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING)

# Link against gtest and gtest_main
target_link_libraries(omptest PRIVATE ${GTEST_LINK_CMD})
else()
# Add 'standalone' compile definitions
target_compile_definitions(omptest PRIVATE
-DOPENMP_LIBOMPTEST_BUILD_STANDALONE)

# Add 'standalone' source files
target_sources(omptest PRIVATE
./include/OmptTesterStandalone.h
./src/OmptTesterStandalone.cpp)
endif()

# Add common include directories.
target_include_directories(omptest PRIVATE
./include
${LIBOMPTARGET_INCLUDE_DIR})
target_compile_features(omptest PRIVATE cxx_std_17)

# Create and install package configuration files.
configure_file(
${omptest_SOURCE_DIR}/cmake/omptest-config.cmake.in
${omptest_BINARY_DIR}/cmake/omptest-config.cmake @ONLY)

install(FILES ${omptest_BINARY_DIR}/cmake/omptest-config.cmake
DESTINATION "${OPENMP_INSTALL_LIBDIR}/cmake/openmp/omptest")

# Install libomptest header files: Copy header-files from include dir
install(DIRECTORY ./include
DESTINATION "${LIBOMP_HEADERS_INSTALL_PATH}/omptest"
FILES_MATCHING PATTERN "*.h")

install(TARGETS omptest LIBRARY COMPONENT omptest
DESTINATION "${OPENMP_INSTALL_LIBDIR}")

# Discover unit tests (added to check-openmp)
if(LIBOMPTEST_BUILD_UNITTESTS)
add_subdirectory(test)
endif()
Loading
Loading