36 use,
intrinsic :: iso_c_binding
72 integer(c_int) function cudamalloc(ptr_d, s) &
73 bind(c, name =
'cudaMalloc')
74 use,
intrinsic :: iso_c_binding
77 integer(c_size_t),
value :: s
78 end function cudamalloc
82 integer(c_int) function cudafree(ptr_d) &
83 bind(c, name =
'cudaFree')
84 use,
intrinsic :: iso_c_binding
86 type(c_ptr),
value :: ptr_d
91 integer(c_int) function cudamemcpy(ptr_dst, ptr_src, s, dir) &
92 bind(c, name =
'cudaMemcpy')
93 use,
intrinsic :: iso_c_binding
95 type(c_ptr),
value :: ptr_dst, ptr_src
96 integer(c_size_t),
value :: s
97 integer(c_int),
value :: dir
98 end function cudamemcpy
102 integer(c_int) function cudamemcpyasync(ptr_dst, ptr_src, s, dir, stream) &
103 bind(c, name =
'cudaMemcpyAsync')
104 use,
intrinsic :: iso_c_binding
106 type(c_ptr),
value :: ptr_dst, ptr_src, stream
107 integer(c_size_t),
value :: s
108 integer(c_int),
value :: dir
109 end function cudamemcpyasync
113 integer(c_int) function cudadevicesynchronize() &
114 bind(c, name =
'cudaDeviceSynchronize')
115 use,
intrinsic :: iso_c_binding
117 end function cudadevicesynchronize
121 integer(c_int) function cudagetdeviceproperties(prop, device) &
122 bind(c, name =
'cudaGetDeviceProperties')
123 use,
intrinsic :: iso_c_binding
125 type(c_ptr),
value :: prop
126 integer(c_int),
value ::
device
127 end function cudagetdeviceproperties
131 integer(c_int) function cudastreamcreate(stream) &
132 bind(c, name =
'cudaStreamCreate')
133 use,
intrinsic :: iso_c_binding
135 type(c_ptr) :: stream
136 end function cudastreamcreate
140 integer(c_int) function cudastreamcreatewithflags(stream, flags) &
141 bind(c, name =
'cudaStreamCreateWithFlags')
142 use,
intrinsic :: iso_c_binding
144 type(c_ptr) :: stream
145 integer(c_int),
value :: flags
146 end function cudastreamcreatewithflags
150 integer(c_int) function cudastreamcreatewithpriority(stream, flags, prio) &
151 bind(c, name =
'cudaStreamCreateWithPriority')
152 use,
intrinsic :: iso_c_binding
154 type(c_ptr) :: stream
155 integer(c_int),
value :: flags, prio
156 end function cudastreamcreatewithpriority
160 integer(c_int) function cudastreamdestroy(steam) &
161 bind(c, name =
'cudaStreamDestroy')
162 use,
intrinsic :: iso_c_binding
164 type(c_ptr),
value :: steam
165 end function cudastreamdestroy
169 integer(c_int) function cudastreamsynchronize(stream) &
170 bind(c, name =
'cudaStreamSynchronize')
171 use,
intrinsic :: iso_c_binding
173 type(c_ptr),
value :: stream
174 end function cudastreamsynchronize
178 integer(c_int) function cudastreamwaitevent(stream, event, flags) &
179 bind(c, name =
'cudaStreamWaitEvent')
180 use,
intrinsic :: iso_c_binding
182 type(c_ptr),
value :: stream, event
183 integer(c_int),
value :: flags
184 end function cudastreamwaitevent
188 integer(c_int) function cudadevicegetstreampriorityrange &
189 (low_prio, high_prio) &
190 bind(c, name =
'cudaDeviceGetStreamPriorityRange')
191 use,
intrinsic :: iso_c_binding
193 integer(c_int) :: low_prio, high_prio
194 end function cudadevicegetstreampriorityrange
198 integer(c_int) function cudaprofilerstart() &
199 bind(c, name =
'cudaProfilerStart')
200 use,
intrinsic :: iso_c_binding
202 end function cudaprofilerstart
206 integer(c_int) function cudaprofilerstop() &
207 bind(c, name =
'cudaProfilerStop')
208 use,
intrinsic :: iso_c_binding
210 end function cudaprofilerstop
214 integer(c_int) function cudaeventcreate(event) &
215 bind(c, name =
'cudaEventCreate')
216 use,
intrinsic :: iso_c_binding
219 end function cudaeventcreate
223 integer(c_int) function cudaeventdestroy(event) &
224 bind(c, name =
'cudaEventDestroy')
225 use,
intrinsic :: iso_c_binding
227 type(c_ptr),
value :: event
228 end function cudaeventdestroy
232 integer(c_int) function cudaeventcreatewithflags(event, flags) &
233 bind(c, name =
'cudaEventCreateWithFlags')
234 use,
intrinsic :: iso_c_binding
237 integer(c_int),
value :: flags
238 end function cudaeventcreatewithflags
242 integer(c_int) function cudaeventrecord(event, stream) &
243 bind(c, name =
'cudaEventRecord')
244 use,
intrinsic :: iso_c_binding
246 type(c_ptr),
value :: event, stream
247 end function cudaeventrecord
251 integer(c_int) function cudaeventsynchronize(event) &
252 bind(c, name =
'cudaEventSynchronize')
253 use,
intrinsic :: iso_c_binding
255 type(c_ptr),
value :: event
256 end function cudaeventsynchronize
260 integer(c_int) function cudagetdevicecount(device_count) &
261 bind(c, name =
'cudaGetDeviceCount')
262 use,
intrinsic :: iso_c_binding
264 integer(c_int) :: device_count
265 end function cudagetdevicecount
269 integer(c_int) function cudagetdevice(device) &
270 bind(c, name =
'cudaGetDevice')
271 use,
intrinsic :: iso_c_binding
274 end function cudagetdevice
278 integer(c_int) function cudasetdevice(device) &
279 bind(c, name =
'cudaSetDevice')
280 use,
intrinsic :: iso_c_binding
282 integer(c_int),
value ::
device
283 end function cudasetdevice
289 integer(c_int) :: device_id
290 integer :: nthrds = 1
299 if (nthrds .gt. 1)
then
300 if (cudagetdevice(device_id) .ne.
cudasuccess)
then
305 if (cudasetdevice(device_id) .ne.
cudasuccess)
then
313 call neko_error(
'Error retrieving stream priority range')
329 call neko_error(
'Error destroying main stream')
333 call neko_error(
'Error destroying aux stream')
338 character(len=*),
intent(inout) :: name
339 character(kind=c_char, len=8192),
target :: prop
351 if (cudagetdeviceproperties(c_loc(prop), 0) .ne.
cudasuccess)
then
355 end_pos = scan(prop(1:256), c_null_char)
356 if (end_pos .ge. 2)
then
357 name(1:end_pos-1) = prop(1:end_pos-1)
363 integer(c_int) :: num_devices
365 if (cudagetdevicecount(num_devices) .ne.
cudasuccess)
then
366 call neko_error(
'Error retrieving device count')
subroutine cuda_device_name(name)
type(c_ptr), bind(C) aux_cmd_queue
Aux HIP command queue.
@ cudamemcpydevicetodevice
integer function cuda_device_count()
Return the number of avaialble CUDA devices.
@ cudaerrorinitializationerror
@ cudaerrormemoryallocation
type(c_ptr), bind(C) glb_cmd_queue
Global HIP command queue.
integer strm_low_prio
Low priority stream setting.
integer strm_high_prio
High priority stream setting.
Device abstraction, common interface for various accelerators.