Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
tensor.cu
Go to the documentation of this file.
1/*
2 Copyright (c) 2021-2023, 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/cuda/check.h>
37#include "tensor_kernel.h"
38#include <stdio.h>
39
40#define max(a,b) \
41 ({ __typeof__ (a) _a = (a); \
42 __typeof__ (b) _b = (b); \
43 _a > _b ? _a : _b; })
44
45template<const int N>
46static void set_tnsr3d_large_shmem_attr(const size_t shmem_size) {
47 static bool is_set = false;
48
49 if (!is_set) {
52 shmem_size));
53 is_set = true;
54 }
55}
56
57extern "C" {
58
60 void cuda_tnsr3d(void *v, int *nv, void *u, int *nu,
61 void *A, void *Bt, void *Ct, int *nel) {
62 const dim3 nthrds(1024, 1, 1);
63 const dim3 nblcks(*nel, 1, 1);
64 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
65
66 int n = max(*nu,*nv);
67#define CASE(N) \
68 case N: \
69 tnsr3d_kernel<real, N> \
70 <<<nblcks, nthrds, 0, stream>>>((real *) v, *nv, \
71 (real *) u, *nu, \
72 (real *) A, (real *) Bt, (real *) Ct); \
73 CUDA_CHECK(cudaGetLastError()); \
74 break
75
76#define CASE_LARGE(N) \
77 case N: { \
78 const size_t shmem_size = 2 * N * N * N * sizeof(real); \
79 set_tnsr3d_large_shmem_attr<N>(shmem_size); \
80 tnsr3d_kernel_large<real, N> \
81 <<<nblcks, nthrds, shmem_size, stream>>>((real *) v, *nv, \
82 (real *) u, *nu, \
83 (real *) A, (real *) Bt, \
84 (real *) Ct); \
85 CUDA_CHECK(cudaGetLastError()); \
86 } \
87 break
88
89 switch(n) {
90 CASE(2);
91 CASE(3);
92 CASE(4);
93 CASE(5);
94 CASE(6);
95 CASE(7);
96 CASE(8);
97 CASE(9);
98 CASE(10);
99 CASE(11);
100 CASE(12);
101 CASE(13);
102 CASE(14);
103 CASE_LARGE(15);
104 CASE_LARGE(16);
105 default:
106 {
107 fprintf(stderr, __FILE__ ": size not supported: %d\n", n);
108 exit(1);
109 }
110 }
111 }
112
114 void cuda_tnsr3d_el_list(void *v, int *nv, void *u, int *nu,
115 void *A, void *Bt, void *Ct, int * elements, int* n_points) {
116 const dim3 nthrds(1024, 1, 1);
117 const dim3 nblcks(*n_points, 1, 1);
118 const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
119
120 int n = max(*nu,*nv);
121#define CASE2(N) \
122 case N: \
123 tnsr3d_el_kernel<real, N> \
124 <<<nblcks, nthrds, 0, stream>>>((real *) v, *nv, \
125 (real *) u, *nu, \
126 (real *) A, (real *) Bt, (real *) Ct, \
127 (int *) elements, *n_points); \
128 CUDA_CHECK(cudaGetLastError()); \
129 break
130
131 switch(n) {
132 CASE2(2);
133 CASE2(3);
134 CASE2(4);
135 CASE2(5);
136 CASE2(6);
137 CASE2(7);
138 CASE2(8);
139 CASE2(9);
140 CASE2(10);
141 CASE2(11);
142 CASE2(12);
143 CASE2(13);
144 CASE2(14);
145 default:
146 {
147 fprintf(stderr, __FILE__ ": size not supported: %d\n", n);
148 exit(1);
149 }
150 }
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)
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
#define CUDA_CHECK(err)
Definition check.h:6
void cuda_tnsr3d(void *v, int *nv, void *u, int *nu, void *A, void *Bt, void *Ct, int *nel)
Definition tensor.cu:60
void cuda_tnsr3d_el_list(void *v, int *nv, void *u, int *nu, void *A, void *Bt, void *Ct, int *elements, int *n_points)
Definition tensor.cu:114
#define CASE(N)
#define CASE_LARGE(N)
#define CASE2(N)
static void set_tnsr3d_large_shmem_attr(const size_t shmem_size)
Definition tensor.cu:46
#define max(a, b)
Definition tensor.cu:40