Skip to content

Commit

Permalink
CMake: HIP_PATH from ROCM_PATH (AMReX-Codes#2948)
Browse files Browse the repository at this point in the history
* On machines like Crusher, `ROCM_PATH` is more likely to be available
then a `HIP_PATH` environment variable.

This is mainly needed for our hacky ROCTX hints.

* ROCTX: New Include

Supposedly, there is a new include we shall use:

Ref.:
ROCm/roctracer#79

* ROCtracer: Include as System library

Because of GNU extensions in the roctracer include files for the legacy include.
But we should make this `-isystem` anyway to be robust for the future.

The 5.2 deprecated include file `<roctracer_ext.h>` throws warnings
because they rely on GNU extensions:
```
In file included from /opt/rocm/hip/../roctracer/include/ext/prof_protocol.h:27:
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:70:7: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:70:7: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:75:7: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:82:7: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:86:7: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:90:7: warning: anonymous structs are a GNU extension [-Wgnu-anonymous-struct]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:82:7: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:86:7: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
      struct {
      ^
/opt/rocm/hip/../roctracer/include/ext/../../../include/roctracer/ext/prof_protocol.h:90:7: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
      struct {
      ^
```

* GNUmake: Update Includes in `hip.mak`

Use public prefix.
  • Loading branch information
ax3l authored Sep 14, 2022
1 parent 9aa23c2 commit 0351c99
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/hip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
-DAMReX_LINEAR_SOLVERS=ON \
-DAMReX_GPU_BACKEND=HIP \
-DAMReX_AMD_ARCH=gfx908 \
-DAMReX_ROCTX=ON \
-DCMAKE_C_COMPILER=$(which clang) \
-DCMAKE_CXX_COMPILER=$(which clang++) \
-DCMAKE_Fortran_COMPILER=$(which flang) \
Expand Down Expand Up @@ -91,6 +92,7 @@ jobs:
-DAMReX_LINEAR_SOLVERS=ON \
-DAMReX_GPU_BACKEND=HIP \
-DAMReX_AMD_ARCH=gfx908 \
-DAMReX_ROCTX=ON \
-DCMAKE_C_COMPILER=$(which clang) \
-DCMAKE_CXX_COMPILER=$(which hipcc) \
-DCMAKE_Fortran_COMPILER=$(which gfortran) \
Expand Down
4 changes: 2 additions & 2 deletions Src/Base/AMReX_GpuDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
#if defined(AMREX_USE_HIP)
#include <hip/hip_runtime.h>
#if defined(AMREX_USE_ROCTX)
#include <roctracer_ext.h>
#include <roctracer/roctracer_ext.h>
#if defined(AMREX_PROFILING) || defined (AMREX_TINY_PROFILING)
#include <roctx.h>
#include <roctracer/roctx.h>
#endif
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion Src/Base/AMReX_TinyProfiler.H
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#endif

#if defined(AMREX_USE_HIP) && defined(AMREX_USE_ROCTX)
#include <roctx.h>
#include <roctracer/roctx.h>
#endif

#include <deque>
Expand Down
20 changes: 14 additions & 6 deletions Tools/CMake/AMReXParallelBackends.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,12 @@ if (AMReX_HIP)
unset(_valid_hip_compilers)

if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
else()
if(DEFINED ENV{HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
elseif(DEFINED ENV{ROCM_PATH})
set(HIP_PATH "$ENV{ROCM_PATH}/hip" CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
endif()
endif()

Expand Down Expand Up @@ -255,9 +257,15 @@ if (AMReX_HIP)
if(AMReX_ROCTX)
# To be modernized in the future, please see:
# https://github.com/ROCm-Developer-Tools/roctracer/issues/56
target_include_directories(amrex PUBLIC ${HIP_PATH}/../roctracer/include ${HIP_PATH}/../rocprofiler/include)
target_link_libraries(amrex PUBLIC "-L${HIP_PATH}/../roctracer/lib/ -lroctracer64" "-L${HIP_PATH}/../roctracer/lib -lroctx64")
endif ()
target_include_directories(amrex SYSTEM PUBLIC
${HIP_PATH}/../roctracer/include
${HIP_PATH}/../rocprofiler/include
)
target_link_libraries(amrex PUBLIC
"-L${HIP_PATH}/../roctracer/lib -lroctracer64"
"-L${HIP_PATH}/../roctracer/lib -lroctx64"
)
endif()
target_link_libraries(amrex PUBLIC hip::hiprand roc::rocrand roc::rocprim)

# avoid forcing the rocm LLVM flags on a gfortran
Expand Down
13 changes: 6 additions & 7 deletions Tools/GNUMake/comps/hip.mak
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ifeq ($(HIP_COMPILER),clang)

# Generic HIP info
ROC_PATH=$(realpath $(dir $(HIP_PATH)))
SYSTEM_INCLUDE_LOCATIONS += $(HIP_PATH)/include
SYSTEM_INCLUDE_LOCATIONS += $(ROC_PATH)/include $(HIP_PATH)/include

# rocRand
SYSTEM_INCLUDE_LOCATIONS += $(ROC_PATH)/include/hiprand $(ROC_PATH)/include/rocrand
Expand All @@ -120,13 +120,12 @@ ifeq ($(HIP_COMPILER),clang)
# rocThrust - Header only
# SYSTEM_INCLUDE_LOCATIONS += $(ROC_PATH)/include/rocthrust

ifeq ($(USE_ROCTX),TRUE)
# rocTracer
CXXFLAGS += -DAMREX_USE_ROCTX
HIPCC_FLAGS += -DAMREX_USE_ROCTX
SYSTEM_INCLUDE_LOCATIONS += $(ROC_PATH)/include/roctracer $(ROC_PATH)/include/rocprofiler
LIBRARY_LOCATIONS += $(ROC_PATH)/lib
LIBRARIES += -lroctracer64 -lroctx64
ifeq ($(USE_ROCTX),TRUE)
CXXFLAGS += -DAMREX_USE_ROCTX
HIPCC_FLAGS += -DAMREX_USE_ROCTX
LIBRARY_LOCATIONS += $(ROC_PATH)/lib
LIBRARIES += -Wl,--rpath=$(ROC_PATH)/lib -lroctracer64 -lroctx64
endif

# hipcc passes a lot of unused arguments to clang
Expand Down

0 comments on commit 0351c99

Please sign in to comment.