Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pipecg_aux.hip
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-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 "pipecg_kernel.h"
39
47int buf_len = 0;
48
49extern "C" {
50
51 void hip_cg_update_xp(void *x, void *p, void *u, void *alpha, void *beta,
52 int *p_cur, int *p_space, int *n) {
53
54 const dim3 nthrds(1024, 1, 1);
55 const dim3 nblcks(((*n) + 1024 - 1) / 1024, 1, 1);
56
58 nblcks, nthrds, 0, (hipStream_t) glb_cmd_queue,
59 (real *) x, (real *) p, (real **) u, (real *) alpha,
60 (real *) beta, *p_cur, *p_space, *n);
62 }
63
64 void hip_pipecg_vecops(void *p, void *q, void *r, void *s, void *u1,
65 void *u2, void *w, void *z,
66 void *ni, void *mi, real *alpha,
67 real *beta, void *mult,
68 real *reduction, int *n) {
69
70 const dim3 nthrds(1024, 1, 1);
71 const dim3 nblcks(((*n) + 1024 - 1)/ 1024, 1, 1);
72 const int nb = ((*n) + 1024 - 1)/ 1024;
73 const hipStream_t stream = (hipStream_t) glb_cmd_queue;
74
75 if (buf != NULL && buf_len < nb) {
80 buf = NULL;
81 }
82
83 if (buf == NULL){
84 HIP_CHECK(hipHostMalloc(&buf, nb*sizeof(real)));
85 HIP_CHECK(hipMalloc(&buf_d1, nb*sizeof(real)));
86 HIP_CHECK(hipMalloc(&buf_d2, nb*sizeof(real)));
87 HIP_CHECK(hipMalloc(&buf_d3, nb*sizeof(real)));
88 buf_len = nb;
89 }
90
92 nblcks, nthrds, 0, stream,
93 (real *) p, (real *) q, (real *) r, (real *) s,
94 (real *) u1, (real *) u2, (real *) w, (real *) z,
95 (real *) ni, (real *) mi, *alpha, *beta,
96 (real *) mult, buf_d1, buf_d2, buf_d3, *n);
98
100 1, 1024, 0 , stream, buf_d1, nb);
103 1, 1024, 0 , stream, buf_d2, nb);
106 1, 1024, 0 , stream, buf_d3, nb);
108
109 HIP_CHECK(hipMemcpyAsync(&buf[0], buf_d1, sizeof(real),
110 hipMemcpyDeviceToHost, stream));
112 HIP_CHECK(hipMemcpyAsync(&buf[1], buf_d2, sizeof(real),
113 hipMemcpyDeviceToHost, stream));
115 HIP_CHECK(hipMemcpyAsync(&buf[2], buf_d3, sizeof(real),
116 hipMemcpyDeviceToHost, stream));
118
120
121 reduction[0] = buf[0];
122 reduction[1] = buf[1];
123 reduction[2] = buf[2];
124
125 }
126}
__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__ u
__global__ void const T *__restrict__ x
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
double real
#define HIP_CHECK(err)
Definition check.h:8
real * buf
void hip_cg_update_xp(void *x, void *p, void *u, void *alpha, void *beta, int *p_cur, int *p_space, int *n)
void hip_pipecg_vecops(void *p, void *q, void *r, void *s, void *u1, void *u2, void *w, void *z, void *ni, void *mi, real *alpha, real *beta, void *mult, real *reduction, int *n)
int buf_len
real * buf_d2
real * buf_d1
real * buf_d3