-
Notifications
You must be signed in to change notification settings - Fork 4
/
check.go
48 lines (39 loc) · 1005 Bytes
/
check.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
// +build linux,cgo,!nogpu
package cupti
// #include <cupti.h>
import "C"
import (
"fmt"
"github.com/pkg/errors"
"github.com/rai-project/go-cupti/types"
)
type Error struct {
Code types.CUptiResult
}
func (e *Error) Error() string {
if e == nil {
return ""
}
var errstr *C.char
C.cuptiGetResultString(C.CUptiResult(e.Code), &errstr)
return fmt.Sprintf("cupti error code = %s, message = %s", e.Code.String(), C.GoString(errstr))
}
func checkCUPTIError(code C.CUptiResult) error {
if code == C.CUPTI_SUCCESS {
return nil
}
return &Error{Code: types.CUptiResult(code)}
}
func checkCUResult(code C.CUresult) error {
if code == C.CUDA_SUCCESS {
return nil
}
return errors.Errorf("cuda error code = %s", types.CUresult(code).String())
}
func checkCUDAError(code C.cudaError_t) error {
if code == C.cudaSuccess {
return nil
}
errstr := C.cudaGetErrorString(code)
return errors.Errorf("cuda error code = %s, message = %s", types.CUDAError(code).String(), C.GoString(errstr))
}