Skip to content

Commit 36d61f9

Browse files
authored
Reenable HIP support (#250)
* Add hip support * Add security when both Cuda and hip are selected
1 parent 270d566 commit 36d61f9

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

cmake/CheckOptions.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ if(USE_KOKKOS AND USE_VECTOR)
33
message(FATAL_ERROR "Both Vector and Kokkos array implementations selected. Please only select one.")
44
endif()
55

6+
7+
if(ENABLE_CUDA AND ENABLE_HIP)
8+
message(FATAL_ERROR "Both Cudo and Hip programming model are selected. Please only select one.")
9+
endif()
10+
611
# Set default if neither is selected
712
if(NOT USE_KOKKOS AND NOT USE_VECTOR)
813
message(WARNING "No array implementation selected. Vector implementation chosen as default.")
914
set(USE_VECTOR TRUE CACHE BOOL "Use Vector array implementation" FORCE)
1015
endif()
16+

cmake/KokkosConfig.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ else()
2525
message(STATUS "Activating CUDA with Kokkos.")
2626
endif()
2727

28+
if(ENABLE_HIP)
29+
set(Kokkos_ENABLE_HIP ON CACHE BOOL "" FORCE)
30+
set(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE OFF CACHE BOOL "" FORCE)
31+
message(STATUS "Activating HIP with Kokkos.")
32+
endif()
33+
34+
2835
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
2936
message(STATUS "Activating Kokkos debug mode")
3037
set(Kokkos_ENABLE_DEBUG ON CACHE BOOL "" FORCE)

cmake/ProxyConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option(USE_VECTOR "Use vectors." OFF)
1111
option(USE_KOKKOS "Use KOKKOS to parallelise loops" OFF)
1212
option(USE_KOKKOS_TEAMS "use hierarchical parallelism in Kokkos" OFF)
1313
option(ENABLE_CUDA "Enable cuda compilation" OFF)
14+
option(ENABLE_HIP "Enable hip compilation" OFF)
1415

1516
# Python wrapping
1617
option(ENABLE_PYWRAP "Enable python binding compilation with pybind11" OFF)

src/solver/fe/impl/common/include/sem_solver_impl.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
493493
model_discretization_interface::gatherTransformData(elementNumber, mesh_local,
494494
transformData);
495495

496-
#ifdef __CUDACC__
496+
#if defined(__CUDACC__) || defined(__HIPCC__)
497+
497498
struct CJPacked
498499
{
499500
float4 a;
@@ -554,7 +555,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
554555
float const v4 = lambda * Jp0 * Jr2 + mu * Jp2 * Jr0;
555556
float const v5 = lambda * Jp1 * Jr2 + mu * Jp2 * Jr1;
556557

557-
#ifdef __CUDACC__
558+
#if defined(__CUDACC__) || defined(__HIPCC__)
559+
558560
CJflat[idx].a = make_float4(v0, v1, v2, v3);
559561
CJflat[idx].b = make_float2(v4, v5);
560562
#else
@@ -570,7 +572,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
570572
},
571573
[&](int i, int j, float val, const int p, const int r) {
572574
int const idx = p * 3 + r;
573-
#ifdef __CUDACC__
575+
#if defined(__CUDACC__) || defined(__HIPCC__)
576+
574577
float3 const u_local = make_float3(localFields[0][j], localFields[1][j],
575578
localFields[2][j]);
576579
float4 const a = CJflat[idx].a;
@@ -664,7 +667,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
664667
model_discretization_interface::gatherTransformData(elementNumber, mesh_local,
665668
transformData);
666669

667-
#ifdef __CUDACC__
670+
#if defined(__CUDACC__) || defined(__HIPCC__)
671+
668672
struct CJPacked
669673
{
670674
float4 a;
@@ -740,7 +744,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
740744
float const v4 = c44 * p0r2 + c13 * p2r0;
741745
float const v5 = c44 * p1r2 + c13 * p2r1;
742746

743-
#ifdef __CUDACC__
747+
#if defined(__CUDACC__) || defined(__HIPCC__)
748+
744749
CJflat[idx].a = make_float4(v0, v1, v2, v3);
745750
CJflat[idx].b = make_float2(v4, v5);
746751
#else
@@ -756,7 +761,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
756761
},
757762
[&](int i, int j, float val, const int p, const int r) {
758763
int const idx = p * 3 + r;
759-
#ifdef __CUDACC__
764+
#if defined(__CUDACC__) || defined(__HIPCC__)
765+
760766
float3 const u_local = make_float3(localFields[0][j], localFields[1][j],
761767
localFields[2][j]);
762768
float4 const a = CJflat[idx].a;
@@ -862,7 +868,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
862868
mesh_local.getCTensorOnElement(elementNumber, CTTI);
863869
}
864870

865-
#ifdef __CUDACC__
871+
#if defined(__CUDACC__) || defined(__HIPCC__)
872+
866873
struct CJPacked
867874
{
868875
float4 a;
@@ -939,7 +946,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
939946
C13 * p1r1 + C12 * p1r2 + C34 * p2r0 + C33 * p2r1 +
940947
C23 * p2r2;
941948

942-
#ifdef __CUDACC__
949+
#if defined(__CUDACC__) || defined(__HIPCC__)
950+
943951
CJflat[idx].a = make_float4(v0, v1, v2, v3);
944952
CJflat[idx].b = make_float2(v4, v5);
945953
#else
@@ -955,7 +963,8 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
955963
},
956964
[&](int i, int j, float val, const int p, const int r) {
957965
const int idx = p * 3 + r;
958-
#ifdef __CUDACC__
966+
#if defined(__CUDACC__) || defined(__HIPCC__)
967+
959968
const float3 u_local = make_float3(
960969
localFields[0][j], localFields[1][j], localFields[2][j]);
961970
const float4 a = CJflat[idx].a;
@@ -1024,7 +1033,6 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
10241033

10251034
if constexpr (PHYSICS == enums::physicType::kAcoustic)
10261035
{
1027-
// ===== ACOUSTIC VERSION =====
10281036
LOOPHEAD(mesh_local.getNumberOfNodes(), I)
10291037
{
10301038
if (mesh_local.isFreeSurface(I))
@@ -1072,7 +1080,6 @@ void SEMsolver<ORDER, INTEGRAL_TYPE, MESH_TYPE, IS_MODEL_ON_NODES,
10721080
}
10731081
else // ELASTIC
10741082
{
1075-
// ===== ELASTIC VERSION =====
10761083
LOOPHEAD(mesh_local.getNumberOfNodes(), I)
10771084
{
10781085
if (mesh_local.isFreeSurface(I))

src/utils/include/data_type_kokkos.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifndef FUNTIDES_UTILS_INCLUDE_DATA_TYPE_KOKKOS_H_
22
#define FUNTIDES_UTILS_INCLUDE_DATA_TYPE_KOKKOS_H_
3+
34
#include "Kokkos_Core_fwd.hpp"
45

56
#ifdef ENABLE_HIP
@@ -8,22 +9,19 @@
89

910
#include <Kokkos_Core.hpp>
1011

11-
#ifdef ENABLE_CUDA
12+
#if defined(ENABLE_CUDA) || defined(ENABLE_HIP)
1213
#define MemSpace Kokkos::SharedSpace
1314
using Layout = Kokkos::LayoutLeft;
1415
#else
1516
#define MemSpace Kokkos::HostSpace
1617
using Layout = Kokkos::LayoutRight;
1718
#endif
18-
1919
typedef Kokkos::View<int *, Layout, MemSpace> vectorInt;
2020
typedef Kokkos::View<float *, Layout, MemSpace> vectorReal;
2121
typedef Kokkos::View<double *, Layout, MemSpace> vectorDouble;
22-
2322
typedef Kokkos::View<int **, Layout, MemSpace> arrayInt;
2423
typedef Kokkos::View<float **, Layout, MemSpace> arrayReal;
2524
typedef Kokkos::View<double **, Layout, MemSpace> arrayDouble;
26-
2725
typedef Kokkos::View<int ***, Layout, MemSpace> array3DInt;
2826
typedef Kokkos::View<float ***, Layout, MemSpace> array3DReal;
2927
typedef Kokkos::View<double ***, Layout, MemSpace> array3DDouble;

0 commit comments

Comments
 (0)