-
Notifications
You must be signed in to change notification settings - Fork 64
/
cu.go
32 lines (26 loc) · 839 Bytes
/
cu.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
// Package cu provides an idiomatic interface to the CUDA Driver API.
package cu // import "gorgonia.org/cu"
// This file implements CUDA driver context management
//#include <cuda.h>
import "C"
import (
"fmt"
"os"
)
const initHtml = "https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__INITIALIZE.html"
func init() {
// Given that the flags must be 0, the CUDA driver is initialized at the package level
// http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__INITIALIZE.html
if err := result(C.cuInit(C.uint(0))); err != nil {
fmt.Printf("Error in initialization, please refer to %q for details on: %+v\n", initHtml, err)
os.Exit(1)
}
}
// Version returns the version of the CUDA driver
func Version() int {
var v C.int
if err := result(C.cuDriverGetVersion(&v)); err != nil {
return -1
}
return int(v)
}