Neko 1.1.0
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
projection.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 <hip/hip_runtime.h>
37#include <device/hip/check.h>
38#include <device/hip/buffer.h>
39#include <device/hip/unified.h>
40
41#include "projection_kernel.h"
43
44
45/*
46 * Device-only reduction buffer, owned by the device layer and
47 * released on device teardown (hip_buffer_free_all in hip_finalize)
48 */
50
51extern "C" {
52
55
56 void hip_project_on(void *alpha, void * b, void *xx, void *bb, void *mult,
57 void *xbar, int *j, int *n){
58
59 int pow2 = 1;
60 while(pow2 < (*j)){
61 pow2 = 2*pow2;
62 }
63 const int nt = 1024/pow2;
64 const dim3 glsc3_nthrds(pow2, nt, 1);
65 const dim3 glsc3_nblcks(((*n)+nt - 1)/nt, 1, 1);
66 const int glsc3_nb = ((*n) + nt - 1)/nt;
69
70 /* First glsc3_many call */
73 0, (hipStream_t) glb_cmd_queue,
74 (const real *) b, (const real **) xx,
75 (const real *) mult, proj_bufred_d, *j, *n);
78 (*j), 1024, 0 , (hipStream_t) glb_cmd_queue,
81 HIP_CHECK(hipMemcpyAsync(alpha, proj_bufred_d, (*j) * sizeof(real),
83 (hipStream_t) glb_cmd_queue));
84 if (hip_zerocopy()) {
85 /* xbar may alias pageable host memory, which hipMemset rejects;
86 zero with a kernel instead (works on any pointer) */
87 const dim3 zero_nthrds(1024, 1, 1);
88 const dim3 zero_nblcks((*n) > 0 ? ((*n) + 1024 - 1) / 1024 : 1, 1, 1);
89
92 (hipStream_t) glb_cmd_queue,
93 (real *) xbar, (real) 0.0, *n);
95 }
96 else {
97 HIP_CHECK(hipMemsetAsync(xbar, 0, (*n) * sizeof(real)));
98 }
99
102
103 const dim3 vec_nthrds(1024, 1, 1);
104 const dim3 vec_nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
105
106 /* First vector operation block */
109 0, (hipStream_t) glb_cmd_queue, (real *) xbar,
110 (const real **) xx, (real *) b, (const real **) bb,
111 (const real *) alpha, *j, *n);
112 /* Second glsc3_many call */
115 0, (hipStream_t) glb_cmd_queue,
116 (const real *) b, (const real **) xx,
117 (const real *) mult, proj_bufred_d, *j, *n);
120 (*j), 1024, 0, (hipStream_t) glb_cmd_queue,
123 HIP_CHECK(hipMemcpyAsync(alpha, proj_bufred_d, (*j) * sizeof(real),
125 (hipStream_t) glb_cmd_queue));
126
129
130 /* Second vector operation block */
133 0, (hipStream_t) glb_cmd_queue, (real *) xbar,
134 (const real **) xx, (real *) b, (const real **) bb,
135 (const real *) alpha, *j, *n);
136 }
137
138 void hip_project_ortho(void *alpha, void * b, void *xx, void *bb,
139 void *w, void *xm, int *j, int *n, real *nrm){
140
141 int pow2 = 1;
142 while(pow2 < (*j)){
143 pow2 = 2*pow2;
144 }
145 const int nt = 1024/pow2;
146 const dim3 glsc3_nthrds(pow2, nt, 1);
147 const dim3 glsc3_nblcks(((*n)+nt - 1)/nt, 1, 1);
148 const int glsc3_nb = ((*n) + nt - 1)/nt;
151
152 /* First glsc3_many call */
155 0, (hipStream_t) glb_cmd_queue,
156 (const real *) b, (const real **) xx,
157 (const real *) w, proj_bufred_d, *j, *n);
160 (*j), 1024, 0 , (hipStream_t) glb_cmd_queue,
163 HIP_CHECK(hipMemcpyAsync(alpha, proj_bufred_d, (*j) * sizeof(real),
165 (hipStream_t) glb_cmd_queue));
166
169
170 HIP_CHECK(hipMemcpyAsync(nrm, (real *) alpha + (*j - 1),
172 (hipStream_t) glb_cmd_queue));
173 (*nrm) = sqrt(*nrm);
174
175
176 const dim3 vec_nthrds(1024, 1, 1);
177 const dim3 vec_nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
178
179 /* First vector operation block */
181 vec_nblcks, vec_nthrds, 0, (hipStream_t) glb_cmd_queue,
182 (real *) xm, (const real **) xx,
183 (real *) b, (const real **) bb,
184 (const real *) alpha, *j, *n);
185
186 /* Second glsc3_many call */
188 glsc3_nblcks, glsc3_nthrds, 0, (hipStream_t) glb_cmd_queue,
189 (const real *) b, (const real **) xx,
190 (const real *) w, proj_bufred_d, *j, *n);
193 (*j), 1024, 0 , (hipStream_t) glb_cmd_queue,
196 HIP_CHECK(hipMemcpyAsync(alpha, proj_bufred_d, (*j) * sizeof(real),
198 (hipStream_t) glb_cmd_queue));
199
202
203 /* Second vector operation block */
205 vec_nblcks, vec_nthrds, 0, (hipStream_t) glb_cmd_queue,
206 (real *) xm, (const real **) xx,
207 (real *) b, (const real **) bb,
208 (const real *) alpha, *j, *n);
209
210 }
211
212}
213
__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__ w
const int j
double real
#define DEVICE_MPI_SUM
void device_mpi_allreduce_inplace(void *buf_d, int count, int nbytes, int op)
void hip_buffer_reserve(hip_buffer_t *buf, size_t size)
Definition buffer.hip:47
#define HIP_BUFFER_INIT_DEV
Definition buffer.h:62
#define HIP_CHECK(err)
Definition check.h:8
hip_buffer_t proj_bufred
void hip_project_ortho(void *alpha, void *b, void *xx, void *bb, void *w, void *xm, int *j, int *n, real *nrm)
void hip_project_on(void *alpha, void *b, void *xx, void *bb, void *mult, void *xbar, int *j, int *n)
void * dev
Definition buffer.h:53
int hip_zerocopy(void)
Definition unified.hip:122