Skip to content

Conversation

mhalk
Copy link
Contributor

@mhalk mhalk commented Aug 21, 2025

Reland of #147381

Added changes to fix observed BuildBot failures:

  • CMake version (reduced minimum to 3.20, was: 3.22)
  • GoogleTest linking (missing ./build/lib/libllvm_gtest.a)
    • Related header issue (missing #include "llvm/Support/raw_os_ostream.h")

@llvmbot llvmbot added openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime labels Aug 21, 2025
Copy link
Contributor

@mjklemm mjklemm left a comment

Choose a reason for hiding this comment

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

LGTM.

@jprotze
Copy link
Collaborator

jprotze commented Aug 21, 2025

My local build still fails during linking openmp/tools/omptest/libomptest.so:

ld: openmp/tools/omptest/CMakeFiles/omptest.dir/src/OmptTester.cpp.o: in function `std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<void*, void*>*>, bool> std::__1::__hash_table<void*, std::__1::hash<void*>, std::__1::equal_to<void*>, std::__1::allocator<void*> >::__emplace_unique_key_args<void*, void* const&>(void* const&, void* const&)':
OmptTester.cpp:(.text._ZNSt3__112__hash_tableIPvNS_4hashIS1_EENS_8equal_toIS1_EENS_9allocatorIS1_EEE25__emplace_unique_key_argsIS1_JRKS1_EEENS_4pairINS_15__hash_iteratorIPNS_11__hash_nodeIS1_S1_EEEEbEERKT_DpOT0_[_ZNSt3__112__hash_tableIPvNS_4hashIS1_EENS_8equal_toIS1_EENS_9allocatorIS1_EEE25__emplace_unique_key_argsIS1_JRKS1_EEENS_4pairINS_15__hash_iteratorIPNS_11__hash_nodeIS1_S1_EEEEbEERKT_DpOT0_]+0x27): undefined reference to `std::__1::__hash_memory(void const*, unsigned long)'

mhalk and others added 2 commits August 21, 2025 11:54
Description
===========
OpenMP Tooling Interface Testing Library (ompTest)
ompTest is a unit testing framework for testing OpenMP implementations.
It offers a simple-to-use framework that allows a tester to check for
OMPT events in addition to regular unit testing code, supported by
linking against GoogleTest by default. It also facilitates writing
concise tests while bridging the semantic gap between the unit under
test and the OMPT-event testing.

Background
==========
This library has been developed to provide the means of testing OMPT
implementations with reasonable effort. Especially, asynchronous or
unordered events are supported and can be verified with ease, which may
prove to be challenging with LIT-based tests. Additionally, since the
assertions are part of the code being tested, ompTest can reference all
corresponding variables during assertion.

Basic Usage
===========
OMPT event assertions are placed before the code, which shall be tested.
These assertion can either be provided as one block or interleaved with
the test code. There are two types of asserters: (1) sequenced
"order-sensitive" and (2) set "unordered" assserters. Once the test is
being run, the corresponding events are triggered by the OpenMP runtime
and can be observed. Each of these observed events notifies asserters,
which then determine if the test should pass or fail.

Example (partial, interleaved)
==============================

  int N = 100000;
  int a[N];
  int b[N];

  OMPT_ASSERT_SEQUENCE(Target, TARGET, BEGIN, 0);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, ALLOC, N * sizeof(int)); // a ?
  OMPT_ASSERT_SEQUENCE(TargetDataOp, H2D, N * sizeof(int), &a);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, ALLOC, N * sizeof(int)); // b ?
  OMPT_ASSERT_SEQUENCE(TargetDataOp, H2D, N * sizeof(int), &b);
  OMPT_ASSERT_SEQUENCE(TargetSubmit, 1);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, D2H, N * sizeof(int), nullptr, &b);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, D2H, N * sizeof(int), nullptr, &a);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, DELETE);
  OMPT_ASSERT_SEQUENCE(TargetDataOp, DELETE);
  OMPT_ASSERT_SEQUENCE(Target, TARGET, END, 0);

#pragma omp target parallel for
  {
    for (int j = 0; j < N; j++)
      a[j] = b[j];
  }

References
==========
This work has been presented at SC'24 workshops, see:
https://ieeexplore.ieee.org/document/10820689

Current State and Future Work
=============================
ompTest's development was mostly device-centric and aimed at OMPT device
callbacks and device-side tracing. Consequentially, a substantial part
of host-related events or features may not be supported in its current
state. However, we are confident that the related functionality can be
added and ompTest provides a general foundation for future OpenMP and
especially OMPT testing. This PR will allow us to upstream the
corresponding features, like OMPT device-side tracing in the future with
significantly reduced risk of introducing regressions in the process.

Build
=====
ompTest is linked against LLVM's GoogleTest by default, but can also be
built 'standalone'. Additionally, it comes with a set of unit tests,
which in turn require GoogleTest (overriding a standalone build). The
unit tests are added to the `check-openmp` target.

Use the following parameters to perform the corresponding build:
`LIBOMPTEST_BUILD_STANDALONE` (Default: ${OPENMP_STANDALONE_BUILD})
`LIBOMPTEST_BUILD_UNITTESTS`  (Default: OFF)

---------

Co-authored-by: Jan-Patrick Lehr <JanPatrick.Lehr@amd.com>
Co-authored-by: Joachim <protze@rz.rwth-aachen.de>
Adapted minimum CMake version
Fixed llvm_gtest linking
 - Replaced archive path with target name
 - Fixed related warning and added checks for llvm_gtest
Copy link
Collaborator

@jprotze jprotze left a comment

Choose a reason for hiding this comment

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

Lgtm

With the additional dependencies a fresh libc++-first build succeeds.

@mhalk mhalk force-pushed the mhalk/feat/openmp-omptest-lib-reland branch from aa3bb7b to 880552c Compare August 21, 2025 17:34
@mhalk
Copy link
Contributor Author

mhalk commented Aug 21, 2025

Apologies @jprotze I was working on this and blindly force-pushed as I was not aware of your commit.
Could you please re-submit your changes?
As it seems, I can not restore your commit.

@mhalk
Copy link
Contributor Author

mhalk commented Aug 21, 2025

Thank you Joachim, much appreciated! :)

@jprotze
Copy link
Collaborator

jprotze commented Aug 21, 2025

git push --force-if-include ;)

@jplehr jplehr merged commit 7c1d246 into llvm:main Aug 22, 2025
9 checks passed
@mhalk mhalk deleted the mhalk/feat/openmp-omptest-lib-reland branch August 22, 2025 18:42

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

Choose a reason for hiding this comment

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

Why is this needed? Shouldn't this be covered on the PUBLIC target_include_directories on llvm_gtest?


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

Choose a reason for hiding this comment

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

Why is this needed? This looks very fishy.


# Link llvm_gtest as whole-archive to expose required symbols
set(GTEST_LINK_CMD "-Wl,--whole-archive" llvm_gtest
"-Wl,--no-whole-archive" LLVMSupport)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need this now that you're using the llvm_gtest target? None of the other places that use llvm_gtest require this. Why does this one?

@mgorny
Copy link
Member

mgorny commented Aug 26, 2025

I'm seeing build failures with this change, while using runtimes build:

FAILED: [code=1] openmp/tools/omptest/CMakeFiles/omptest.dir/src/InternalEvent.cpp.o 
/usr/lib/ccache/bin/aarch64-unknown-linux-gnu-g++ -DOPENMP_LIBOMPTEST_BUILD_STANDALONE -D_GLIBCXX_USE_CXX11_ABI=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Domptest_EXPORTS -I/var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/openmp/tools/omptest/include  -O2 -pipe -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wcast-qual -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -Wno-maybe-uninitialized -fno-semantic-interposition -fdata-sections -std=c++17 -fPIC -MD -MT openmp/tools/omptest/CMakeFiles/omptest.dir/src/InternalEvent.cpp.o -MF openmp/tools/omptest/CMakeFiles/omptest.dir/src/InternalEvent.cpp.o.d -o openmp/tools/omptest/CMakeFiles/omptest.dir/src/InternalEvent.cpp.o -c /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/openmp/tools/omptest/src/InternalEvent.cpp
In file included from /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/openmp/tools/omptest/include/InternalEvent.h:17,
                 from /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/openmp/tools/omptest/src/InternalEvent.cpp:14:
/var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/openmp/tools/omptest/include/InternalEventCommon.h:17:10: fatal error: omp-tools.h: No such file or directory
   17 | #include "omp-tools.h"
      |          ^~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

and similar.

Configured via:

cmake -C /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/runtimes_build-.arm64/gentoo_common_config.cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_ENABLE_RUNTIMES=openmp -DOPENMP_STANDALONE_BUILD=ON -DOPENMP_LIBDIR_SUFFIX=64 -DLIBOMP_USE_HWLOC=yes -DLIBOMP_OMPD_GDB_SUPPORT=yes -DLIBOMP_OMPT_SUPPORT=yes -DLIBOMP_INSTALL_ALIASES=OFF -DLIBOMP_COPY_EXPORTS=OFF -DOPENMP_LLVM_LIT_EXECUTABLE=/usr/bin/lit -DOPENMP_LIT_ARGS=-vv;-j;96 -DOPENMP_TEST_C_COMPILER=/usr/lib/ccache/bin/aarch64-unknown-linux-gnu-clang -DOPENMP_TEST_CXX_COMPILER=/usr/lib/ccache/bin/aarch64-unknown-linux-gnu-clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=/var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/runtimes_build-.arm64/gentoo_toolchain.cmake /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/runtimes

The file's present, so I guess it's a missing include directory:

# find /var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/runtimes_build-.arm64 -name omp-tools.h
/var/tmp/portage/llvm-runtimes/openmp-22.0.0.9999/work/runtimes_build-.arm64/openmp/runtime/src/omp-tools.h

@jprotze
Copy link
Collaborator

jprotze commented Aug 26, 2025

The other tools have this line in their CMake config:

  include_directories(${LIBOMP_INCLUDE_DIR})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openmp:libomp OpenMP host runtime openmp:libomptarget OpenMP offload runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants