Neko 1.99.10
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
opr_cfl.hip
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 <hip/hip_runtime.h>
38#include <device/hip/check.h>
39#include <device/hip/buffer.h>
40#include "cfl_kernel.h"
41
42extern "C" {
43
46
47#ifdef HAVE_RCCL
50#endif
51
58
62 double hip_cfl(double *dt, void *u, void *v, void *w,
63 void *drdx, void *dsdx, void *dtdx,
64 void *drdy, void *dsdy, void *dtdy,
65 void *drdz, void *dsdz, void *dtdz,
66 void *dr_inv, void *ds_inv, void *dt_inv,
67 void *jacinv, int *nel, int *lx) {
68
69 const dim3 nthrds(1024, 1, 1);
70 const dim3 nblcks((*nel), 1, 1);
71
72 hip_buffer_reserve(&cfl_buf, (*nel) * sizeof(double));
73 double *cfl_d = (double *) cfl_buf.dev;
74
75#define CASE(LX) \
76 case LX: \
77 hipLaunchKernelGGL(HIP_KERNEL_NAME( cfl_kernel<double, real, LX, 1024> ), \
78 nblcks, nthrds, 0, (hipStream_t) glb_cmd_queue, \
79 *dt, (real *) u, (real *) v, (real *) w, \
80 (real *) drdx, (real *) dsdx, (real *) dtdx, \
81 (real *) drdy, (real *) dsdy, (real *) dtdy, \
82 (real *) drdz, (real *) dsdz, (real *) dtdz, \
83 (real *) dr_inv, (real *) ds_inv, (real *) dt_inv, \
84 (real *) jacinv, (double *) cfl_d); \
85 HIP_CHECK(hipGetLastError()); \
86 break
87
88 switch(*lx) {
89 CASE(2);
90 CASE(3);
91 CASE(4);
92 CASE(5);
93 CASE(6);
94 CASE(7);
95 CASE(8);
96 CASE(9);
97 CASE(10);
98 CASE(11);
99 CASE(12);
100 default:
101 {
102 fprintf(stderr, __FILE__ ": size not supported: %d\n", *lx);
103 exit(1);
104 }
105 }
106
107
108 hipLaunchKernelGGL(HIP_KERNEL_NAME(cfl_reduce_kernel<double>),
109 1, 1024, 0, (hipStream_t) glb_cmd_queue,
110 cfl_d, (*nel));
111 HIP_CHECK(hipGetLastError());
112
113 double cfl = 0.0;
114#ifdef HAVE_RCCL
115 device_nccl_allreduce(cfl_d, cfl_d, 1, sizeof(double),
117 HIP_CHECK(hipMemcpyAsync(&cfl, cfl_d, sizeof(double),
118 hipMemcpyDeviceToHost,
119 (hipStream_t) glb_cmd_queue));
120 HIP_CHECK(hipStreamSynchronize((hipStream_t) glb_cmd_queue));
121#elif HAVE_DEVICE_MPI
122 HIP_CHECK(hipStreamSynchronize((hipStream_t) glb_cmd_queue));
123 device_mpi_allreduce(cfl_d, &cfl, 1, sizeof(double), DEVICE_MPI_MAX);
124#else
125 HIP_CHECK(hipMemcpyAsync(&cfl, cfl_d, sizeof(double),
126 hipMemcpyDeviceToHost,
127 (hipStream_t) glb_cmd_queue));
128 HIP_CHECK(hipStreamSynchronize((hipStream_t) glb_cmd_queue));
129#endif
130
131
132 return cfl;
133 }
134}
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ w
__global__ void const T *__restrict__ u
__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__ const T *__restrict__ dtdy
__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__ 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__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ jacinv
__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__ 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__ 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__ dsdx
__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__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ drdy
__global__ void const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ dt
__global__ void cfl_reduce_kernel(T *bufred, const int n)
Definition cfl_kernel.h:55
void * glb_cmd_queue
#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)
void hip_buffer_reserve(hip_buffer_t *buf, size_t size)
Definition buffer.hip:47
struct hip_buffer hip_buffer_t
Definition buffer.h:59
#define HIP_BUFFER_INIT_DEV
Definition buffer.h:62
#define HIP_CHECK(err)
Definition check.h:8
cuda_buffer_t cfl_buf
Definition opr_cfl.cu:62
#define CASE(LX)
double hip_cfl(double *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.hip:62