forked from mumax/3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfatbin.go
42 lines (35 loc) · 789 Bytes
/
fatbin.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
package cuda
import (
"log"
"github.com/mumax/3/cuda/cu"
)
// load PTX code for function name, find highest SM that matches our card.
func fatbinLoad(sm map[int]string, fn string) cu.Function {
cc := determineCC()
return cu.ModuleLoadData(sm[cc]).GetFunction(fn)
}
var UseCC = 0
func determineCC() int {
if UseCC != 0 {
return UseCC
}
for k, _ := range madd2_map {
if k > UseCC && ccIsOK(k) {
UseCC = k
}
}
if UseCC == 0 {
log.Fatalln("\nNo binary for GPU. Your nvidia driver may be out-of-date\n")
}
return UseCC
}
// check wheter compute capability cc works
func ccIsOK(cc int) (ok bool) {
defer func() {
if err := recover(); err == cu.ERROR_NO_BINARY_FOR_GPU {
ok = false
}
}()
cu.ModuleLoadData(madd2_map[cc]).GetFunction("madd2")
return true
}