Skip to content
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

Merged
merged 12 commits into from
Mar 18, 2021
Merged

Conversation

dalg24
Copy link
Member

@dalg24 dalg24 commented Mar 11, 2021

CC: @abbotts @AdamLavely-Cray

They are a few issues we need to discuss:

cmake/kokkos_arch.cmake Outdated Show resolved Hide resolved
cmake/kokkos_arch.cmake Outdated Show resolved Hide resolved
@dalg24 dalg24 requested a review from Rombur March 11, 2021 17:30
@dalg24
Copy link
Member Author

dalg24 commented Mar 12, 2021

Note that I configured with

        "CMAKE_EXE_LINKER_FLAGS": "-lamdhip64 -lhsa-runtime64 -L$env{ROCM_PATH}/lib",
        "CMAKE_SHARED_LINKER_FLAGS": "-lamdhip64 -lhsa-runtime64 -L$env{ROCM_PATH}/lib",

so we probably should find the library and handle this from CMake.

Copy link
Contributor

@jrmadsen jrmadsen left a 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).

ELSE()
SET(AMDGPU_ARCH_FLAG "--offload-arch")
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS -x hip)
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS --rocm-path=$ENV{ROCM_PATH})
Copy link
Contributor

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.

Copy link

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.

Comment on lines 153 to 159
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()
Copy link
Contributor

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?

ELSE()
SET(AMDGPU_ARCH_FLAG "--offload-arch")
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS -x hip)
GLOBAL_APPEND(KOKKOS_AMDGPU_OPTIONS --rocm-path=$ENV{ROCM_PATH})
Copy link

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.

@@ -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})
Copy link

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)
Copy link

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?

Copy link
Member Author

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.

@Rombur
Copy link
Member

Rombur commented Mar 16, 2021

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.

@dalg24
Copy link
Member Author

dalg24 commented Mar 16, 2021

it turns out find_package(hip) is broken For ROCm 3.8->4.0


kokkos_create_imported_tpl(ROCM INTERFACE
LINK_LIBRARIES ${HSA_RUNTIME_LIBRARY} ${AMD_HIP_LIBRARY}
COMPILE_OPTIONS -D__HIP_ROCclr__
Copy link
Member

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?

Copy link
Member Author

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

CMAKE_PARSE_ARGUMENTS(TPL
"INTERFACE"
"LIBRARY"
"LINK_LIBRARIES;INCLUDES;COMPILE_OPTIONS;LINK_OPTIONS"
${ARGN})

@dalg24 dalg24 marked this pull request as ready for review March 17, 2021 15:12
Copy link

@jjwilke jjwilke left a 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.

@dalg24
Copy link
Member Author

dalg24 commented Mar 18, 2021

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

@dalg24 dalg24 merged commit f0c7101 into kokkos:develop Mar 18, 2021
@dalg24 dalg24 deleted the hip_support_cray_clang branch March 18, 2021 01:07
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.

None yet

5 participants