Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fusedcg_cpld_aux.hip
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 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
36#include <device/hip/check.h>
37#include <device/hip/buffer.h>
38#include "fusedcg_cpld_kernel.h"
39
45
46extern "C" {
47
50
51 void hip_fusedcg_cpld_part1(void *a1, void *a2, void *a3,
52 void *b1, void *b2, void *b3,
53 void *tmp, int *n) {
54
55 const dim3 nthrds(1024, 1, 1);
56 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
57 const hipStream_t stream = (hipStream_t) glb_cmd_queue;
58
60 nblcks, nthrds, 0, stream,
61 (real *) a1, (real *) a2, (real *) a3,
62 (real *) b1, (real *) b2, (real *) b3,
63 (real *) tmp, *n);
65 }
66
67 void hip_fusedcg_cpld_update_p(void *p1, void *p2, void *p3,
68 void *z1, void *z2, void *z3,
69 void *po1, void *po2, void *po3,
70 real *beta, int *n) {
71
72 const dim3 nthrds(1024, 1, 1);
73 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
74 const hipStream_t stream = (hipStream_t) glb_cmd_queue;
75
76
78 nblcks, nthrds, 0, stream,
79 (real *) p1, (real *) p2, (real *) p3,
80 (real *) z1, (real *) z2, (real *) z3,
81 (real *) po1, (real *) po2, (real *) po3,
82 *beta, *n);
84
85 }
86
87 void hip_fusedcg_cpld_update_x(void *x1, void *x2, void *x3,
88 void *p1, void *p2, void *p3,
89 void *alpha, int *p_cur, int *n) {
90
91 const dim3 nthrds(1024, 1, 1);
92 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
93 const hipStream_t stream = (hipStream_t) glb_cmd_queue;
94
95
97 nblcks, nthrds, 0, stream,
98 (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 hip_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 hipStream_t stream = (hipStream_t) glb_cmd_queue;
113
114 /* nb + 1 to fit the two-element host staging area for any nb */
118
119 /* Store alpha(p_cur) in pinned memory */
120 fusedcg_cpld_buf[1] = (*alpha);
121
122 /* Update alpha_d(p_cur) = alpha(p_cur) */
123 real *alpha_d_p_cur = ((real *) alpha_d) + ((*p_cur - 1));
126 stream));
127
129 nblcks, nthrds, 0, stream,
130 (real *) a1, (real *) a2, (real *) a3,
131 (real *) b, (real *) c1, (real *) c2,
132 (real *) c3, *alpha, fusedcg_cpld_buf_d,
133 *n);
135
137 1, 1024, 0, stream, fusedcg_cpld_buf_d, nb);
139
140#ifdef HAVE_DEVICE_MPI
143 sizeof(real), DEVICE_MPI_SUM);
144#else
146 hipMemcpyDeviceToHost, stream));
148#endif
149
150 return fusedcg_cpld_buf[0];
151 }
152}
153
__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)
double real
#define DEVICE_MPI_SUM
void device_mpi_allreduce(void *buf_d, void *buf, int count, int nbytes, int op)
void hip_fusedcg_cpld_update_x(void *x1, void *x2, void *x3, void *p1, void *p2, void *p3, void *alpha, int *p_cur, int *n)
hip_buffer_t fusedcg_cpld_redbuf
void hip_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)
real hip_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)
void hip_fusedcg_cpld_part1(void *a1, void *a2, void *a3, void *b1, void *b2, void *b3, void *tmp, int *n)
void hip_buffer_reserve(hip_buffer_t *buf, size_t size)
Definition buffer.hip:47
#define HIP_BUFFER_INIT
Definition buffer.h:61
#define HIP_CHECK(err)
Definition check.h:8
void * host
Definition buffer.h:52
void * dev
Definition buffer.h:53