Neko 0.9.99
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pnpn_res.c
Go to the documentation of this file.
1/*
2 Copyright (c) 2022, The Neko Authors
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13 * Neither the name of the authors nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifdef __APPLE__
31#include <OpenCL/cl.h>
32#else
33#include <CL/cl.h>
34#endif
35
36#include <stdio.h>
38#include <device/opencl/jit.h>
40#include <device/opencl/check.h>
41
42#include "pnpn_res_kernel.cl.h"
43
44void pnpn_prs_res_part1_opencl(void *ta1, void *ta2, void *ta3,
45 void *wa1, void *wa2, void *wa3,
46 void *f_u, void *f_v, void *f_w,
47 void *B, void *h1, real *mu,
48 real *rho, int *n) {
49 cl_int err;
50
53
55 "prs_res_part1_kernel", &err);
57
58 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &ta1));
59 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &ta2));
60 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &ta3));
61 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *) &wa1));
62 CL_CHECK(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *) &wa2));
63 CL_CHECK(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *) &wa3));
64 CL_CHECK(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *) &f_u));
65 CL_CHECK(clSetKernelArg(kernel, 7, sizeof(cl_mem), (void *) &f_v));
66 CL_CHECK(clSetKernelArg(kernel, 8, sizeof(cl_mem), (void *) &f_w));
67 CL_CHECK(clSetKernelArg(kernel, 9, sizeof(cl_mem), (void *) &B));
68 CL_CHECK(clSetKernelArg(kernel, 10, sizeof(cl_mem), (void *) &h1));
69 CL_CHECK(clSetKernelArg(kernel, 11, sizeof(real), mu));
70 CL_CHECK(clSetKernelArg(kernel, 12, sizeof(real), rho));
71 CL_CHECK(clSetKernelArg(kernel, 13, sizeof(int), n));
72
73 const int nb = ((*n) + 256 - 1) / 256;
74 const size_t global_item_size = 256 * nb;
75 const size_t local_item_size = 256;
76
79 0, NULL, NULL));
80}
81
82void pnpn_prs_res_part2_opencl(void *p_res, void *wa1, void *wa2,
83 void *wa3, int *n) {
84 cl_int err;
85
88
90 "prs_res_part2_kernel", &err);
92
93 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &p_res));
94 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &wa1));
95 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &wa2));
96 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *) &wa3));
97 CL_CHECK(clSetKernelArg(kernel, 4, sizeof(int), n));
98
99 const int nb = ((*n) + 256 - 1) / 256;
100 const size_t global_item_size = 256 * nb;
101 const size_t local_item_size = 256;
102
105 0, NULL, NULL));
106}
107
108void pnpn_prs_res_part3_opencl(void *p_res, void *ta1, void *ta2,
109 void *ta3, real *dtbd, int *n) {
110 cl_int err;
111
112 if (pnpn_res_program == NULL)
114
116 "prs_res_part3_kernel", &err);
117 CL_CHECK(err);
118
119 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &p_res));
120 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &ta1));
121 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &ta2));
122 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *) &ta3));
123 CL_CHECK(clSetKernelArg(kernel, 4, sizeof(real), dtbd));
124 CL_CHECK(clSetKernelArg(kernel, 5, sizeof(int), n));
125
126 const int nb = ((*n) + 256 - 1) / 256;
127 const size_t global_item_size = 256 * nb;
128 const size_t local_item_size = 256;
129
132 0, NULL, NULL));
133}
134
135void pnpn_vel_res_update_opencl(void *u_res, void *v_res, void *w_res,
136 void *ta1, void *ta2, void *ta3,
137 void *f_u, void *f_v, void *f_w, int *n) {
138 cl_int err;
139
140 if (pnpn_res_program == NULL)
142
144 "vel_res_update_kernel", &err);
145 CL_CHECK(err);
146
147 CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &u_res));
148 CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &v_res));
149 CL_CHECK(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *) &w_res));
150 CL_CHECK(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *) &ta1));
151 CL_CHECK(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *) &ta2));
152 CL_CHECK(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *) &ta3));
153 CL_CHECK(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *) &f_u));
154 CL_CHECK(clSetKernelArg(kernel, 7, sizeof(cl_mem), (void *) &f_v));
155 CL_CHECK(clSetKernelArg(kernel, 8, sizeof(cl_mem), (void *) &f_w));
156 CL_CHECK(clSetKernelArg(kernel, 9, sizeof(int), n));
157
158 const int nb = ((*n) + 256 - 1) / 256;
159 const size_t global_item_size = 256 * nb;
160 const size_t local_item_size = 256;
161
164 0, NULL, NULL));
165}
__global__ void T *__restrict__ T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ const T *__restrict__ h1
__global__ void dirichlet_apply_scalar_kernel(const int *__restrict__ msk, T *__restrict__ x, const T g, const int m)
double real
void opencl_kernel_jit(const char *kernel, cl_program *program)
Definition jit.c:50
#define CL_CHECK(err)
Definition check.h:12
void pnpn_prs_res_part3_opencl(void *p_res, void *ta1, void *ta2, void *ta3, real *dtbd, int *n)
Definition pnpn_res.c:108
void pnpn_prs_res_part1_opencl(void *ta1, void *ta2, void *ta3, void *wa1, void *wa2, void *wa3, void *f_u, void *f_v, void *f_w, void *B, void *h1, real *mu, real *rho, int *n)
Definition pnpn_res.c:44
void pnpn_prs_res_part2_opencl(void *p_res, void *wa1, void *wa2, void *wa3, int *n)
Definition pnpn_res.c:82
void pnpn_vel_res_update_opencl(void *u_res, void *v_res, void *w_res, void *ta1, void *ta2, void *ta3, void *f_u, void *f_v, void *f_w, int *n)
Definition pnpn_res.c:135
void * pnpn_res_program