-
Notifications
You must be signed in to change notification settings - Fork 407
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
Enable HIP with Cray Clang #3842
Conversation
Note that I configured with
so we probably should find the library and handle this from CMake. |
eb9f5d1
to
5c422be
Compare
a6a0cff
to
07a643e
Compare
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 main change I would like to see is w.r.t. --rocm-path=$ENV{ROCM_PATH}
. We should at least check that is defined in the env. Optionally, we could also allow the user to specify it on the command-line and fallback to the env variable (if that would work with the toolchain).
cmake/kokkos_arch.cmake
Outdated
ELSE() | ||
SET(AMDGPU_ARCH_FLAG "--offload-arch") | ||
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS -x hip) | ||
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS --rocm-path=$ENV{ROCM_PATH}) |
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 don't really like relying on environment variables this explicitly. This would cause weird compiler issues if this variable isn't set.
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.
Agreed with @jrmadsen. Referencing the comment below, I think it makes sense to have a FindROCM.cmake file that resolves all these paths. ROCM_PATH would then be a variable.
cmake/kokkos_arch.cmake
Outdated
FIND_LIBRARY(LIB_AMD_HIP amdhip64 PATHS ENV ROCM_PATH PATH_SUFFIXES lib) | ||
FIND_LIBRARY(LIB_HSA_RUNTIME hsa-runtime64 PATHS ENV ROCM_PATH PATH_SUFFIXES lib) | ||
MESSAGE(STATUS "Found libamdhip64: ${LIB_AMD_HIP}") | ||
MESSAGE(STATUS "Found libhsa-runtime: ${LIB_HSA_RUNTIME}") | ||
IF(NOT LIB_AMD_HIP OR NOT LIB_HSA_RUNTIME) | ||
MESSAGE(FATAL_ERROR "Could not find AMD HIP and/or HSA Runtime library(ies)") | ||
ENDIF() |
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 (personally) don't like replicating a find_package
in-place. I think it complicates the flow of our CMake. Can we move this to stuff to a local cmake/Modules/FindAMDGPU.cmake
script?
cmake/kokkos_arch.cmake
Outdated
ELSE() | ||
SET(AMDGPU_ARCH_FLAG "--offload-arch") | ||
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS -x hip) | ||
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS --rocm-path=$ENV{ROCM_PATH}) |
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.
Agreed with @jrmadsen. Referencing the comment below, I think it makes sense to have a FindROCM.cmake file that resolves all these paths. ROCM_PATH would then be a variable.
cmake/kokkos_arch.cmake
Outdated
@@ -414,6 +433,8 @@ FUNCTION(CHECK_AMDGPU_ARCH ARCH FLAG) | |||
IF(KOKKOS_ENABLE_HIP_RELOCATABLE_DEVICE_CODE) | |||
GLOBAL_APPEND(KOKKOS_LINK_OPTIONS "${AMDGPU_ARCH_FLAG}=${FLAG}") | |||
ENDIF() | |||
#GLOBAL_APPEND(KOKKOS_LINK_OPTIONS -lamdhip64 -lhsa-runtime64 -L${LIB_AMD_HIP_DIR}) | |||
GLOBAL_APPEND(KOKKOS_LINK_OPTIONS ${LIB_HSA_RUNTIME} ${LIB_AMD_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.
Continuing with the find module approach, Kokkos is structured around defining imported or interface targets (e.g. Kokkos::ROCM) that would have an INTERFACE_LINK_LIBRARIES=amdhip64 hsa-runtime64
and you would have a target_link_libraries(kokkoscore PUBLIC Kokkos::ROCM)
@@ -153,7 +157,7 @@ ELSEIF(KOKKOS_CXX_COMPILER_ID STREQUAL NVIDIA) | |||
MESSAGE(FATAL_ERROR "${KOKKOS_MESSAGE_TEXT}") | |||
ENDIF() | |||
SET(CMAKE_CXX_EXTENSIONS OFF CACHE BOOL "Kokkos turns off CXX extensions" FORCE) | |||
ELSEIF(KOKKOS_CXX_COMPILER_ID STREQUAL HIP) | |||
ELSEIF(KOKKOS_CXX_COMPILER_ID STREQUAL HIPCC) |
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.
Any reason for the change from HIP
to HIPCC
?
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.
Because effectively this tells whether hipcc is being used as the compiler. "hip" does not designate any compiler.
This PR does not work for me. Depending on the version of HIP I am using I get different errors either at configuration time or at compile time. |
it turns out |
|
||
kokkos_create_imported_tpl(ROCM INTERFACE | ||
LINK_LIBRARIES ${HSA_RUNTIME_LIBRARY} ${AMD_HIP_LIBRARY} | ||
COMPILE_OPTIONS -D__HIP_ROCclr__ |
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.
Shouldn't this be a COMPILE_DEFINITIONS
?
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.
Yes you are right for classic cmake but kokkos_create_imported_tpl
does not currently support it probably because target_compile_definitions
was only added in 3.11
kokkos/cmake/kokkos_functions.cmake
Lines 310 to 314 in 233fc53
CMAKE_PARSE_ARGUMENTS(TPL | |
"INTERFACE" | |
"LIBRARY" | |
"LINK_LIBRARIES;INCLUDES;COMPILE_OPTIONS;LINK_OPTIONS" | |
${ARGN}) |
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'm not able to test, but looks good to me. It would be nice to add the compile definitions to the TPL system correctly... but I guess not necessary.
Will implement in a follow up PR |
CC: @abbotts @AdamLavely-Cray
They are a few issues we need to discuss:
Duplicated logic to detect Cray Clang innow detectingkokkos_compiler_id.cmake
hipcc
and not distinguishing Cray Clang from vanilla LLVMhttps://github.com/dalg24/kokkos/blob/e0f332456a93a89e9c9a2105cf9b0719f0bf9118/cmake/kokkos_compiler_id.cmake#L91-L99Minimum versions requirementshttps://github.com/dalg24/kokkos/blob/e0f332456a93a89e9c9a2105cf9b0719f0bf9118/cmake/kokkos_compiler_id.cmake#L163-L166HIP offload target architecture flagShould we be using--offload-arch=...
?Logic to getrelying onROCM_PATH
find_package(hip)
to get ithttps://github.com/dalg24/kokkos/blob/e0f332456a93a89e9c9a2105cf9b0719f0bf9118/cmake/kokkos_arch.cmake#L117-L119