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