Neko-TOP
A portable framework for high-order spectral element flow toplogy optimization.
Loading...
Searching...
No Matches
math_ext.hip
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// System includes
36#include <stdio.h>
37#include <stdlib.h>
38
39// Device includes
40#include <hip/hip_runtime.h>
41
42// Neko includes
43#include <neko/device/device_config.h>
44#include <neko/device/hip/check.h>
45#include <neko/math/bcknd/device/device_mpi_op.h>
46#include <neko/math/bcknd/device/device_mpi_reduce.h>
47
48// Local includes
49#include "math_ext_kernel.h"
50
51extern "C" {
52
56void hip_copy_mask(void* a, void* b, int* size, int* mask, int* mask_size) {
57 const dim3 nthrds(1024, 1, 1);
58 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
59
60 if(*mask_size == 0) return;
61 hipLaunchKernelGGL(copy_mask_kernel<real>, nblcks, nthrds, 0,
62 (hipStream_t)glb_cmd_queue,
63 (real*)a, (real*)b, *size, mask, *mask_size);
64 HIP_CHECK(hipGetLastError());
65}
66
70void hip_cadd_mask(void* a, real* c, int* size, int* mask, int* mask_size) {
71 const dim3 nthrds(1024, 1, 1);
72 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
73
74 if(*mask_size == 0) return;
75 hipLaunchKernelGGL(cadd_mask_kernel<real>, nblcks, nthrds, 0,
76 (hipStream_t)glb_cmd_queue, (real*)a, *c, *size, mask, *mask_size);
77 HIP_CHECK(hipGetLastError());
78}
79
83void hip_invcol1_mask(void* a, int* size, int* mask, int* mask_size) {
84 const dim3 nthrds(1024, 1, 1);
85 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
86
87 if(*mask_size == 0) return;
88 hipLaunchKernelGGL(invcol1_mask_kernel<real>, nblcks, nthrds, 0,
89 (hipStream_t)glb_cmd_queue, (real*)a, *size, mask, *mask_size);
90 HIP_CHECK(hipGetLastError());
91}
92
96void hip_col2_mask(void* a, void* b, int* size, int* mask, int* mask_size) {
97 const dim3 nthrds(1024, 1, 1);
98 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
99
100 if(*mask_size == 0) return;
101 hipLaunchKernelGGL(col2_mask_kernel<real>, nblcks, nthrds, 0,
102 (hipStream_t)glb_cmd_queue,
103 (real*)a, (real*)b, *size, mask, *mask_size);
104 HIP_CHECK(hipGetLastError());
105}
106
110void hip_col3_mask(
111 void* a, void* b, void* c, int* size, int* mask, int* mask_size) {
112
113 const dim3 nthrds(1024, 1, 1);
114 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
115
116 if(*mask_size == 0) return;
117 hipLaunchKernelGGL(col3_mask_kernel<real>, nblcks, nthrds, 0,
118 (hipStream_t)glb_cmd_queue,
119 (real*)a, (real*)b, (real*)c, *size, mask, *mask_size);
120 HIP_CHECK(hipGetLastError());
121}
122
126void hip_sub3_mask(
127 void* a, void* b, void* c, int* size, int* mask, int* mask_size) {
128
129 const dim3 nthrds(1024, 1, 1);
130 const dim3 nblcks(((*mask_size) + 1024 - 1) / 1024, 1, 1);
131
132 if(*mask_size == 0) return;
133 hipLaunchKernelGGL(sub3_mask_kernel<real>, nblcks, nthrds, 0,
134 (hipStream_t)glb_cmd_queue,
135 (real*)a, (real*)b, (real*)c, *size, mask, *mask_size);
136 HIP_CHECK(hipGetLastError());
137}
138}