Skip to content

Commit 0c81277

Browse files
committed
added -DACC_KERNELS
1 parent c4f1ddb commit 0c81277

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

CMakeLists.txt

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(CMAKE_CXX_STANDARD 11)
88

99
option(OPENACC "Enable OpenACC support" OFF)
1010
option(ACC_MULTICORE "Whether for OpenACC to compile for multicore" OFF)
11+
option(ACC_KERNELS "Whether for OpenACC to use the kernels directives" OFF)
1112
option(OPENMP "Enable OpenMP support" ON)
1213
option(OPENMP_OFFLOAD "Enable OpenMP offloading to GPU support" OFF)
1314
option(ROCM "Enable ROCm, offloading to MI100 using OpenMPI 4.5" OFF)
@@ -110,23 +111,28 @@ if ((NOT OPENACC) AND OPENMP_FOUND)
110111
else ()
111112
# OpenACC is incompatible with OpenMP, either one or the other or none
112113
if (OPENACC)
113-
add_definitions(-DHAVE_OPENACC)
114-
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^NVHPC|PGI")
115-
if (ACC_MULTICORE)
116-
message(STATUS "Apply OpenACC directives for offloading to multicore CPU")
117-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -acc=multicore -Minfo=acc")
114+
add_definitions(-DHAVE_OPENACC)
115+
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^NVHPC|PGI")
116+
if (ACC_KERNELS)
117+
message(STATUS "Apply OpenACC kernels directives")
118+
add_definitions(-DHAVE_OPENACC_KERNELS)
119+
endif ()
120+
if (ACC_MULTICORE)
121+
message(STATUS "Apply OpenACC directives for offloading to multicore CPU")
122+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -acc=multicore -Minfo=acc")
118123
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -acc=multicore -Minfo=acc")
119-
else ()
120-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -acc -gpu=mem:managed -Minfo=acc")
124+
else ()
125+
message(STATUS "Apply OpenACC directives for offloading to GPU")
126+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -acc -gpu=mem:managed -Minfo=acc")
121127
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -acc -gpu=mem:managed -Minfo=acc")
122-
endif ()
123-
message(STATUS "Using PGI or Nvidia C++ compiler, added OpenACC compiler switches")
124-
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^GNU")
125-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenacc -fopt-info-optimized-omp")
126-
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fopenacc -fopt-info-optimized-omp")
127-
message(STATUS "Using GNU C++ compiler, added OpenACC compiler switches")
128-
endif ()
129-
message(STATUS "OpenACC enabled")
128+
endif ()
129+
message(STATUS "Using PGI or Nvidia C++ compiler, added OpenACC compiler switches")
130+
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "^GNU")
131+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenacc -fopt-info-optimized-omp")
132+
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fopenacc -fopt-info-optimized-omp")
133+
message(STATUS "Using GNU C++ compiler, added OpenACC compiler switches")
134+
endif ()
135+
message(STATUS "OpenACC enabled")
130136
endif ()
131137
endif ()
132138

upwind/fortran/upwindF08Gpu.F90

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ subroutine upwind_advect(this, deltaTime)
162162
enddo
163163

164164
#if defined(HAVE_OPENACC)
165+
#if defined(USE_OPENACC_KERNELS)
166+
!$acc kernels
167+
#else
165168
!$acc parallel loop
169+
#endif
166170
#else
167171
!$omp target
168172
!$omp parallel do
@@ -171,15 +175,23 @@ subroutine upwind_advect(this, deltaTime)
171175
oldF(i) = fptr(i)
172176
enddo
173177
#if defined(HAVE_OPENACC)
178+
#if defined(USE_OPENACC_KERNELS)
179+
!$acc end kernels
180+
#else
174181
!$acc end parallel loop
182+
#endif
175183
#else
176184
!$omp end parallel do
177185
!$omp end target
178186
#endif
179187

180188
! iterate over the cells
181189
#if defined(HAVE_OPENACC)
190+
#if defined(USE_OPENACC_KERNELS)
191+
!$acc kernels
192+
#else
182193
!$acc parallel loop private(inds, j, oldIndex, upI)
194+
#endif
183195
#else
184196
!$omp target
185197
!$omp parallel do private(inds, j, oldIndex, upI)
@@ -215,7 +227,11 @@ subroutine upwind_advect(this, deltaTime)
215227
enddo
216228
enddo
217229
#if defined(HAVE_OPENACC)
230+
#if defined(USE_OPENACC_KERNELS)
231+
!$acc end kernels
232+
#else
218233
!$acc end parallel loop
234+
#endif
219235
#else
220236
!$omp end parallel do
221237
!$omp end target

0 commit comments

Comments
 (0)