gorgonia.org/gorgonia@v0.9.17/cuda/interfaces.go (about)

     1  package cuda
     2  
     3  import (
     4  	"gorgonia.org/cu"
     5  	"gorgonia.org/cu/blas"
     6  	"gorgonia.org/cu/dnn"
     7  	"gorgonia.org/tensor"
     8  )
     9  
    10  // Arena is a representation of a memory arena which is managed.
    11  type Arena interface {
    12  	// Get returns a NoOpError when it cannot get a memory. Please allocate
    13  	Get(size int64) (tensor.Memory, error)
    14  
    15  	// Puts the memory back into arena
    16  	Put(mem tensor.Memory, size int64)
    17  
    18  	// ResetAllocator resets the allocator statisttics, but doesn't actually deallocate  real memory
    19  	ResetAllocator()
    20  }
    21  
    22  // External is a representation of an external device, conceptually modelled as a machine
    23  type External interface {
    24  	// Arena implies that the machine has to be able to manage its own memory
    25  	Arena
    26  
    27  	// Engine implies that the machine is able to allocate and free memory
    28  	tensor.Engine
    29  
    30  	// HasFunc checks if a function exists within this machine
    31  	HasFunc(string) bool
    32  
    33  	// Sync returns a channel of sync signals
    34  	Sync() chan struct{}
    35  
    36  	// Signal signals the machine to do work
    37  	Signal()
    38  
    39  	// Context returns the Context (the default implementation returns a *cu.BatchedContext)
    40  	Context() *cu.BatchedContext
    41  
    42  	// CUDNNContext returns the cuDNN context
    43  	CUDNNContext() *cudnn.Context
    44  
    45  	// BLASContext returns the cuBLAS context
    46  	BLASContext() *cublas.Standard
    47  
    48  	// Modules returns the loaded modules. It is indexed by name
    49  	Modules() map[string]cu.Module
    50  
    51  	// Functions returns the loaded functions. It is indexed by name
    52  	Functions() map[string]cu.Function
    53  
    54  	// ElemGridSize calculates the grid sizes for elementwise operations
    55  	ElemGridSize(n int) (gridDimX, gridDimY, gridDimZ, blockDimX, blockDimY, blockDimZ int)
    56  
    57  	// Init initializes the machine
    58  	Init(device cu.Device, size int64) error
    59  
    60  	// Close cleans up the machine, and closes all available resources
    61  	Close() error
    62  
    63  	// DoWork sends a signal to the batched CUDA Context to actually do work
    64  	DoWork() error
    65  }