Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
lpt_periodic_bc.c
Go to the documentation of this file.
1/*
2 Copyright (c) 2026, 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#ifdef __APPLE__
36#include <OpenCL/cl.h>
37#else
38#include <CL/cl.h>
39#endif
40
42#include <device/opencl/check.h>
43#include <device/opencl/jit.h>
46
47#include "lpt_periodic_bc_kernel.cl.h"
48
51 void *x, void *y, void *z, int *n, int *n_periodic_dirs,
52 real *periodic_dir_x1, real *periodic_dir_y1, real *periodic_dir_z1,
53 real *periodic_dir_x2, real *periodic_dir_y2, real *periodic_dir_z2,
54 real *periodic_dir_x3, real *periodic_dir_y3, real *periodic_dir_z3,
55 real *periodic_min1, real *periodic_min2, real *periodic_min3,
56 real *periodic_max1, real *periodic_max2, real *periodic_max3,
57 real *periodic_shift_x1, real *periodic_shift_y1,
58 real *periodic_shift_z1, real *periodic_shift_x2,
59 real *periodic_shift_y2, real *periodic_shift_z2,
60 real *periodic_shift_x3, real *periodic_shift_y3,
61 real *periodic_shift_z3, real *periodic_len1, real *periodic_len2,
62 real *periodic_len3, void *strm) {
63 cl_int err;
64
65 if (*n < 1) return;
66
70 }
71
74 "lpt_periodic_bc_wrap_translational_kernel", &err);
76
79 periodic_dir_x1, periodic_dir_y1, periodic_dir_z1,
80 periodic_dir_x2, periodic_dir_y2, periodic_dir_z2,
81 periodic_dir_x3, periodic_dir_y3, periodic_dir_z3,
82 periodic_min1, periodic_min2, periodic_min3,
83 periodic_max1, periodic_max2, periodic_max3,
84 periodic_shift_x1, periodic_shift_y1, periodic_shift_z1,
85 periodic_shift_x2, periodic_shift_y2, periodic_shift_z2,
86 periodic_shift_x3, periodic_shift_y3, periodic_shift_z3,
87 periodic_len1, periodic_len2, periodic_len3);
88
89 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &x));
90 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &y));
91 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &z));
92 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(int), n));
93 CL_CHECK(clSetKernelArg(kernel, 4, sizeof(int), n_periodic_dirs));
95 (void *) &prm));
96
97 const int nb = ((*n) + 256 - 1) / 256;
98 const size_t global_item_size = 256 * nb;
99 const size_t local_item_size = 256;
100
103 &local_item_size, 0, NULL, NULL));
104
106}
107
114 void *x, void *y, void *z, int *n,
116 void *u, void *v, void *w,
117 void *u_lag, void *v_lag, void *w_lag,
118 void *u_laglag, void *v_laglag, void *w_laglag,
119 void *acc_xlag, void *acc_ylag, void *acc_zlag,
120 void *acc_xlaglag, void *acc_ylaglag, void *acc_zlaglag,
121 void *strm) {
122 cl_int err;
123
124 if (*n < 1) return;
125
129 }
130
133 "lpt_periodic_bc_wrap_rotational_kernel", &err);
134 CL_CHECK(err);
135
136 int present_mask = 0;
137 if (u != NULL && v != NULL) present_mask |= 1;
138 if (u_lag != NULL && v_lag != NULL) present_mask |= 2;
139 if (u_laglag != NULL && v_laglag != NULL) present_mask |= 4;
140 if (acc_xlag != NULL && acc_ylag != NULL) present_mask |= 8;
141 if (acc_xlaglag != NULL && acc_ylaglag != NULL) present_mask |= 16;
142
143 /* Unbound slots still need a valid memory object */
144 void *pairs[10] = { u, v, u_lag, v_lag, u_laglag, v_laglag,
145 acc_xlag, acc_ylag, acc_xlaglag, acc_ylaglag };
146 for (int i = 0; i < 10; i++) {
147 if (pairs[i] == NULL) pairs[i] = x;
148 }
149
150 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &x));
151 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &y));
152 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &z));
153 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(int), n));
157 for (int i = 0; i < 10; i++) {
158 CL_CHECK(clSetKernelArg(kernel, 7 + i, sizeof(cl_mem),
159 (void *) &pairs[i]));
160 }
161 CL_CHECK(clSetKernelArg(kernel, 17, sizeof(int), (void *) &present_mask));
162
163 const int nb = ((*n) + 256 - 1) / 256;
164 const size_t global_item_size = 256 * nb;
165 const size_t local_item_size = 256;
166
169 &local_item_size, 0, NULL, NULL));
170
172}
__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__ const T *__restrict__ const T *__restrict__ w
const int i
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ u
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ v
__global__ void const T *__restrict__ x
double real
void opencl_kernel_jit(const char *kernel, cl_program *program)
Definition jit.c:50
void opencl_lpt_periodic_bc_wrap_translational(void *x, void *y, void *z, int *n, int *n_periodic_dirs, real *periodic_dir_x1, real *periodic_dir_y1, real *periodic_dir_z1, real *periodic_dir_x2, real *periodic_dir_y2, real *periodic_dir_z2, real *periodic_dir_x3, real *periodic_dir_y3, real *periodic_dir_z3, real *periodic_min1, real *periodic_min2, real *periodic_min3, real *periodic_max1, real *periodic_max2, real *periodic_max3, real *periodic_shift_x1, real *periodic_shift_y1, real *periodic_shift_z1, real *periodic_shift_x2, real *periodic_shift_y2, real *periodic_shift_z2, real *periodic_shift_x3, real *periodic_shift_y3, real *periodic_shift_z3, real *periodic_len1, real *periodic_len2, real *periodic_len3, void *strm)
void opencl_lpt_periodic_bc_wrap_rotational(void *x, void *y, void *z, int *n, real *theta_min, real *theta_max, real *theta_len, void *u, void *v, void *w, void *u_lag, void *v_lag, void *w_lag, void *u_laglag, void *v_laglag, void *w_laglag, void *acc_xlag, void *acc_ylag, void *acc_zlag, void *acc_xlaglag, void *acc_ylaglag, void *acc_zlaglag, void *strm)
static void lpt_periodic_params_pack(lpt_periodic_params *prm, const real *dir_x1, const real *dir_y1, const real *dir_z1, const real *dir_x2, const real *dir_y2, const real *dir_z2, const real *dir_x3, const real *dir_y3, const real *dir_z3, const real *min1, const real *min2, const real *min3, const real *max1, const real *max2, const real *max3, const real *shift_x1, const real *shift_y1, const real *shift_z1, const real *shift_x2, const real *shift_y2, const real *shift_z2, const real *shift_x3, const real *shift_y3, const real *shift_z3, const real *len1, const real *len2, const real *len3)
#define CL_CHECK(err)
Definition check.h:12
void * lpt_periodic_bc_program