Debian Codegraph @

blas.go

raw
1 package tensor
2
3 import (
4 "sync"
5
6 "gonum.org/v1/gonum/blas"
7 "gonum.org/v1/gonum/blas/gonum"
8 )
9
10 var blasdoor sync.Mutex
11 var whichblas BLAS
12
13 // BLAS represents all the possible implementations of BLAS.
14 // The default is Gonum's Native
15 type BLAS interface {
16 blas.Float32
17 blas.Float64
18 blas.Complex64
19 blas.Complex128
20 }
21
22 // only blastoise.Implementation() and cubone.Implementation() are batchedBLAS -
23 // they both batch cgo calls (and cubone batches cuda calls)
24 type batchedBLAS interface {
25 WorkAvailable() int
26 DoWork()
27 BLAS
28 }
29
30 // Use defines which BLAS implementation gorgonia should use.
31 // The default is Gonum's Native. These are the other options:
32 // Use(blastoise.Implementation())
33 // Use(cubone.Implementation())
34 // Use(cgo.Implementation)
35 // Note the differences in the brackets. The blastoise and cubone ones are functions.
36 func Use(b BLAS) {
37 // close the blast door! close the blast door!
38 blasdoor.Lock()
39 // open the blast door! open the blast door!
40 defer blasdoor.Unlock()
41 // 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.
42
43 whichblas = b
44 }
45
46 // WhichBLAS returns the BLAS that gorgonia uses.
47 func WhichBLAS() BLAS { return whichblas }
48
49 func init() {
50 whichblas = gonum.Implementation{}
51 }