Neko  0.9.99
A portable framework for high-order spectral element flow simulations
opr_cfl.cu
Go to the documentation of this file.
1 /*
2  Copyright (c) 2022, The Neko Authors
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions
7  are met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above
13  copyright notice, this list of conditions and the following
14  disclaimer in the documentation and/or other materials provided
15  with the distribution.
16 
17  * Neither the name of the authors nor the names of its
18  contributors may be used to endorse or promote products derived
19  from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  POSSIBILITY OF SUCH DAMAGE.
33 */
34 
35 #include <stdio.h>
36 #include "cfl_kernel.h"
37 #include <device/device_config.h>
38 #include <device/cuda/check.h>
39 
40 
41 extern "C" {
42 
45 
49  real *cfl_d = NULL;
50 
54  real cuda_cfl(real *dt, void *u, void *v, void *w,
55  void *drdx, void *dsdx, void *dtdx,
56  void *drdy, void *dsdy, void *dtdy,
57  void *drdz, void *dsdz, void *dtdz,
58  void *dr_inv, void *ds_inv, void *dt_inv,
59  void *jacinv, int *nel, int *lx) {
60 
61  const dim3 nthrds(1024, 1, 1);
62  const dim3 nblcks((*nel), 1, 1);
63  const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
64 
65  if (cfl_d == NULL) {
66  CUDA_CHECK(cudaMalloc(&cfl_d, (*nel) * sizeof(real)));
67  }
68 
69 
70 
71 #define CASE(LX) \
72  case LX: \
73  cfl_kernel<real, LX, 1024> \
74  <<<nblcks, nthrds, 0, stream>>> \
75  (*dt, (real *) u, (real *) v, (real *) w, \
76  (real *) drdx, (real *) dsdx, (real *) dtdx, \
77  (real *) drdy, (real *) dsdy, (real *) dtdy, \
78  (real *) drdz, (real *) dsdz, (real *) dtdz, \
79  (real *) dr_inv, (real *) ds_inv, (real *) dt_inv, \
80  (real *) jacinv, (real *) cfl_d); \
81  CUDA_CHECK(cudaGetLastError()); \
82  break
83 
84  switch(*lx) {
85  CASE(2);
86  CASE(3);
87  CASE(4);
88  CASE(5);
89  CASE(6);
90  CASE(7);
91  CASE(8);
92  CASE(9);
93  CASE(10);
94  default:
95  {
96  fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
97  exit(1);
98  }
99  }
100 
101  cfl_reduce_kernel<real><<<1, 1024, 0, stream>>> (cfl_d, (*nel));
102  CUDA_CHECK(cudaGetLastError());
103 
104  real cfl;
105 #ifdef HAVE_DEVICE_MPI
106  cudaStreamSynchronize(stream);
108 #else
109  CUDA_CHECK(cudaMemcpyAsync(&cfl, cfl_d, sizeof(real),
110  cudaMemcpyDeviceToHost, stream));
111  cudaStreamSynchronize(stream);
112 #endif
113 
114  return cfl;
115  }
116 }
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdy
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdz
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dsdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dtdx
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
Definition: cdtp_kernel.h:109
#define CUDA_CHECK(err)
Definition: check.h:6
double real
Definition: device_config.h:12
void * glb_cmd_queue
#define DEVICE_MPI_MAX
Definition: device_mpi_op.h:10
void device_mpi_allreduce(void *buf_d, void *buf, int count, int nbytes, int op)
real(kind=rp) function, public cfl(dt, u, v, w, Xh, coef, nelv, gdim)
Definition: operators.f90:394
real * cfl_d
Definition: opr_cfl.cu:49
#define CASE(LX)
real cuda_cfl(real *dt, void *u, void *v, void *w, void *drdx, void *dsdx, void *dtdx, void *drdy, void *dsdy, void *dtdy, void *drdz, void *dsdz, void *dtdz, void *dr_inv, void *ds_inv, void *dt_inv, void *jacinv, int *nel, int *lx)
Definition: opr_cfl.cu:54