Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
fusedcg_cpld_aux.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2024-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 "fusedcg_cpld_kernel.h"
37#include <device/cuda/check.h>
38
39#ifdef HAVE_NVSHMEM
40#include <nvshmem.h>
41#include <nvshmemx.h>
42#endif
43
50
51extern "C" {
52
55
56 void cuda_fusedcg_cpld_part1(void *a1, void *a2, void *a3,
57 void *b1, void *b2, void *b3,
58 void *tmp, int *n) {
59
60 const dim3 nthrds(1024, 1, 1);
61 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
62 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
63
65 <<<nblcks, nthrds, 0, stream>>>((real *) a1, (real *) a2, (real *) a3,
66 (real *) b1, (real *) b2, (real *) b3,
67 (real *) tmp, *n);
69 }
70
71 void cuda_fusedcg_cpld_update_p(void *p1, void *p2, void *p3,
72 void *z1, void *z2, void *z3,
73 void *po1, void *po2, void *po3,
74 real *beta, int *n) {
75
76 const dim3 nthrds(1024, 1, 1);
77 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
78 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
79
81 <<<nblcks, nthrds, 0, stream>>>((real *) p1, (real *) p2, (real *) p3,
82 (real *) z1, (real *) z2, (real *) z3,
83 (real *) po1, (real *) po2, (real *) po3,
84 *beta, *n);
86
87 }
88
89 void cuda_fusedcg_cpld_update_x(void *x1, void *x2, void *x3,
90 void *p1, void *p2, void *p3,
91 void *alpha, int *p_cur, int *n) {
92
93 const dim3 nthrds(1024, 1, 1);
94 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
95 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
96
98 <<<nblcks, nthrds, 0, stream>>>((real *) x1, (real *) x2, (real *) x3,
99 (const real **) p1, (const real **) p2,
100 (const real **) p3, (const real *) alpha,
101 *p_cur, *n);
103 }
104
105 real cuda_fusedcg_cpld_part2(void *a1, void *a2, void *a3, void *b,
106 void *c1, void *c2, void *c3, void *alpha_d ,
107 real *alpha, int *p_cur, int * n) {
108
109 const dim3 nthrds(1024, 1, 1);
110 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
111 const int nb = ((*n) + 1024 - 1)/ 1024;
112 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
113
116#ifdef HAVE_NVSHMEM
118#else
120#endif
122 }
123
124 if (fusedcg_cpld_buf == NULL){
126#ifdef HAVE_NVSHMEM
128#else
130#endif
132 }
133
134 /* Store alpha(p_cur) in pinned memory */
135 fusedcg_cpld_buf[1] = (*alpha);
136
137 /* Update alpha_d(p_cur) = alpha(p_cur) */
138 real *alpha_d_p_cur = ((real *) alpha_d) + ((*p_cur - 1));
141 stream));
142
143
145 <<<nblcks, nthrds, 0, stream>>>((real *) a1, (real *) a2, (real *) a3,
146 (real *) b, (real *) c1, (real *) c2,
147 (real *) c3, *alpha,
148 (real *) fusedcg_cpld_buf_d, *n);
150
151 reduce_kernel<real><<<1, 1024, 0, stream>>>((real *) fusedcg_cpld_buf_d, nb);
153
154#ifdef HAVE_DEVICE_MPI
155 cudaStreamSynchronize(stream);
157 sizeof(real), DEVICE_MPI_SUM);
158#elif HAVE_NVSHMEM
159 if (sizeof(real) == sizeof(float)) {
161 (float *) fusedcg_cpld_buf_d,
162 (float *) fusedcg_cpld_buf_d,
163 1, stream);
164 }
165 else if (sizeof(real) == sizeof(double)) {
167 (double *) fusedcg_cpld_buf_d,
168 (double *) fusedcg_cpld_buf_d,
169 1, stream);
170
171 }
173 sizeof(real), cudaMemcpyDeviceToHost, stream));
174 cudaStreamSynchronize(stream);
175#else
177 cudaMemcpyDeviceToHost, stream));
178 cudaStreamSynchronize(stream);
179#endif
180
181 return fusedcg_cpld_buf[0];
182 }
183}
#define CUDA_CHECK(err)
Definition check.h:6
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
double real
#define DEVICE_MPI_SUM
void device_mpi_allreduce(void *buf_d, void *buf, int count, int nbytes, int op)
void cuda_fusedcg_cpld_update_x(void *x1, void *x2, void *x3, void *p1, void *p2, void *p3, void *alpha, int *p_cur, int *n)
void * fusedcg_cpld_buf_d
int fusedcg_cpld_buf_len
void cuda_fusedcg_cpld_part1(void *a1, void *a2, void *a3, void *b1, void *b2, void *b3, void *tmp, int *n)
real cuda_fusedcg_cpld_part2(void *a1, void *a2, void *a3, void *b, void *c1, void *c2, void *c3, void *alpha_d, real *alpha, int *p_cur, int *n)
real * fusedcg_cpld_buf
void cuda_fusedcg_cpld_update_p(void *p1, void *p2, void *p3, void *z1, void *z2, void *z3, void *po1, void *po2, void *po3, real *beta, int *n)