-
Notifications
You must be signed in to change notification settings - Fork 4
/
library.go
58 lines (51 loc) · 1.25 KB
/
library.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
// +build linux,amd64
package cupti
import (
"os/exec"
"path/filepath"
"runtime"
"github.com/Unknwon/com"
"github.com/rai-project/config"
"github.com/rainycape/dl"
)
var (
dlib *dl.DL
DefaultCUPTILibraryPath string
DefaultCUDALibraryPath string
)
func load() {
var err error
libPrefix := ""
if runtime.GOOS == "linux" {
libPrefix = "lib"
}
lib := filepath.Join(DefaultCUPTILibraryPath, libPrefix+"cupti"+dl.LibExt)
if !com.IsFile(lib) {
log.WithField("lib", lib).Error("unable to find cupti library")
return
}
log.WithField("lib", lib).Debug("loading cupti library")
dlib, err = dl.Open(lib, 0)
if err != nil {
log.WithError(err).Error("unable to find cupti")
}
}
func xinit() {
config.AfterInit(func() {
nvccPath, err := exec.LookPath("nvcc")
if err != nil {
nvccPath = "/usr/local/cuda/bin/nvcc"
}
cudaBaseDir, _ := filepath.Abs(filepath.Join(nvccPath, "..", ".."))
if DefaultCUDALibraryPath == "" {
DefaultCUDALibraryPath = filepath.Join(cudaBaseDir, "lib")
}
if DefaultCUPTILibraryPath == "" {
DefaultCUPTILibraryPath = filepath.Join(cudaBaseDir, "extras", "CUPTI", "lib")
if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" {
DefaultCUPTILibraryPath += "64"
}
}
load()
})
}