Documentation ¶
Overview ¶
Package data provides structures to store arrays in a hardware-agnostic (GPU-CPU) way.
Index ¶
- Constants
- func Copy(dst, src *Slice)
- func EnableGPU(free, freeHost func(unsafe.Pointer), ...)
- func MustWriteFile(fname string, s *Slice, time float64)
- func Write(out io.Writer, s *Slice, time float64) error
- func WriteFile(fname string, s *Slice, time float64) error
- type Mesh
- type Slice
- func MustReadFile(fname string) (data *Slice, time float64)
- func NewSlice(nComp int, m *Mesh) *Slice
- func NilSlice(nComp int, m *Mesh) *Slice
- func Read(in io.Reader) (data *Slice, time float64, err error)
- func ReadFile(fname string) (data *Slice, time float64, err error)
- func Resample(in *Slice, N0, N1, N2 int) *Slice
- func SliceFromList(data [][]float32, mesh *Mesh) *Slice
- func SliceFromPtrs(m *Mesh, memType int8, ptrs []unsafe.Pointer) *Slice
- func (s *Slice) CPUAccess() bool
- func (s *Slice) Comp(i int) *Slice
- func (s *Slice) DevPtr(component int) unsafe.Pointer
- func (s *Slice) Free()
- func (s *Slice) GPUAccess() bool
- func (s *Slice) Host() [][]float32
- func (s *Slice) HostCopy() *Slice
- func (s *Slice) Len() int
- func (s *Slice) MemType() int
- func (i Slice) Mesh() *Mesh
- func (s *Slice) NComp() int
- func (f *Slice) Scalars() [][][]float32
- func (s *Slice) Slice(a, b int) *Slice
- func (i Slice) Tag() string
- func (f *Slice) Tensors() [][][][]float32
- func (i Slice) Unit() string
- func (f *Slice) Vectors() [3][][][]float32
- type Synced
Constants ¶
const ( CPUMemory = 1 << 0 GPUMemory = 1 << 1 UnifiedMemory = CPUMemory | GPUMemory )
value for Slice.memType
const MAGIC = "#dump002"
const MAX_COMP = 3 // Maximum supported number of Slice components
const SIZEOF_FLOAT32 = 4
Variables ¶
This section is empty.
Functions ¶
func EnableGPU ¶
func EnableGPU(free, freeHost func(unsafe.Pointer), cpy, cpyDtoH, cpyHtoD func(dst, src unsafe.Pointer, bytes int64))
Internal: enables slices on GPU. Called upon cuda init.
func MustWriteFile ¶
Types ¶
type Mesh ¶
type Mesh struct {
// contains filtered or unexported fields
}
Mesh stores info of a finite-difference mesh.
func NewMesh ¶
Retruns a new mesh with N0 x N1 x N2 cells of size cellx x celly x cellz. Optional periodic boundary conditions (pbc): number of repetitions in X, Y, Z direction. 0,0,0 means no periodicity.
func (*Mesh) InternString ¶
String representation in internal coordinates (ZYX)
func (*Mesh) UserString ¶
String representation in user coordinates (XYZ)
type Slice ¶
type Slice struct {
// contains filtered or unexported fields
}
Slice is like a [][]float32, but may be stored in GPU or host memory.
func MustReadFile ¶
func NilSlice ¶
Return a slice without underlying storage. Used to represent a mask containing all 1's.
func SliceFromList ¶
func SliceFromPtrs ¶
Internal: construct a Slice using bare memory pointers. Used by cuda.
func (*Slice) CPUAccess ¶
CPUAccess returns whether the Slice is accessible by the CPU. true means it is stored in host memory.
func (*Slice) DevPtr ¶
DevPtr returns a CUDA device pointer to a component. Slice must have GPUAccess. It is safe to call on a nil slice, returns NULL.
func (*Slice) Free ¶
func (s *Slice) Free()
Frees the underlying storage and zeros the Slice header to avoid accidental use. Slices sharing storage will be invalid after Free. Double free is OK.
func (*Slice) GPUAccess ¶
GPUAccess returns whether the Slice is accessible by the GPU. true means it is either stored on GPU or in unified host memory.
func (*Slice) Host ¶
Host returns the Slice as a [][]float32, indexed by component, cell number. It should have CPUAccess() == true.
func (*Slice) MemType ¶
MemType returns the memory type of the underlying storage: CPUMemory, GPUMemory or UnifiedMemory
func (*Slice) Scalars ¶
Floats returns the data as 3D array, indexed by cell position. Data should be scalar (1 component) and have CPUAccess() == true.
type Synced ¶
type Synced struct {
// contains filtered or unexported fields
}
Slice + RWMutex combination.
func NewSynced ¶
NewSynced wraps the slice with an RWMutex. After construction, the Slice should only be used through the Synced anymore.