Neko  0.9.0
A portable framework for high-order spectral element flow simulations
scalar_residual.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>
37 #include <device/device_config.h>
38 #include <device/opencl/jit.h>
39 #include <device/opencl/prgm_lib.h>
40 #include <device/opencl/check.h>
41 
42 #include "scalar_residual_kernel.cl.h"
43 
44 
45 void scalar_residual_update_opencl(void *s_res, void *f_s, int *n) {
46  cl_int err;
47 
48  if (scalar_residual_program == NULL)
49  opencl_kernel_jit(scalar_residual_kernel, (cl_program *) &scalar_residual_program);
50 
51  cl_kernel kernel = clCreateKernel(scalar_residual_program,
52  "scalar_residual_update_kernel", &err);
53  CL_CHECK(err);
54 
55  CL_CHECK(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *) &s_res));
56  CL_CHECK(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *) &f_s));
57  CL_CHECK(clSetKernelArg(kernel, 2, sizeof(int), n));
58 
59  const int nb = ((*n) + 256 - 1) / 256;
60  const size_t global_item_size = 256 * nb;
61  const size_t local_item_size = 256;
62 
63  CL_CHECK(clEnqueueNDRangeKernel((cl_command_queue) glb_cmd_queue, kernel, 1,
64  NULL, &global_item_size, &local_item_size,
65  0, NULL, NULL));
66 }
void * glb_cmd_queue
void opencl_kernel_jit(const char *kernel, cl_program *program)
Definition: jit.c:50
#define CL_CHECK(err)
Definition: check.h:12
void * scalar_residual_program
void scalar_residual_update_opencl(void *s_res, void *f_s, int *n)