Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pipecg_aux.cu
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 "pipecg_kernel.h"
37#include <device/cuda/check.h>
38
46int buf_len = 0;
47
48extern "C" {
49
50 void cuda_cg_update_xp(void *x, void *p, void *u, void *alpha, void *beta,
51 int *p_cur, int *p_space, int *n) {
52
53 const dim3 nthrds(1024, 1, 1);
54 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
55 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
56
58 <<<nblcks, nthrds, 0, stream>>>((real *) x, (real *) p,
59 (real **) u, (real *) alpha,
60 (real *) beta, *p_cur, *p_space, *n);
62
63 }
64
65 void cuda_pipecg_vecops(void *p, void *q, void *r, void *s, void *u1,
66 void *u2, void *w, void *z,
67 void *ni, void *mi, real *alpha,
68 real *beta, void *mult,
69 real *reduction, int *n) {
70
71 const dim3 nthrds(1024, 1, 1);
72 const dim3 nblcks(((*n)+1024 - 1)/ 1024, 1, 1);
73 const int nb = ((*n) + 1024 - 1)/ 1024;
74 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
75
76 if (buf != NULL && buf_len < nb) {
81 buf = NULL;
82 }
83
84 if (buf == NULL){
85 CUDA_CHECK(cudaMallocHost(&buf, 3*sizeof(real)));
89 buf_len = nb;
90 }
91
93 <<<nblcks, nthrds, 0, stream>>>((real *) p, (real *) q,
94 (real *) r, (real *) s,
95 (real *) u1, (real *) u2,
96 (real *) w, (real *) z,
97 (real *) ni, (real *) mi,
98 *alpha, *beta, (real *)mult,
99 buf_d1, buf_d2, buf_d3, *n);
100
102
103 reduce_kernel<real><<<1, 1024, 0, stream>>>(buf_d1, nb);
105 reduce_kernel<real><<<1, 1024, 0, stream>>>(buf_d2, nb);
107 reduce_kernel<real><<<1, 1024, 0, stream>>>(buf_d3, nb);
109
111 cudaMemcpyDeviceToHost, stream));
114 cudaMemcpyDeviceToHost, stream));
117 cudaMemcpyDeviceToHost, stream));
119
121
122 reduction[0] = buf[0];
123 reduction[1] = buf[1];
124 reduction[2] = buf[2];
125
126 }
127}
128
__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
#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
void cuda_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)
Definition pipecg_aux.cu:65
real * buf
Definition pipecg_aux.cu:42
int buf_len
Definition pipecg_aux.cu:46
void cuda_cg_update_xp(void *x, void *p, void *u, void *alpha, void *beta, int *p_cur, int *p_space, int *n)
Definition pipecg_aux.cu:50
real * buf_d2
Definition pipecg_aux.cu:44
real * buf_d1
Definition pipecg_aux.cu:43
real * buf_d3
Definition pipecg_aux.cu:45