36 use,
intrinsic :: iso_c_binding
42 type(c_ptr),
bind(c) :: glb_cmd_queue = c_null_ptr
90 integer(c_int) function hipmalloc(ptr_d, s) &
91 bind(c, name =
'hipMalloc')
92 use,
intrinsic :: iso_c_binding
95 integer(c_size_t),
value :: s
96 end function hipmalloc
98 integer(c_int) function hipfree(ptr_d) &
99 bind(c, name =
'hipFree')
100 use,
intrinsic :: iso_c_binding
102 type(c_ptr),
value :: ptr_d
105 integer(c_int) function hipmemcpy(ptr_dst, ptr_src, s, dir) &
106 bind(c, name =
'hipMemcpy')
107 use,
intrinsic :: iso_c_binding
109 type(c_ptr),
value :: ptr_dst, ptr_src
110 integer(c_size_t),
value :: s
111 integer(c_int),
value :: dir
112 end function hipmemcpy
114 integer(c_int) function hipmemcpyasync(ptr_dst, ptr_src, s, dir, stream) &
115 bind(c, name =
'hipMemcpyAsync')
116 use,
intrinsic :: iso_c_binding
118 type(c_ptr),
value :: ptr_dst, ptr_src, stream
119 integer(c_size_t),
value :: s
120 integer(c_int),
value :: dir
121 end function hipmemcpyasync
123 integer(c_int) function hipdevicesynchronize() &
124 bind(c, name =
'hipDeviceSynchronize')
125 use,
intrinsic :: iso_c_binding
127 end function hipdevicesynchronize
129 integer(c_int) function hipdevicegetname(name, len, device) &
130 bind(c, name =
'hipDeviceGetName')
131 use,
intrinsic :: iso_c_binding
133 type(c_ptr),
value :: name
134 integer(c_int),
value :: len
135 integer(c_int),
value ::
device
136 end function hipdevicegetname
138 integer(c_int) function hipgetdevicecount(amount) &
139 bind(c, name =
'hipGetDeviceCount')
140 use,
intrinsic :: iso_c_binding
142 integer(c_int) :: amount
143 end function hipgetdevicecount
145 integer(c_int) function hipstreamcreate(stream) &
146 bind(c, name =
'hipStreamCreate')
147 use,
intrinsic :: iso_c_binding
149 type(c_ptr) :: stream
150 end function hipstreamcreate
152 integer(c_int) function hipstreamcreatewithflags(stream, flags) &
153 bind(c, name =
'hipStreamCreateWithFlags')
154 use,
intrinsic :: iso_c_binding
156 type(c_ptr) :: stream
157 integer(c_int),
value :: flags
158 end function hipstreamcreatewithflags
160 integer(c_int) function hipstreamcreatewithpriority(stream, flags, prio) &
161 bind(c, name =
'hipStreamCreateWithPriority')
162 use,
intrinsic :: iso_c_binding
164 type(c_ptr) :: stream
165 integer(c_int),
value :: flags, prio
166 end function hipstreamcreatewithpriority
168 integer(c_int) function hipstreamdestroy(steam) &
169 bind(c, name =
'hipStreamDestroy')
170 use,
intrinsic :: iso_c_binding
172 type(c_ptr),
value :: steam
173 end function hipstreamdestroy
175 integer(c_int) function hipstreamsynchronize(stream) &
176 bind(c, name =
'hipStreamSynchronize')
177 use,
intrinsic :: iso_c_binding
179 type(c_ptr),
value :: stream
180 end function hipstreamsynchronize
182 integer(c_int) function hipstreamwaitevent(stream, event, flags) &
183 bind(c, name =
'hipStreamWaitEvent')
184 use,
intrinsic :: iso_c_binding
186 type(c_ptr),
value :: stream, event
187 integer(c_int),
value :: flags
188 end function hipstreamwaitevent
190 integer(c_int) function hipdevicegetstreampriorityrange(low_prio, &
192 bind(c, name =
'hipDeviceGetStreamPriorityRange')
193 use,
intrinsic :: iso_c_binding
195 integer(c_int) :: low_prio, high_prio
196 end function hipdevicegetstreampriorityrange
198 integer(c_int) function hipeventcreate(event) &
199 bind(c, name =
'hipEventCreate')
200 use,
intrinsic :: iso_c_binding
203 end function hipeventcreate
205 integer(c_int) function hipeventdestroy(event) &
206 bind(c, name =
'hipEventDestroy')
207 use,
intrinsic :: iso_c_binding
209 type(c_ptr),
value :: event
210 end function hipeventdestroy
212 integer(c_int) function hipeventcreatewithflags(event, flags) &
213 bind(c, name =
'hipEventCreateWithFlags')
214 use,
intrinsic :: iso_c_binding
217 integer(c_int),
value :: flags
218 end function hipeventcreatewithflags
220 integer(c_int) function hipeventrecord(event, stream) &
221 bind(c, name =
'hipEventRecord')
222 use,
intrinsic :: iso_c_binding
224 type(c_ptr),
value :: event, stream
225 end function hipeventrecord
227 integer(c_int) function hipeventsynchronize(event) &
228 bind(c, name =
'hipEventSynchronize')
229 use,
intrinsic :: iso_c_binding
231 type(c_ptr),
value :: event
232 end function hipeventsynchronize
241 call neko_error(
'Error retrieving stream priority range')
244 if (hipstreamcreatewithpriority(glb_cmd_queue, 1,
strm_high_prio) &
256 if (hipstreamdestroy(glb_cmd_queue) .ne.
hipsuccess)
then
257 call neko_error(
'Error destroying main stream')
261 call neko_error(
'Error destroying aux stream')
266 character(len=*),
intent(inout) :: name
267 character(kind=c_char, len=1024),
target :: c_name
270 if (hipdevicegetname(c_loc(c_name), 1024, 0) .ne.
hipsuccess)
then
274 end_pos = scan(c_name, c_null_char)
275 if (end_pos .ge. 2)
then
276 name(1:end_pos-1) = c_name(1:end_pos-1)
283 type(c_ptr) :: hip_count_ptr
286 if (hipgetdevicecount(amount) .ne.
hipsuccess)
then
287 call neko_error(
'Failed to query device count')
Device abstraction, common interface for various accelerators.
type(c_ptr), bind(C) aux_cmd_queue
Aux HIP command queue.
integer strm_low_prio
Low priority stream setting.
subroutine hip_device_name(name)
@ hipmemcpydevicetodevice
integer strm_high_prio
High priority stream setting.
@ hiperrormapbufferobjectfailed
@ hiperrorinvaliddevicepointer
@ hiperrorpeeraccessnotenabled
@ hiperrorinvalidkernelfile
@ hiperrorpeeraccessalreadyenabled
@ hiperrorinvalidresourcehandle
@ hiperrorhostmemorynotregistered
@ hiperrormemoryallocation
@ hiperrorlaunchoutofresources
@ hiperrorinvalidmemcpydirection
@ hiperrorinitializationerror
@ hiperrorhostmemoryalreadyregistered
integer function hip_device_count()
Return the number of available HIP devices.