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