Neko 1.99.6
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
metal_intf.F90
Go to the documentation of this file.
1! Copyright (c) 2025, The Neko Authors
2! All rights reserved.
3!
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!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use utils, only : neko_error
36 use, intrinsic :: iso_c_binding
37 implicit none
38
39#ifdef HAVE_METAL
40
42 integer, parameter :: metalSuccess = 0
43
44 interface
45
47 integer(c_int) function metalalloc(ptr_d, s) &
48 bind(c, name = 'metal_alloc')
49 use, intrinsic :: iso_c_binding
50 implicit none
51 type(c_ptr) :: ptr_d
52 integer(c_size_t), value :: s
53 end function metalalloc
54
57 integer(c_int) function metalmap(ptr_d, ptr_h, s) &
58 bind(c, name = 'metal_map')
59 use, intrinsic :: iso_c_binding
60 implicit none
61 type(c_ptr) :: ptr_d
62 type(c_ptr), value :: ptr_h
63 integer(c_size_t), value :: s
64 end function metalmap
65
67 integer(c_int) function metalfree(ptr_d) &
68 bind(c, name = 'metal_free')
69 use, intrinsic :: iso_c_binding
70 implicit none
71 type(c_ptr), value :: ptr_d
72 end function metalfree
73
75 integer(c_int) function metalmemcpyhtod(dst_d, src, s) &
76 bind(c, name = 'metal_memcpy_htod')
77 use, intrinsic :: iso_c_binding
78 implicit none
79 type(c_ptr), value :: dst_d, src
80 integer(c_size_t), value :: s
81 end function metalmemcpyhtod
82
84 integer(c_int) function metalmemcpydtoh(dst, src_d, s) &
85 bind(c, name = 'metal_memcpy_dtoh')
86 use, intrinsic :: iso_c_binding
87 implicit none
88 type(c_ptr), value :: dst, src_d
89 integer(c_size_t), value :: s
90 end function metalmemcpydtoh
91
93 integer(c_int) function metalmemcpydtod(dst_d, src_d, s) &
94 bind(c, name = 'metal_memcpy_dtod')
95 use, intrinsic :: iso_c_binding
96 implicit none
97 type(c_ptr), value :: dst_d, src_d
98 integer(c_size_t), value :: s
99 end function metalmemcpydtod
100
102 integer(c_int) function metalmemset(buf_d, v, s) &
103 bind(c, name = 'metal_memset')
104 use, intrinsic :: iso_c_binding
105 implicit none
106 type(c_ptr), value :: buf_d
107 integer(c_int), value :: v
108 integer(c_size_t), value :: s
109 end function metalmemset
110
112 integer(c_int) function metaldevicesynchronize() &
113 bind(c, name = 'metal_device_sync')
114 use, intrinsic :: iso_c_binding
115 implicit none
116 end function metaldevicesynchronize
117
119 integer(c_int) function metalstreamsynchronize(stream) &
120 bind(c, name = 'metal_stream_sync')
121 use, intrinsic :: iso_c_binding
122 implicit none
123 type(c_ptr), value :: stream
124 end function metalstreamsynchronize
125
127 integer(c_int) function metalstreamcreate(stream) &
128 bind(c, name = 'metal_stream_create')
129 use, intrinsic :: iso_c_binding
130 implicit none
131 type(c_ptr) :: stream
132 end function metalstreamcreate
133
135 integer(c_int) function metalstreamdestroy(stream) &
136 bind(c, name = 'metal_stream_destroy')
137 use, intrinsic :: iso_c_binding
138 implicit none
139 type(c_ptr), value :: stream
140 end function metalstreamdestroy
141
143 integer(c_int) function metaleventcreate(event) &
144 bind(c, name = 'metal_event_create')
145 use, intrinsic :: iso_c_binding
146 implicit none
147 type(c_ptr) :: event
148 end function metaleventcreate
149
151 integer(c_int) function metaleventdestroy(event) &
152 bind(c, name = 'metal_event_destroy')
153 use, intrinsic :: iso_c_binding
154 implicit none
155 type(c_ptr), value :: event
156 end function metaleventdestroy
157
159 integer(c_int) function metaleventrecord(event, stream) &
160 bind(c, name = 'metal_event_record')
161 use, intrinsic :: iso_c_binding
162 implicit none
163 type(c_ptr), value :: event, stream
164 end function metaleventrecord
165
167 integer(c_int) function metaleventsynchronize(event) &
168 bind(c, name = 'metal_event_sync')
169 use, intrinsic :: iso_c_binding
170 implicit none
171 type(c_ptr), value :: event
172 end function metaleventsynchronize
173
175 integer(c_int) function metalstreamwaitevent(stream, event) &
176 bind(c, name = 'metal_stream_wait_event')
177 use, intrinsic :: iso_c_binding
178 implicit none
179 type(c_ptr), value :: stream, event
180 end function metalstreamwaitevent
181
183 subroutine metal_device_name_c(name, len) &
184 bind(c, name = 'metal_device_name')
185 use, intrinsic :: iso_c_binding
186 implicit none
187 type(c_ptr), value :: name
188 integer(c_int), value :: len
189 end subroutine metal_device_name_c
190
192 integer(c_int) function metal_device_count_c() &
193 bind(c, name = 'metal_device_count')
194 use, intrinsic :: iso_c_binding
195 implicit none
196 end function metal_device_count_c
197
198 end interface
199
200contains
201
203 subroutine metal_init(glb_cmd_queue, aux_cmd_queue)
204 type(c_ptr), intent(inout) :: glb_cmd_queue
205 type(c_ptr), intent(inout) :: aux_cmd_queue
206
207 interface
208 subroutine metal_init_c(glb_q, aux_q) &
209 bind(c, name = 'metal_init')
210 use, intrinsic :: iso_c_binding
211 implicit none
212 type(c_ptr) :: glb_q
213 type(c_ptr) :: aux_q
214 end subroutine metal_init_c
215 end interface
216
217 call metal_init_c(glb_cmd_queue, aux_cmd_queue)
218 end subroutine metal_init
219
221 subroutine metal_finalize(glb_cmd_queue, aux_cmd_queue)
222 type(c_ptr), intent(inout) :: glb_cmd_queue
223 type(c_ptr), intent(inout) :: aux_cmd_queue
224
225 interface
226 subroutine metal_finalize_c(glb_q, aux_q) &
227 bind(c, name = 'metal_finalize')
228 use, intrinsic :: iso_c_binding
229 implicit none
230 type(c_ptr), value :: glb_q
231 type(c_ptr), value :: aux_q
232 end subroutine metal_finalize_c
233 end interface
234
235 call metal_finalize_c(glb_cmd_queue, aux_cmd_queue)
236 end subroutine metal_finalize
237
239 subroutine metal_device_name(name)
240 character(len=*), intent(inout) :: name
241 character(kind=c_char, len=256), target :: c_name
242 integer :: end_pos
243
244 call metal_device_name_c(c_loc(c_name), 256)
245
246 end_pos = scan(c_name, c_null_char)
247 if (end_pos .ge. 2) then
248 name(1:end_pos-1) = c_name(1:end_pos-1)
249 end if
250 end subroutine metal_device_name
251
253 integer function metal_device_count()
254 metal_device_count = metal_device_count_c()
255 end function metal_device_count
256
257#endif
258
259end module metal_intf
Fortran interface to the Metal device layer (see device/metal/metal.m)
Utilities.
Definition utils.f90:35