forked from mumax/3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
58 lines (48 loc) · 1.31 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cu
// This file implements CUDA streams
//#include <cuda.h>
import "C"
import "unsafe"
// CUDA stream.
type Stream uintptr
// Creates an asynchronous stream
func StreamCreate() Stream {
var stream C.CUstream
err := Result(C.cuStreamCreate(&stream, C.uint(0))) // flags has to be zero
if err != SUCCESS {
panic(err)
}
return Stream(uintptr(unsafe.Pointer(stream)))
}
// Destroys the asynchronous stream
func (stream *Stream) Destroy() {
str := *stream
err := Result(C.cuStreamDestroy(C.CUstream(unsafe.Pointer(uintptr(str)))))
*stream = 0
if err != SUCCESS {
panic(err)
}
}
// Destroys an asynchronous stream
func StreamDestroy(stream *Stream) {
stream.Destroy()
}
// Blocks until the stream has completed.
func (stream Stream) Synchronize() {
err := Result(C.cuStreamSynchronize(C.CUstream(unsafe.Pointer(uintptr(stream)))))
if err != SUCCESS {
panic(err)
}
}
// Returns Success if all operations have completed, ErrorNotReady otherwise
func (stream Stream) Query() Result {
return Result(C.cuStreamQuery(C.CUstream(unsafe.Pointer(uintptr(stream)))))
}
// Returns Success if all operations have completed, ErrorNotReady otherwise
func StreamQuery(stream Stream) Result {
return stream.Query()
}
// Blocks until the stream has completed.
func StreamSynchronize(stream Stream) {
stream.Synchronize()
}