Skip to content

Use HIP as language in CMake#3646

Merged
ye-luo merged 23 commits into
QMCPACK:developfrom
quantumsteve:cmake_hip_language
Dec 1, 2022
Merged

Use HIP as language in CMake#3646
ye-luo merged 23 commits into
QMCPACK:developfrom
quantumsteve:cmake_hip_language

Conversation

@quantumsteve

Copy link
Copy Markdown
Contributor

Please review the developer documentation
on the wiki of this project that contains help and requirements.

Proposed changes

Describe what this PR changes and why. If it closes an issue, link to it here
with a supported keyword.

Fixes #3581

What type(s) of changes does this code introduce?

Delete the items that do not apply

  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes

Does this introduce a breaking change?

  • Yes (requires CMake 3.21 or later)

What systems has this change been tested on?

Checklist

Update the following with a yes where the items apply. If you're unsure about any of them, don't hesitate to ask. This is
simply a reminder of what we are going to look for before merging your code.

  • Yes. This PR is up to date with current the current state of 'develop'
  • No. Documentation has been added (if appropriate)

Signed-off-by: Steven Hahn <hahnse@ornl.gov>
Signed-off-by: Steven Hahn <hahnse@ornl.gov>
Signed-off-by: Steven Hahn <hahnse@ornl.gov>
@quantumsteve
quantumsteve requested a review from ye-luo December 8, 2021 20:41
@qmc-robot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@quantumsteve

Copy link
Copy Markdown
Contributor Author

@ye-luo I'm getting the following warnings when building and suspect it's related to CMAKE_HIP_ARCHITECTURES.

clang-13: warning: argument unused during compilation: '--offload-arch=gfx906' [-Wunused-command-line-argument]
clang-13: warning: argument unused during compilation: '--offload-arch=gfx908' [-Wunused-command-line-argument]

@prckent

prckent commented Dec 8, 2021

Copy link
Copy Markdown
Contributor

Is this OK on spock?

@ye-luo

ye-luo commented Dec 8, 2021

Copy link
Copy Markdown
Contributor

@quantumsteve could you paste your cmake line here? I mean on a regular workstation not spock.

I got a strange error

cmake -DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ -DQMC_MPI=0 -DENABLE_CUDA=ON -DQMC_CUDA2HIP=ON ..
...
-- Check for working HIP compiler: /opt/rocm-4.5.0/llvm/bin/clang++
-- Check for working HIP compiler: /opt/rocm-4.5.0/llvm/bin/clang++ - broken
CMake Error at /home/packages/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.3.0/cmake-3.21.4-t47xgwhz7ql3mvemzhzc7zwsrly6na3s/share/cmake-3.21/Modules/CMakeTestHIPCompiler.cmake:65 (message):
  The HIP compiler

    "/opt/rocm-4.5.0/llvm/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/yeluo/opt/cleanup/qmcpack/build_R7_aompbuild_offload_cuda2hip_real_check/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make -f Makefile cmTC_90a18/fast && /usr/bin/make  -f CMakeFiles/cmTC_90a18.dir/build.make CMakeFiles/cmTC_90a18.dir/build
    make[1]: Entering directory '/home/yeluo/opt/cleanup/qmcpack/build_R7_aompbuild_offload_cuda2hip_real_check/CMakeFiles/CMakeTmp'
    Building HIP object CMakeFiles/cmTC_90a18.dir/testHIPCompiler.hip.o
    /opt/rocm-4.5.0/llvm/bin/clang++ -D__HIP_ROCclr__=1 -I/opt/rocm-4.5.0/hip/include -I/opt/rocm-4.5.0/include -isystem /opt/rocm-4.5.0/hip/../include -isystem /opt/rocm-4.5.0/llvm/lib/clang/13.0.0 -fopenmp--cuda-host-only  --offload-arch=gfx906 -mllvm -amdgpu-early-inline-all=true -mllvm -amdgpu-function-calls=false -o CMakeFiles/cmTC_90a18.dir/testHIPCompiler.hip.o -x hip -c /home/yeluo/opt/cleanup/qmcpack/build_R7_aompbuild_offload_cuda2hip_real_check/CMakeFiles/CMakeTmp/testHIPCompiler.hip
    clang-13: error: unknown argument: '-fopenmp--cuda-host-only'
    make[1]: *** [CMakeFiles/cmTC_90a18.dir/build.make:78: CMakeFiles/cmTC_90a18.dir/testHIPCompiler.hip.o] Error 1
    make[1]: Leaving directory '/home/yeluo/opt/cleanup/qmcpack/build_R7_aompbuild_offload_cuda2hip_real_check/CMakeFiles/CMakeTmp'
    make: *** [Makefile:127: cmTC_90a18/fast] Error 2

no idea where -fopenmp--cuda-host-only si from

@quantumsteve

Copy link
Copy Markdown
Contributor Author

@ye-luo I had some trouble getting the spacing right between arguments in CMAKE_HIP_FLAGS. Expect it should be -fopenmp --cuda-host-only

Signed-off-by: Steven Hahn <hahnse@ornl.gov>
@quantumsteve

Copy link
Copy Markdown
Contributor Author

Last commit fixes that issue on Nitrogen. @prckent I haven't tried building on spock.

Using the same cmake configuration as GitHub Actions:

cmake -GNinja -DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ -DQMC_MPI=0 -DENABLE_CUDA=ON -DQMC_CUDA2HIP=ON -DCMAKE_PREFIX_PATH=/opt/OpenBLAS/0.3.18 -DQMC_COMPLEX=0 -DQMC_MIXED_PRECISION=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..

Comment thread CMakeLists.txt Outdated
Signed-off-by: Steven Hahn <hahnse@ornl.gov>
@mdewing

mdewing commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

I'm getting some linking errors

ld.lld: error: undefined symbol: __tgt_target_data_update_mapper
>>> referenced by test_ompBLAS.cpp
>>>               CMakeFiles/test_omptarget_blas.dir/test_ompBLAS.cpp.o:(void qmcplusplus::test_gemv<float>(int, int, char))

This is on my desktop machine with the aomp 14.0 compiler and rocm 4.5.0. I did compile the aomp offload version successfully a few weeks ago.

Comment thread CMake/ClangCompilers.cmake Outdated
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
if(ENABLE_ROCM)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@markdewing Does adding another variable to this check fix the linking error your experiencing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had offload enabled. If I disable that, then it works.

@mdewing

mdewing commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

Nevermind ... I was confused about what this support was for. It's not for the offload version.

@ye-luo

ye-luo commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

Had no luck with gcc

cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DENABLE_CUDA=ON -DQMC_CUDA2HIP=ON -DQMC_MPI=OFF ..

it tries to link programs with clang instead of gcc.
Got messages like

[100%] Linking HIP executable test_CUDA

which is expected host code.

@quantumsteve

Copy link
Copy Markdown
Contributor Author

Had no luck with gcc

cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DENABLE_CUDA=ON -DQMC_CUDA2HIP=ON -DQMC_MPI=OFF ..

it tries to link programs with clang instead of gcc. Got messages like

[100%] Linking HIP executable test_CUDA

which is expected host code.

This test comment seems to suggest that the link language for mixed targets should always be HIP 😕
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Tests/HIP/MixedLanguage/CMakeLists.txt

@ye-luo

ye-luo commented Dec 10, 2021

Copy link
Copy Markdown
Contributor

HIP is only part of the program. Having HIP compiler (and its flags) to take over linking is just so wrong.

@quantumsteve

quantumsteve commented Dec 10, 2021

Copy link
Copy Markdown
Contributor Author

HIP is only part of the program. Having HIP compiler (and its flags) to take over linking is just so wrong.

HIP, CXX, and CUDA have values of 90, 30, and 15.
https://gitlab.kitware.com/cmake/cmake/-/blob/a6fa3fa136c291c36aefbc79b62995a63bf9107b/Modules/CMakeHIPCompiler.cmake.in#L27

@ye-luo
ye-luo marked this pull request as draft December 11, 2021 19:52
@ye-luo

ye-luo commented Dec 11, 2021

Copy link
Copy Markdown
Contributor

Unfortunately, I found the current ROCm 4.5 release is bad in many ways for adopting HIP as a language. I have to park this PR for the moment. ROCm/ROCm#1259 (comment)

@quantumsteve

Copy link
Copy Markdown
Contributor Author

@ye-luo Thank you for reviewing this. I'll move onto other issues while we wait for a more usable ROCm release.

@PDoakORNL

Copy link
Copy Markdown
Contributor

temporarily close or mark this [WIP] it's clutter up the PR list.

@quantumsteve quantumsteve changed the title Use HIP as language in CMake [WIP] Use HIP as language in CMake Dec 17, 2021
@ye-luo
ye-luo force-pushed the cmake_hip_language branch from 151536b to ef7b5ad Compare November 19, 2022 04:23
@ye-luo

ye-luo commented Nov 28, 2022

Copy link
Copy Markdown
Contributor

Test this please

@ye-luo

ye-luo commented Nov 28, 2022

Copy link
Copy Markdown
Contributor

Test this please

@ye-luo
ye-luo force-pushed the cmake_hip_language branch from 885eaac to 560d34b Compare November 28, 2022 21:59
@ye-luo

ye-luo commented Nov 28, 2022

Copy link
Copy Markdown
Contributor

Test this please

@ye-luo ye-luo changed the title [WIP] Use HIP as language in CMake Use HIP as language in CMake Nov 28, 2022
@ye-luo
ye-luo marked this pull request as ready for review November 28, 2022 22:09
@ye-luo

ye-luo commented Nov 28, 2022

Copy link
Copy Markdown
Contributor

@quantumsteve @markdewing I think it is good now. We can use HIP as a cmake language. Since I did many changes. I should not approval my own changes. So please do another round of review.

@ye-luo

ye-luo commented Nov 29, 2022

Copy link
Copy Markdown
Contributor

@prckent please review the documentation update. crusher recipe has been updated to use rocm 5.3.0

@ye-luo
ye-luo requested a review from prckent November 29, 2022 20:52
@ye-luo
ye-luo force-pushed the cmake_hip_language branch from 8cdfad5 to 34ad46e Compare November 29, 2022 20:55
Comment thread CMakeLists.txt
Comment thread tests/test_automation/nightly_test_scripts/nightly_ornl.sh
@quantumsteve

Copy link
Copy Markdown
Contributor Author

@quantumsteve @markdewing I think it is good now. We can use HIP as a cmake language. Since I did many changes. I should not approval my own changes. So please do another round of review.

LGTM, though GitHub won't let me approve a PR I'm the original author of.

@ye-luo

ye-luo commented Nov 30, 2022

Copy link
Copy Markdown
Contributor

Confirmed good with rocm 5.4.0 as well.

@ye-luo

ye-luo commented Nov 30, 2022

Copy link
Copy Markdown
Contributor

Test this please

@ye-luo
ye-luo enabled auto-merge November 30, 2022 23:14
@ye-luo
ye-luo merged commit 787b5ca into QMCPACK:develop Dec 1, 2022
@quantumsteve
quantumsteve deleted the cmake_hip_language branch December 1, 2022 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use HIP as language in CMake

6 participants