Skip to content

Commit 393e4e7

Browse files
committed
cu/result: return error code for undefined errors
1 parent 4f793ce commit 393e4e7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

result.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ package cu
22

33
//#include <cuda.h>
44
import "C"
5+
import "fmt"
56

67
// cuResult is the Go version of CUresult:
78
// http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html#group__CUDA__TYPES_1gc6c391505e117393cc2558fff6bfc2e9
89
type cuResult int
910

1011
func (err cuResult) Error() string { return err.String() }
11-
func (err cuResult) String() string { return resString[err] }
12+
func (err cuResult) String() string {
13+
if msg, ok := resString[err]; ok {
14+
return msg
15+
}
16+
return fmt.Sprintf("UnknownErrorCode:%d", err)
17+
}
1218

1319
func result(x C.CUresult) error {
1420
err := cuResult(x)
1521
if err == Success {
1622
return nil
1723
}
18-
if err > Unknown {
19-
return Unknown
20-
}
21-
2224
return err
2325
}
2426

0 commit comments

Comments
 (0)