Skip to content

Build fails for openmp #159

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

Closed
almishra opened this issue Feb 29, 2020 · 11 comments
Closed

Build fails for openmp #159

almishra opened this issue Feb 29, 2020 · 11 comments
Labels
build-problem cmake Build system in general and CMake in particular openmp question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@almishra
Copy link

When trying to build openmp I'm getting the following error:

[ 42%] Building CXX object libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o
/gpfs/projects/ChapmanGroup/alok/git/llvm-project-build/openmp/libomptarget/plugins/cuda/src/rtl.cpp:262:18: error: no member named 'make_unique' in namespace 'std'
      Ptr = std::make_unique<std::atomic_uint>(0);
            ~~~~~^
/gpfs/projects/ChapmanGroup/alok/git/llvm-project-build/openmp/libomptarget/plugins/cuda/src/rtl.cpp:262:46: error: expected '(' for function-style cast or type construction
      Ptr = std::make_unique<std::atomic_uint>(0);
                             ~~~~~~~~~~~~~~~~^
2 errors generated.
make[2]: *** [libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o] Error 1
make[1]: *** [libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/all] Error 2
make: *** [all] Error 2

I never faced this issue till a couple of weeks back.
I always build my llvm with clang first and then use the clang to build openmp with offloading support.

To build llvm/clang:

cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DCLANG_BUILD_EXAMPLES=1 -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLLVM_TARGETS_TO_BUILD="X86;NVPTX" $LLVM_SRC/llvm
make -j16
make install

To build openmp:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LLVM_PATH -DCMAKE_C_COMPILER=$LLVM_PATH/bin/clang -DCMAKE_CXX_COMPILER=$LLVM_PATH/bin/clang++ -DLIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=35,60,70 $LLVM_SRC/openmp
make -j16
make install

My gcc version is 6.5.0

$ gcc --version
gcc (GCC) 6.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@JonChesterfield
Copy link
Collaborator

JonChesterfield commented Feb 29, 2020

Stale cmake files? They should be setting C++ 14 as of a couple of weeks ago

edit: though I can't find where we set the c++ version for the plugins (not currently at a desk) so it maybe we're just using the default, which is 11 and won't work any more. If so you can work around by specifying c++14

@almishra
Copy link
Author

I see that patch - 3ff4e2e

And I am still able to build openmp if I checkout the commit before this patch.

@almishra
Copy link
Author

I have tried passing c++14 as option to cmake. It didn't work

-DCMAKE_CXX_FLAGS="-std=c++14"

I get the same error.

@shiltian
Copy link
Contributor

Finally I can reproduced it now, but I didn’t find anything wrong in the dry run:

$ make -n
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build && /gpfs/software/cmake-3.16.2/bin/cmake -S/gpfs/scratch/shiltian/Documents/llvm-project/openmp -B/gpfs/scratch/shiltian/Documents/llvm-project/openmp/build --check-build-system CMakeFiles/Makefile.cmake 0
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build && /gpfs/software/cmake-3.16.2/bin/cmake -E cmake_progress_start /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/CMakeFiles /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda/CMakeFiles/progress.marks
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build && make -f CMakeFiles/Makefile2 libomptarget/plugins/cuda/all
make -f libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/build.make libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/depend
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build && /gpfs/software/cmake-3.16.2/bin/cmake -E cmake_depends "Unix Makefiles" /gpfs/scratch/shiltian/Documents/llvm-project/openmp /gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/plugins/cuda /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/DependInfo.cmake --color=
make -f libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/build.make libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/build
/gpfs/software/cmake-3.16.2/bin/cmake -E cmake_echo_color --switch= --green --progress-dir=/gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/CMakeFiles --progress-num=79 "Building CXX object libomptarget/plugins/cuda/CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o"
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda && /gpfs/scratch/shiltian/Documents/llvm-project/build/bin/clang++  -DTARGET_NAME=CUDA -Domptarget_rtl_cuda_EXPORTS -I/gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/include -I/gpfs/software/cuda/10.0/include  -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -std=gnu++14 -O3 -DNDEBUG -fPIC   -o CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o -c /gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/plugins/cuda/src/rtl.cpp
/gpfs/software/cmake-3.16.2/bin/cmake -E cmake_echo_color --switch= --green --bold --progress-dir=/gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/CMakeFiles --progress-num=80 "Linking CXX shared library ../../libomptarget.rtl.cuda.so"
cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda && /gpfs/software/cmake-3.16.2/bin/cmake -E cmake_link_script CMakeFiles/omptarget.rtl.cuda.dir/link.txt --verbose=
/gpfs/software/cmake-3.16.2/bin/cmake -E cmake_echo_color --switch= --progress-dir=/gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/CMakeFiles --progress-num=79,80 "Built target omptarget.rtl.cuda"
/gpfs/software/cmake-3.16.2/bin/cmake -E cmake_progress_start /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/CMakeFiles 0

As you can see -std=gnu++14 has already there, so it is of course no use to append it yourself. I’ll try to figure out what is wrong on this system.

@shiltian
Copy link
Contributor

I have root cause the issue, if you append --gcc-toolchain=/gpfs/software/gcc/6.5.0, problem solved. The reason is clang by default will use system provided gcc, even if another gcc has already been in PATH, etc. If you try to print the compilation command appending -###, you can see:

-bash-4.2$ cd /gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda && /gpfs/scratch/shiltian/Documents/llvm-project/build/bin/clang++  -DTARGET_NAME=CUDA -Domptarget_rtl_cuda_EXPORTS -I/gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/include -I/gpfs/software/cuda/10.0/include  -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -std=gnu++14 -O3 -DNDEBUG -fPIC   -o CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o -c /gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/plugins/cuda/src/rtl.cpp -###
clang version 11.0.0 ([email protected]:llvm/llvm-project.git 4fa63fd4524c9818dab2fc0d3ea3a8d65d3bc22b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gpfs/scratch/shiltian/Documents/llvm-project/build/bin
 (in-process)
 "/gpfs/scratch/shiltian/Documents/llvm-project/build/bin/clang-11" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "rtl.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mframe-pointer=none" "-fmath-errno" "-fdenormal-fp-math=ieee,ieee" "-fdenormal-fp-math-f32=ieee,ieee" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info" "-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir" "/gpfs/scratch/shiltian/Documents/llvm-project/build/lib/clang/11.0.0" "-D" "TARGET_NAME=CUDA" "-D" "omptarget_rtl_cuda_EXPORTS" "-I" "/gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/include" "-I" "/gpfs/software/cuda/10.0/include" "-D" "NDEBUG" "-I/cm/shared/apps/cuda100/sdk/10.0/common/inc" "-I/gpfs/software/cuda/10.0/include" "-I/gpfs/software/cmake-3.16.2/share/cmake-3.16.2/include" "-I/gpfs/software/gcc/6.5.0/include" "-c-isystem" "/gpfs/software/cmake-3.16.2/share/cmake-3.16.2/include" "-c-isystem" "/gpfs/software/gcc/6.5.0/include" "-cxx-isystem" "/gpfs/software/cmake-3.16.2/share/cmake-3.16.2/include" "-cxx-isystem" "/gpfs/software/gcc/6.5.0/include" "-objc-isystem" "/gpfs/software/cmake-3.16.2/share/cmake-3.16.2/include" "-objc-isystem" "/gpfs/software/gcc/6.5.0/include" "-internal-isystem" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5" "-internal-isystem" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux" "-internal-isystem" "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/gpfs/scratch/shiltian/Documents/llvm-project/build/lib/clang/11.0.0/include" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-Wall" "-Wcast-qual" "-Wformat-pedantic" "-Wimplicit-fallthrough" "-Wsign-compare" "-Wno-extra" "-Wno-pedantic" "-std=gnu++14" "-fdeprecated-macro" "-fdebug-compilation-dir" "/gpfs/scratch/shiltian/Documents/llvm-project/openmp/build/libomptarget/plugins/cuda" "-ferror-limit" "19" "-fmessage-length" "0" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-faddrsig" "-o" "CMakeFiles/omptarget.rtl.cuda.dir/src/rtl.cpp.o" "-x" "c++" "/gpfs/scratch/shiltian/Documents/llvm-project/openmp/libomptarget/plugins/cuda/src/rtl.cpp"

Still using head files from system which is 4.8.5. GCC 4.8.5 has partially support for C++14 so that’s why that function is not found.

@almishra
Copy link
Author

And how to set this option in cmake?

@shiltian
Copy link
Contributor

Try CMAKE_<LANG>_COMPILER_EXTERNAL_TOOLCHAIN.

@almishra
Copy link
Author

This worked. Thanks Shilei for the help.

@almishra
Copy link
Author

I still don't understand one thing. Why does clang use system provided gcc, even if we specified our own compiler with the CMAKE_CXX_COMPILER option?

@shiltian
Copy link
Contributor

That is different stories. CMAKE_<LANG>_COMPILER is telling CMake to use specific compiler. In your case, you want to use clang. You did right for this "story". Another story is only for clang, has nothing to do with CMake. Clang doesn't provide every C/C++ header, and it should not actually. Then it must use system provided one. The search path for system headers is hard coded into clang if you do not specify GCC toolchain. module only sets PATH, LIBRARY_PATH, C_INCLUDE_PATH, etc. It doesn't affect how clang searches for system headers actually.

@RKSimon RKSimon added cmake Build system in general and CMake in particular openmp build-problem labels Apr 12, 2022
@llvmbot
Copy link
Member

llvmbot commented Apr 12, 2022

@llvm/issue-subscribers-openmp

@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Apr 12, 2022
mjklemm pushed a commit to mjklemm/llvm-project that referenced this issue Oct 1, 2024
…duction clauses to generate info. (llvm#159)

* Move teams reductions from distribute to teams and use the reduction clause
for the teams directive to create the reduction information.
* Remove composite matching framework since this is no longer needed with the new
teams reduction implementation.
jpinot pushed a commit to jpinot/llvm-project that referenced this issue Apr 9, 2025
Here is a description of the implementation.

Clang:

Taskiter (for) is modeled as a loop directive, like
taskloop.

Taskiter (while) is more permissive, allowing any C/C++
condition in the while loop. This includes lambdas and
condition using pointers.

The loop iterator is firstprivate instead of private.
Because in the llvm transform is needed.

- Unroll clause is an integer > 0

NOTE: At this time the loop iterator is not usable in
taskiter (for) clauses.

NOTE: At this time while condition used variables
are not specially handled to make them shared variables

NOTE: There is no support for stride() clause yet.
Its implementation is the same as unroll clause

LLVM:

Taskiter is lowered in the unpack function as a simple
body without the loop. In particular, taskiter (for)
includes the body and emits the code to increment the iterator.
In taskiter (while) only the body is emitted.

The reason is because the runtime will have the amount of
iterations to execute (for version), or a task_info field
with the function that evaluates the condition.

NOTE: In contrast to Clang, Taskiter is NOT a loop directive
because the lowering in the unpack function differs.

Special rebase notes:

  Remove apparently unused code to clear OSSLateParsedToks

  In 35ff500 removing this code results in the test error.
  I add the test to keep track we do not introduce the bug again.

Reference llvm#159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-problem cmake Build system in general and CMake in particular openmp question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

6 participants