forked from gorgonia/gorgonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blas.go
57 lines (47 loc) · 1.37 KB
/
blas.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
package gorgonia
import (
"sync"
"gonum.org/v1/gonum/blas"
"gonum.org/v1/gonum/blas/gonum"
"gorgonia.org/tensor"
)
var blasdoor sync.Mutex
var whichblas BLAS
// BLAS represents all the possible implementations of BLAS.
// The default is Gonum's Native
type BLAS interface {
blas.Float32
blas.Float64
blas.Complex64
blas.Complex128
}
// only blase.Implementation() and cubone.Implementation() are batchedBLAS -
// they both batch cgo calls (and cubone batches cuda calls)
type batchedBLAS interface {
WorkAvailable() <-chan struct{}
DoWork()
Close() error
BLAS
}
// Use defines which BLAS implementation gorgonia should use.
// The default is Gonum's Native. These are the other options:
// Use(blase.Implementation())
// Use(cubone.Implementation())
// Use(cgo.Implementation)
// Note the differences in the brackets. The blase and cubone ones are functions.
func Use(b BLAS) {
// close the blast door! close the blast door!
blasdoor.Lock()
// open the blast door! open the blast door!
defer blasdoor.Unlock()
// those lines were few of the better additions to the Special Edition. There, I said it. The Special Edition is superior. Except Han still shot first in my mind.
whichblas = b
tensor.Use(b)
// TODO:
// float32
}
// WhichBLAS returns the BLAS that gorgonia uses.
func WhichBLAS() BLAS { return whichblas }
func init() {
whichblas = gonum.Implementation{}
}