Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opr_cfl.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2022-2025, 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"
38#include <device/cuda/check.h>
39#include <device/cuda/buffer.h>
40
41
42#ifdef HAVE_NVSHMEM
43#include <nvshmem.h>
44#include <nvshmemx.h>
45#endif
46
47extern "C" {
48
51
52#ifdef HAVE_NCCL
55#endif
56
63
64#ifdef HAVE_NVSHMEM
71#endif
72
76 real cuda_cfl(real *dt, void *u, void *v, void *w,
77 void *drdx, void *dsdx, void *dtdx,
78 void *drdy, void *dsdy, void *dtdy,
79 void *drdz, void *dsdz, void *dtdz,
80 void *dr_inv, void *ds_inv, void *dt_inv,
81 void *jacinv, int *nel, int *lx) {
82
83 const dim3 nthrds(1024, 1, 1);
84 const dim3 nblcks((*nel), 1, 1);
85 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
86
87 cuda_buffer_reserve(&cfl_buf, (*nel) * sizeof(real));
88 real *cfl_d = (real *) cfl_buf.dev;
89#ifdef HAVE_NVSHMEM
91 real *cfl_red_d = (real *) cfl_red_buf.dev;
92#endif
93
94#define CASE(LX) \
95 case LX: \
96 cfl_kernel<real, LX, 1024> \
97 <<<nblcks, nthrds, 0, stream>>> \
98 (*dt, (real *) u, (real *) v, (real *) w, \
99 (real *) drdx, (real *) dsdx, (real *) dtdx, \
100 (real *) drdy, (real *) dsdy, (real *) dtdy, \
101 (real *) drdz, (real *) dsdz, (real *) dtdz, \
102 (real *) dr_inv, (real *) ds_inv, (real *) dt_inv, \
103 (real *) jacinv, (real *) cfl_d); \
104 CUDA_CHECK(cudaGetLastError()); \
105 break
106
107 switch(*lx) {
108 CASE(2);
109 CASE(3);
110 CASE(4);
111 CASE(5);
112 CASE(6);
113 CASE(7);
114 CASE(8);
115 CASE(9);
116 CASE(10);
117 default:
118 {
119 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
120 exit(1);
121 }
122 }
123
124 cfl_reduce_kernel<real><<<1, 1024, 0, stream>>> ((real *) cfl_d, (*nel));
126
127 real cfl;
128#ifdef HAVE_NCCL
129 device_nccl_allreduce(cfl_d, cfl_d, 1, sizeof(real),
130 DEVICE_NCCL_MAX, stream);
131 CUDA_CHECK(cudaMemcpyAsync(&cfl, cfl_d, sizeof(real),
132 cudaMemcpyDeviceToHost, stream));
133 cudaStreamSynchronize(stream);
134#elif HAVE_NVSHMEM
136 cudaMemcpyDeviceToDevice, stream));
137 if (sizeof(real) == sizeof(float)) {
139 (float *) cfl_red_d,
140 (float *) cfl_red_d, 1, stream);
141 }
142 else if (sizeof(real) == sizeof(double)) {
144 (double *) cfl_red_d,
145 (double *) cfl_red_d, 1, stream);
146 }
148 cudaMemcpyDeviceToHost, stream));
149 cudaStreamSynchronize(stream);
150#elif HAVE_DEVICE_MPI
151 cudaStreamSynchronize(stream);
152 device_mpi_allreduce(cfl_d, &cfl, 1, sizeof(real), DEVICE_MPI_MAX);
153#else
154 CUDA_CHECK(cudaMemcpyAsync(&cfl, cfl_d, sizeof(real),
155 cudaMemcpyDeviceToHost, stream));
156 cudaStreamSynchronize(stream);
157#endif
158 return cfl;
159 }
160}
void cuda_buffer_reserve(cuda_buffer_t *buf, size_t size)
Definition buffer.cu:50
__global__ void ale_add_kinematics_kernel(const int n, T *__restrict__ wx, T *__restrict__ wy, T *__restrict__ wz, const T *__restrict__ x_ref, const T *__restrict__ y_ref, const T *__restrict__ z_ref, const T *__restrict__ phi, const T *__restrict__ x, const T *__restrict__ y, const T *__restrict__ z, const kinematics_params_t kin_params)
__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
#define CUDA_BUFFER_INIT_DEV
Definition buffer.h:64
#define CUDA_BUFFER_INIT_SYMM
Definition buffer.h:63
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
#define CUDA_CHECK(err)
Definition check.h:6
double real
#define DEVICE_MPI_MAX
void device_mpi_allreduce(void *buf_d, void *buf, int count, int nbytes, int op)
#define DEVICE_NCCL_MAX
void device_nccl_allreduce(void *sbuf_d, void *rbuf_d, int count, int nbytes, int op, void *stream)
#define CASE(LX)
cuda_buffer_t cfl_buf
Definition opr_cfl.cu:62
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:76
void * dev
Definition buffer.h:53