-
Notifications
You must be signed in to change notification settings - Fork 520
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
Cmake hip module restrict to cxx #2280
Conversation
Previous to these any target that has mixed languages ( C++ && Fortran ) would break as the HIP specific flags such as '-x hip' would be past to the Fortran compiler.
Hi @tomsang, I created a reproducer for you under Simply build with:
The original error that you will see is:
|
I just went ahead, used an existing ROCm 4.1.0 install on OLCF Spock, copied and modified a local https://github.com/ax3l/hip_cxxf_cmake/tree/test-hipconfig This PR fixes the problem 🎉 |
Yes, this and all other changes in this PR need to be added. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for readying this up.
I appreciate it :)
hip-config.cmake.in
Outdated
set_property(TARGET hip::device APPEND PROPERTY | ||
INTERFACE_COMPILE_OPTIONS -xhip | ||
set_property(TARGET hip::device APPEND PROPERTY | ||
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:SHELL:-x hip>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did another test (replicating the logic elsewhere) and this line was causing trouble unless I wrote it as:
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:SHELL:-x hip>" | |
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:SHELL:-xhip>" |
With ... "-x hip" ...
:
clang-12: error: language not recognized: ' hip'
Seen on Spock with HIP 4.1.0
I am not sure why this flag is added in quotes on the command line, maybe that's also causing it. Anyway, removing the space solves it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if doing "$<$<COMPILE_LANGUAGE:CXX>:SHELL:-x> $<$<COMPILE_LANGUAGE:CXX>:SHELL:hip>"
would work as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe $<$<COMPILE_LANGUAGE:CXX>:SHELL:-x;hip>
like what is done for the other flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem in my test was, that I had both -xhip
and "-x hip"
on my command line. Not entirely sure where the ""
came from, I am playing if I can find a work around until the PR herein lands:
target_compile_options(amrex PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:SHELL:-mllvm;-amdgpu-early-inline-all=true;-mllvm;-amdgpu-function-calls=false;-xhip>
If I added ...;-x hip
my CLI looked like this: clang++ ... "-x hip" -xhip
. Without the space it worked. Probably related to list-handing in a SHELL
section.
AMReX-Codes/amrex#2031
$ clang++ -x hip
# ok
$ clang++ -xhip
# ok
$ clang++ "-x hip" -xhip
clang-12: error: language not recognized: ' hip'
$ clang++ "-x hip"
clang-12: error: language not recognized: ' hip'
$ clang++ -x hip
# ok
Anyway, I think that might just be from my work-around. The stand-alone test I did worked, as reported earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe
$<$ <COMPILE_LANGUAGE:CXX>:SHELL:-x;hip> like what is done for the other flags.
That might be a bit risky, the idea of SHELL is to keep options that belong together also in lists together. The list ;
would tokenize them and potentially shuffle them later on.
https://cmake.org/cmake/help/git-master/command/target_compile_options.html#option-de-duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I take this back, I think the current patch is ok. We should trust on @robertmaynard's expertise in CMake things :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thus I don't need update it .
@mangupta will help us merge in weekend or next monday
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. The problem was on my side, writing
target_compile_options(amrex PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:SHELL:-mllvm;-amdgpu-early-inline-all=true;-mllvm;-amdgpu-function-calls=false;-x hip>")
where I should have written
target_compile_options(amrex PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:SHELL:-mllvm;-amdgpu-early-inline-all=true;-mllvm;-amdgpu-function-calls=false>")
target_compile_options(amrex PUBLIC
"$<$<COMPILE_LANGUAGE:CXX>:SHELL:-x hip>")
Current diff in this PR is good to go :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, if HIP is recognized by cmake as a language, we just need to change COMPILE_LANGUAGE:CXX to COMPILE_LANGUAGE:HIP or add similar options for COMPILE_LANGUAGE:HIP.
No, this target is to use for CXX and switching it to COMPILE_LANGUAGE:HIP could break builds that do not have source files set to HIP language in cmake(such as .cpp files). For the HIP language, there is a hip-lang-config cmake file and corresponding hip-lang::device target: CMake will use this hip-lang-config file and hip-lang::device when using the HIP language. The reason its seperate is not only because it needs to apply the flags to a different language but also some of the flags are actually different. CMake will pass the So the |
The patch has been merged internally. Will be publicly released to github in Rocm4.4 . |
Thanks for the update, that's great! |
Yes, the merge-window for this bugfix for ROCm 4.3 is already closed. |
@ax3l After that patch is merged internally, we experienced building failure in some math libs.
|
I think its 3.13 because it relies on the set(_HIP_SHELL "SHELL:")
if(CMAKE_VERSION VERSION_LESS 3.13)
set(_HIP_SHELL "")
endif()
set_property(TARGET hip::device APPEND PROPERTY
INTERFACE_COMPILE_OPTIONS
"$<$<COMPILE_LANGUAGE:CXX>:${_HIP_SHELL}-mllvm;-amdgpu-early-inline-all=true;-mllvm;-amdgpu-function-calls=false>"
) I haven't tested this to know if this works. So we might need to only conditionally enabled the CXX restriction when using the newer cmake. |
Hi, the CXX restrictions and SHELL variable are two independent things. The SHELL prefix makes sure that - independent of the restriction to the proper language targets - CMake does not deduplicate your The CMake features in this PR by @robertmaynard (#2190), according to docs:
If you like to be backwards compatible, you can do the You could alternatively, like Intel oneAPI, build & ship a recent CMake package with the ROCm packages. Or document to install a recent CMake for older Ubuntus from Kitware's apt repo: https://apt.kitware.com |
Thus the minimum cmake version is 3.18.6 in terms of last comment . rocBlas tester just confirmed 3.20.2 can work. But I think it's too high. |
3.20 is whats in ubuntu 20.04, so if we want to bump the version we should just require ubuntu 20.04.
There is more than just rocblas. It would be best to fallback on the old way in older versions of cmake, and then use CXX, and SHELL: when the cmake version is greater than 3.18. This wont break any projects building with hip as most libraries just use whats in ubuntu. |
I think that's do-able. Note that personally, I would recommend to just bump your CMake requirement and document how to acquire CMake on older systems. Besides the apt-repos, there are tons of resources to quickly get a pre-compiled CMake binary for legacy systems (apt/ppa, conda, pip, Spack, conan, vcpkg, Nuget, Chocolatey, MSI packages, ZIP files, ...) and as a last resort can quickly be bootstrapped from source. If you want a look at other GPU vendor software products: Intel oneAPI and Nvidia RAPIDS ship the latest CMake to all platforms in order to move fast. CMake is a fully self-contained binary alongside text-based scripts. I would personally join the club and use recent releases, otherwise you will constantly have to maintain legacy work-arounds and bugs filed against them. |
After updating cmake to 3.18.6 we still experience failures in a few mathlibs projects which cannot deal with something like "$<LINK_LANGUAGE:CXX>" and "SHELL:" . I will have to rework patch to be backward compatible. |
I've updated the PR to check cmake version for SHELL and LINK_LANGUAGE. |
@ax3l could you verify whether the new update can still work for your projects? |
Thanks for the ping! Visually, the patch looks good to me. I am a bit busy with deadlines right now, please feel free to test with the self-contained reproducer here:
That's curious, which exact syntax did not work? |
@tomsang just to confirm. I now used my example in https://github.com/ax3l/hip_cxxf_cmake, patched my local ROCm 4.2.0 install with the latest state of this PR, and can confirm that with CMake 3.20.5 the demonstrator now compiles. (And it fails with e.g., CMake 3.16 as we patch out the fixes.) Do you want to add the test I linked maybe to your integration tests, so we can be sure multi-language CMake projects will continue to build with HIP targets included? Any news on potentially shipping a CMake package with your ROCm packages (as Intel oneAPI and NVIDIA RAPIDS do as well)? |
This feature will be available in Rocm4.4. But the change is in another format in order to fix mathlib build issues. |
LINK_LANGUAGE has issue in CMake version from 3.18.0 to 3.19.8 when complex lib dependence exists. This PR failed building if(CMAKE_VERSION VERSION_LESS 3.20) |
Close it as the file was removed and another PR in a new project(hipamd) has been merged for the same purpose. |
It looks to me that at least the missing I see issues with that using ROCm 4.5.2 for CXX targets, I fear. Migrated issue to ROCm/hipamd#12 |
## Summary By now (HIP 4.5), we should be able to link also against Fortran targets. Let's remove work-arounds and ditch old HIP releases, so improve maintainability and avoid surprises. ## Additional background X-ref: - ROCm/HIP#2280 (ROCm/HIP#2190) - ROCm/HIP#2275
Fix path issue in #2190