48 #include "Kokkos_Core.hpp"
54 #ifdef KOKKOS_ENABLE_CUDA
55 #include "cuda_runtime_api.h"
58 template <
typename Storage>
61 const int use_trials ,
62 const int use_nodes[] ,
66 const int entry_min = 8;
67 const int entry_max = 48;
68 const int entry_step = 8;
70 const int entry_min = 4;
71 const int entry_max = 32;
72 const int entry_step = 4;
78 performance_test_driver<Storage,entry_min,entry_max,entry_step>(
79 comm, use_print, use_trials, use_nodes, check, dev_config);
82 template <
typename Storage>
85 const int use_trials ,
86 const int use_nodes[] ,
89 const int entry_min = 16;
90 const int entry_max = 64;
91 const int entry_step = 16;
92 performance_test_driver<Storage,entry_min,entry_max,entry_step>(
93 comm, use_print, use_trials, use_nodes, check, dev_config);
108 const size_t num_sockets = Kokkos::hwloc::get_available_numa_count();
109 const size_t num_cores_per_socket =
110 Kokkos::hwloc::get_available_cores_per_numa();
111 const size_t num_threads_per_core =
112 Kokkos::hwloc::get_available_threads_per_core();
117 "This test performance of MP::Vector FEM assembly.\n");
119 CLP.
setOption(
"n", &nGrid,
"Number of mesh points in the each direction");
121 CLP.
setOption(
"ni", &nIter,
"Number of assembly iterations");
123 CLP.
setOption(
"print",
"no-print", &print,
"Print debugging output");
125 int num_cores = num_cores_per_socket * num_sockets;
127 "Number of CPU cores to use (defaults to all)");
129 CLP.
setOption(
"hyperthreads", &num_hyper_threads,
130 "Number of hyper threads per core to use (defaults to all)");
131 int threads_per_vector = 1;
132 CLP.
setOption(
"threads_per_vector", &threads_per_vector,
133 "Number of threads to use within each vector");
134 CLP.
setOption(
"check",
"no-check", &check,
"Check correctness");
135 #ifdef KOKKOS_ENABLE_SERIAL
137 CLP.
setOption(
"serial",
"no-serial", &serial,
"Enable Serial device");
139 #ifdef KOKKOS_ENABLE_THREADS
141 CLP.
setOption(
"threads",
"no-threads", &threads,
"Enable Threads device");
143 #ifdef KOKKOS_ENABLE_OPENMP
145 CLP.
setOption(
"openmp",
"no-openmp", &openmp,
"Enable OpenMP device");
147 #ifdef KOKKOS_ENABLE_CUDA
149 CLP.
setOption(
"cuda",
"no-cuda", &cuda,
"Enable Cuda device");
150 int cuda_threads_per_vector = 16;
151 CLP.
setOption(
"cuda_threads_per_vector", &cuda_threads_per_vector,
152 "Number of Cuda threads to use within each vector");
153 int cuda_block_size = 256;
154 CLP.
setOption(
"cuda_block_size", &cuda_block_size,
156 int num_cuda_blocks = 0;
157 CLP.
setOption(
"num_cuda_blocks", &num_cuda_blocks,
158 "Number of Cuda blocks (0 implies the default choice)");
160 CLP.
setOption(
"device", &device_id,
"CUDA device ID. Set to default of -1 to use the default device as determined by the local node MPI rank and --ngpus");
162 CLP.
setOption(
"ngpus", &ngpus,
"Number of GPUs per node for multi-GPU runs via MPI");
164 CLP.
parse( argc, argv );
167 use_nodes[0] = nGrid; use_nodes[1] = nGrid; use_nodes[2] = nGrid;
172 #ifdef KOKKOS_ENABLE_SERIAL
174 typedef Kokkos::Serial Device;
177 Kokkos::initialize();
179 if (comm->getRank() == 0)
180 std::cout << std::endl
181 <<
"Serial performance with " << comm->getSize()
182 <<
" MPI ranks" << std::endl;
186 mainHost<Storage>(comm, print, nIter, use_nodes, check,
193 #ifdef KOKKOS_ENABLE_THREADS
195 typedef Kokkos::Threads Device;
198 Kokkos::InitArguments init_args;
200 Kokkos::initialize( init_args );
202 if (comm->getRank() == 0)
203 std::cout << std::endl
204 <<
"Threads performance with " << comm->getSize()
205 <<
" MPI ranks and " << num_cores*num_hyper_threads
206 <<
" threads per rank:" << std::endl;
210 num_hyper_threads / threads_per_vector);
212 mainHost<Storage>(comm, print, nIter, use_nodes, check,
219 #ifdef KOKKOS_ENABLE_OPENMP
221 typedef Kokkos::OpenMP Device;
224 Kokkos::InitArguments init_args;
226 Kokkos::initialize( init_args );
228 if (comm->getRank() == 0)
229 std::cout << std::endl
230 <<
"OpenMP performance with " << comm->getSize()
231 <<
" MPI ranks and " << num_cores*num_hyper_threads
232 <<
" threads per rank:" << std::endl;
236 num_hyper_threads / threads_per_vector);
238 mainHost<Storage>(comm, print, nIter, use_nodes, check,
245 #ifdef KOKKOS_ENABLE_CUDA
247 typedef Kokkos::Cuda Device;
250 if (device_id == -1) {
253 if ((str = std::getenv(
"SLURM_LOCALID")))
254 local_rank = std::atoi(str);
255 else if ((str = std::getenv(
"MV2_COMM_WORLD_LOCAL_RANK")))
256 local_rank = std::atoi(str);
257 else if ((str = getenv(
"OMPI_COMM_WORLD_LOCAL_RANK")))
258 local_rank = std::atoi(str);
259 device_id = local_rank % ngpus;
262 int num_device; cudaGetDeviceCount(&num_device);
264 device_id >= num_device, std::logic_error,
265 "Invalid device ID " << device_id <<
". You probably are trying" <<
266 " to run with too many GPUs per node");
269 Kokkos::InitArguments init_args;
270 init_args.device_id = device_id;
271 Kokkos::initialize( init_args );
273 cudaDeviceProp deviceProp;
274 cudaGetDeviceProperties(&deviceProp, device_id);
275 if (comm->getRank() == 0)
276 std::cout << std::endl
277 <<
"CUDA performance performance with " << comm->getSize()
278 <<
" MPI ranks and device " << device_id <<
" ("
279 << deviceProp.name <<
"):"
284 cuda_threads_per_vector,
285 cuda_threads_per_vector == 0 ? 0 : cuda_block_size / cuda_threads_per_vector);
287 mainCuda<Storage>(comm, print, nIter, use_nodes, check,
Stokhos::StandardStorage< int, double > Storage
void mainHost(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const int use_print, const int use_trials, const int use_nodes[], const bool check, Kokkos::Example::FENL::DeviceConfig dev_config)
Statically allocated storage class.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void mainCuda(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const int use_print, const int use_trials, const int use_nodes[], const bool check, Kokkos::Example::FENL::DeviceConfig dev_config)
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
int check(Epetra_CrsGraph &A, int NumMyRows1, int NumGlobalRows1, int NumMyNonzeros1, int NumGlobalNonzeros1, int *MyGlobalElements, bool verbose)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
int main(int argc, char **argv)
void setDocString(const char doc_string[])