Neko  0.8.99
A portable framework for high-order spectral element flow simulations
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 
35 #include <device/device_config.h>
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 
45 
46 extern "C" {
47 
49  void cuda_tnsr3d(void *v, int *nv, void *u, int *nu,
50  void *A, void *Bt, void *Ct, int *nel) {
51  const dim3 nthrds(1024, 1, 1);
52  const dim3 nblcks(*nel, 1, 1);
53  const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
54 
55  int n = max(*nu,*nv);
56 #define CASE(N) \
57  case N: \
58  tnsr3d_kernel<real, N> \
59  <<<nblcks, nthrds, 0, stream>>>((real *) v, *nv, \
60  (real *) u, *nu, \
61  (real *) A, (real *) Bt, (real *) Ct); \
62  CUDA_CHECK(cudaGetLastError()); \
63  break
64 
65 #define CASE_LARGE(N) \
66  case N: \
67  tnsr3d_kernel_large<real, N> \
68  <<<nblcks, nthrds, 0, stream>>>((real *) v, *nv, \
69  (real *) u, *nu, \
70  (real *) A, (real *) Bt, (real *) Ct); \
71  CUDA_CHECK(cudaGetLastError()); \
72  break
73 
74  switch(n) {
75  CASE(2);
76  CASE(3);
77  CASE(4);
78  CASE(5);
79  CASE(6);
80  CASE(7);
81  CASE(8);
82  CASE(9);
83  CASE(10);
84  CASE(11);
85  CASE(12);
86  CASE(13);
87  CASE(14);
88  CASE_LARGE(15);
89  CASE_LARGE(16);
90  default:
91  {
92  fprintf(stderr, __FILE__ ": size not supported: %d\n", n);
93  exit(1);
94  }
95  }
96  }
97 
99  void cuda_tnsr3d_el_list(void *v, int *nv, void *u, int *nu,
100  void *A, void *Bt, void *Ct, int * elements, int* n_points) {
101  const dim3 nthrds(1024, 1, 1);
102  const dim3 nblcks(*n_points, 1, 1);
103  const cudaStream_t stream = (cudaStream_t) glb_cmd_queue;
104 
105  int n = max(*nu,*nv);
106 #define CASE2(N) \
107  case N: \
108  tnsr3d_el_kernel<real, N> \
109  <<<nblcks, nthrds, 0, stream>>>((real *) v, *nv, \
110  (real *) u, *nu, \
111  (real *) A, (real *) Bt, (real *) Ct, \
112  (int *) elements, *n_points); \
113  CUDA_CHECK(cudaGetLastError()); \
114  break
115 
116  switch(n) {
117  CASE2(2);
118  CASE2(3);
119  CASE2(4);
120  CASE2(5);
121  CASE2(6);
122  CASE2(7);
123  CASE2(8);
124  CASE2(9);
125  CASE2(10);
126  CASE2(11);
127  CASE2(12);
128  CASE2(13);
129  CASE2(14);
130  default:
131  {
132  fprintf(stderr, __FILE__ ": size not supported: %d\n", n);
133  exit(1);
134  }
135  }
136  }
137 
138 }
__global__ void const T *__restrict__ u
Definition: conv1_kernel.h:132
__global__ void const T *__restrict__ const T *__restrict__ v
void * glb_cmd_queue
void cuda_tnsr3d(void *v, int *nv, void *u, int *nu, void *A, void *Bt, void *Ct, int *nel)
Definition: tensor.cu:49
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:99
#define CASE(N)
#define CASE_LARGE(N)
#define CASE2(N)
#define max(a, b)
Definition: tensor.cu:40