Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
kernel_utils.h
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#ifndef __DEVICE_METAL_KERNEL_UTILS_H__
36#define __DEVICE_METAL_KERNEL_UTILS_H__
37
38#ifdef __APPLE__
39
40#import <Metal/Metal.h>
41
44extern void *glb_cmd_queue;
45
46/* ------------------------------------------------------------------ */
47/* Pipeline state cache (one per translation unit) */
48/* ------------------------------------------------------------------ */
49
52
60 }
62 if (!pso) {
64 NSError *err = nil;
67 if (!fn) {
68 NSLog(@"Metal: kernel '%@' not found in library", name);
69 abort();
70 }
72 if (err) {
73 NSLog(@"Metal: pipeline error for '%@': %@", name, err);
74 abort();
75 }
77 }
78 return pso;
79}
80
81/* ------------------------------------------------------------------ */
82/* Dispatch helper */
83/* ------------------------------------------------------------------ */
84
85#define NEKO_METAL_NTHREADS 1024
86
91static inline void
95 NSUInteger n) {
96 if (n == 0) return;
101 encode(enc);
102 MTLSize threads = MTLSizeMake(n, 1, 1);
104 MTLSize tg = MTLSizeMake(tpg, 1, 1);
107 [cb commit];
109 }
110}
111
117static inline void
121 if (ngroups == 0) return;
124 (__bridge id<MTLCommandQueue>) glb_cmd_queue;
128 encode(enc);
132 [cb commit];
134 }
135}
136
141static inline void
143 void (^encode)(id<MTLComputeCommandEncoder>),
144 NSUInteger n) {
146 (__bridge id<MTLCommandQueue>) glb_cmd_queue, pso, encode, n);
147}
148
149#endif /* __APPLE__ */
150#endif /* __DEVICE_METAL_KERNEL_UTILS_H__ */
__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)
type(c_ptr), bind(C), public glb_cmd_queue
Global command queue.
Definition device.F90:52