Skip to content

Commit 42e86ec

Browse files
committed
Add serial
1 parent 9c3a401 commit 42e86ec

18 files changed

+115
-145
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
CI:
1414
strategy:
1515
matrix:
16-
backend: ["OPENMP"]
16+
backend: ["OPENMP","SERIAL"]
1717
runs-on: ubuntu-latest
1818
steps:
1919
- name: Install deps
@@ -46,6 +46,6 @@ jobs:
4646
uses: actions/checkout@v2.2.0
4747
- name: Build
4848
run: |
49-
cmake -B build -DCMAKE_PREFIX_PATH="$HOME/kokkos;$HOME/Cabana"
49+
cmake -B build -DCMAKE_PREFIX_PATH="$HOME/kokkos;$HOME/Cabana" $([[ ${{ matrix.backend }} == SERIAL ]] || echo -DUSE_OMP=OFF) -DUSE_GPU=OFF
5050
cmake --build build --parallel 2
5151
cd build && ctest --output-on-failure

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
2929
# find dependencies
3030
find_package(Cabana REQUIRED)
3131

32+
option(USE_OMP "Use OpenMP" ON)
33+
option(USE_GPU "Use GPU" OFF)
34+
35+
configure_file(advanced_examples/CFE_config.hpp.cmakein advanced_examples/CFE_config.hpp @ONLY)
36+
3237
enable_language(Fortran)
3338
find_package(MPI REQUIRED COMPONENTS Fortran)
3439
add_subdirectory(advanced_examples)

advanced_examples/01_parallel_for/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
if( Cabana_ENABLE_Cuda )
1+
if( USE_GPU )
22
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
3-
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32 -DUSE_GPU=1)
3+
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32)
44
set(MPI_Fortran_COMPILE_FLAGS "-r -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
55
set(CMAKE_CXX_FLAGS "--relocatable-device-code=true")
66
set(CMAKE_EXE_LINKER_FLAGS "-pgc++libs -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
@@ -9,10 +9,10 @@ if( Cabana_ENABLE_Cuda )
99
return()
1010
endif()
1111
else()
12-
if( Kokkos_ENABLE_OPENMP )
12+
if( USE_OMP )
1313
add_definitions(-fopenmp)
1414
endif()
15-
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32 -DUSE_GPU=0)
15+
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32)
1616
endif()
1717

1818
add_definitions(${MPI_Fortran_COMPILE_FLAGS})

advanced_examples/01_parallel_for/cabana_cpp_interface.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,16 @@
1818
#include <cstdlib>
1919
#include <iostream>
2020

21+
#include "../CFE_config.hpp"
2122
#include "../Fortran_features/cabana_fortran_cpp_defs.h"
2223

23-
// Whether to use the GPU version
24-
#ifndef USE_GPU
25-
#define USE_GPU 0
26-
#endif
27-
28-
// If using the CPU version, whether to use OpenMP
29-
#ifndef USE_OMP
30-
#define USE_OMP 1
31-
#endif
32-
3324
// Declare the memory and execution spaces.
34-
#if USE_GPU == 1
25+
#ifdef USE_GPU
3526
using MemorySpace = Kokkos::CudaUVMSpace;
3627
using ExecutionSpace = Kokkos::Cuda;
3728
#else
3829
using MemorySpace = Kokkos::HostSpace;
39-
#if USE_OMP == 1
30+
#ifdef USE_OMP
4031
using ExecutionSpace = Kokkos::OpenMP;
4132
#else
4233
using ExecutionSpace = Kokkos::Serial;
@@ -66,6 +57,3 @@ int parallel_for_example( int start_pt, int end_pt)
6657
Kokkos::parallel_for( range_policy_vec, local_lambda, "example_op" );
6758
return 0;
6859
}
69-
70-
71-

advanced_examples/02_push/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
if( Cabana_ENABLE_Cuda )
1+
if( USE_GPU )
22
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
3-
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32 -DUSE_GPU=1)
3+
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32 )
44
set(MPI_Fortran_COMPILE_FLAGS "-r -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
55
set(CMAKE_CXX_FLAGS "--relocatable-device-code=true")
66
set(CMAKE_EXE_LINKER_FLAGS "-pgc++libs -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
@@ -9,10 +9,10 @@ if( Cabana_ENABLE_Cuda )
99
return()
1010
endif()
1111
else()
12-
if( Kokkos_ENABLE_OPENMP )
12+
if( USE_OMP )
1313
add_definitions(-fopenmp)
1414
endif()
15-
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32 -DUSE_GPU=0)
15+
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32)
1616
endif()
1717

1818
add_definitions(${MPI_Fortran_COMPILE_FLAGS})

advanced_examples/02_push/cabana_cpp_interface.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdlib>
88
#include <iostream>
99

10+
#include "../CFE_config.hpp"
1011
#include "../Fortran_features/cabana_fortran_cpp_defs.h"
1112

1213
// Length of loop for vectorization
@@ -19,22 +20,25 @@
1920
#define VEC_LEN 1
2021
#endif
2122

22-
// Whether to use the GPU version
23-
#ifndef USE_GPU
24-
#define USE_GPU 0
23+
// Declare the memory and execution spaces.
24+
#ifdef USE_GPU
25+
using MemorySpace = Kokkos::CudaUVMSpace;
26+
using ExecutionSpace = Kokkos::Cuda;
27+
#else
28+
using MemorySpace = Kokkos::HostSpace;
29+
#ifdef USE_OMP
30+
using ExecutionSpace = Kokkos::OpenMP;
31+
#else
32+
using ExecutionSpace = Kokkos::Serial;
2533
#endif
26-
27-
// If using the CPU version, whether to use OpenMP
28-
#ifndef USE_OMP
29-
#define USE_OMP 1
3034
#endif
3135

3236
// Most particle routines can be written as a loop over particles.
3337
// In the GPU case, launch a parallel_for over particles
3438
// In the CPU case, launch a parallel_for over vectors
3539
// The vector loop is currently inclusive of the ends, so if you ask to operate over
3640
// particles 15-33 and your vector length is 16, you will operate over particle 1-48.
37-
#if USE_GPU==1
41+
#ifdef USE_GPU
3842
#define PARTICLE_OP(C_FUNC,F_FUNC) \
3943
extern "C" int C_FUNC( int sp, int np ); \
4044
extern "C" KOKKOS_FUNCTION void F_FUNC(local_particle_struct_t*, int, int); \
@@ -97,19 +101,6 @@ struct local_particle_struct_t {
97101
long long int gid[VEC_LEN];
98102
};
99103

100-
// Declare the memory and execution spaces.
101-
#if USE_GPU == 1
102-
using MemorySpace = Kokkos::CudaUVMSpace;
103-
using ExecutionSpace = Kokkos::Cuda;
104-
#else
105-
using MemorySpace = Kokkos::HostSpace;
106-
#if USE_OMP == 1
107-
using ExecutionSpace = Kokkos::OpenMP;
108-
#else
109-
using ExecutionSpace = Kokkos::Serial;
110-
#endif
111-
#endif
112-
113104
// Set the type and memory space for the particle AoSoA.
114105
using ParticleList = Cabana::AoSoA<ParticleDataTypes,MemorySpace,VEC_LEN>;
115106

@@ -130,4 +121,3 @@ int particle_allocation(int num_particle)
130121
}
131122

132123
#include "particle_ops.h"
133-

advanced_examples/02_push/ptl_module.F90

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
#include "../CFE_config.hpp"
12
#include "../Fortran_features/cabana_fortran_macros.h"
2-
#ifndef USE_GPU
3-
#define USE_GPU 0
4-
#endif
3+
54
#ifndef SIMD_SIZE
65
#define SIMD_SIZE 1
76
#endif
@@ -55,7 +54,7 @@ integer(C_INT) function particle_initialization(sp, num_particle) bind(C, name="
5554
! Allocate and initialize particles
5655
subroutine particle_setup
5756
integer :: err
58-
#if USE_GPU==1
57+
#ifdef USE_GPU
5958
print *, "*** GPU VERSION ***"
6059
#else
6160
print *, "*** CPU VERSION ***"
@@ -155,7 +154,7 @@ subroutine AoS_indices(i_item,s_vec,a_vec)
155154
integer, intent(out) :: s_vec
156155
integer, intent(out) :: a_vec
157156
integer :: i_temp, i_mod
158-
#if USE_CAB_GPU == 1
157+
#ifdef USE_GPU
159158
! GPU: access an individual particle
160159
i_temp = i_item
161160
i_mod = modulo(i_temp,VEC_LEN)

advanced_examples/02_push/push_module.F90

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "../Fortran_features/cabana_fortran_macros.h"
2-
#ifndef USE_GPU
3-
#define USE_GPU 0
4-
#endif
2+
53
#ifndef SIMD_SIZE
64
#define SIMD_SIZE 1
75
#endif

advanced_examples/03_scatter/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
if( Cabana_ENABLE_Cuda )
1+
if( USE_GPU )
22
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
3-
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32 -DUSE_GPU=1)
3+
add_definitions(-DSIMD_SIZE=1 -DVEC_LEN=32)
44
set(MPI_Fortran_COMPILE_FLAGS "-r -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
55
set(CMAKE_CXX_FLAGS "--relocatable-device-code=true")
66
set(CMAKE_EXE_LINKER_FLAGS "-pgc++libs -ta=tesla:cuda9.0 -Minfo=accel -Mcuda=cuda9.0")
@@ -9,10 +9,10 @@ if( Cabana_ENABLE_Cuda )
99
return()
1010
endif()
1111
else()
12-
if( Kokkos_ENABLE_OPENMP )
12+
if( USE_OMP )
1313
add_definitions(-fopenmp)
1414
endif()
15-
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32 -DUSE_GPU=0)
15+
add_definitions(-DSIMD_SIZE=32 -DVEC_LEN=32)
1616
endif()
1717

1818
add_definitions(${MPI_Fortran_COMPILE_FLAGS})

advanced_examples/03_scatter/cabana_cpp_interface.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdlib>
88
#include <iostream>
99

10+
#include "../CFE_config.hpp"
1011
#include "../Fortran_features/cabana_fortran_cpp_defs.h"
1112

1213
// Length of loop for vectorization
@@ -19,22 +20,25 @@
1920
#define VEC_LEN 1
2021
#endif
2122

22-
// Whether to use the GPU version
23-
#ifndef USE_GPU
24-
#define USE_GPU 0
23+
// Declare the memory and execution spaces.
24+
#ifdef USE_GPU
25+
using MemorySpace = Kokkos::CudaUVMSpace;
26+
using ExecutionSpace = Kokkos::Cuda;
27+
#else
28+
using MemorySpace = Kokkos::HostSpace;
29+
#ifdef USE_OMP
30+
using ExecutionSpace = Kokkos::OpenMP;
31+
#else
32+
using ExecutionSpace = Kokkos::Serial;
2533
#endif
26-
27-
// If using the CPU version, whether to use OpenMP
28-
#ifndef USE_OMP
29-
#define USE_OMP 1
3034
#endif
3135

3236
// Most particle routines can be written as a loop over particles.
3337
// In the GPU case, launch a parallel_for over particles
3438
// In the CPU case, launch a parallel_for over vectors
3539
// The vector loop is currently inclusive of the ends, so if you ask to operate over
3640
// particles 15-33 and your vector length is 16, you will operate over particle 1-48.
37-
#if USE_GPU==1
41+
#ifdef USE_GPU
3842
#define PARTICLE_OP(C_FUNC,F_FUNC) \
3943
extern "C" int C_FUNC( int sp, int np ); \
4044
extern "C" KOKKOS_FUNCTION void F_FUNC(local_particle_struct_t*, int, int); \
@@ -97,19 +101,6 @@ struct local_particle_struct_t {
97101
long long int gid[VEC_LEN];
98102
};
99103

100-
// Declare the memory and execution spaces.
101-
#if USE_GPU == 1
102-
using MemorySpace = Kokkos::CudaUVMSpace;
103-
using ExecutionSpace = Kokkos::Cuda;
104-
#else
105-
using MemorySpace = Kokkos::HostSpace;
106-
#if USE_OMP == 1
107-
using ExecutionSpace = Kokkos::OpenMP;
108-
#else
109-
using ExecutionSpace = Kokkos::Serial;
110-
#endif
111-
#endif
112-
113104
// Set the type and memory space for the particle AoSoA.
114105
using ParticleList = Cabana::AoSoA<ParticleDataTypes,MemorySpace,VEC_LEN>;
115106

@@ -143,4 +134,3 @@ void cabana_initialize() {
143134
void cabana_finalize( void ) {
144135
Kokkos::finalize();
145136
}
146-

0 commit comments

Comments
 (0)