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 MustReadFile(fname string) (data *Slice, info Meta)
- func MustWriteFile(fname string, s *Slice, info Meta)
- func Read(in io.Reader) (data *Slice, info Meta, err error)
- func ReadFile(fname string) (data *Slice, info Meta, err error)
- func Write(out io.Writer, s *Slice, info Meta) error
- func WriteFile(fname string, s *Slice, info Meta) error
- type Mesh
- type Meta
- type Slice
- func Crop(in *Slice, x1, x2, y1, y2, z1, z2 int) *Slice
- func NewSlice(nComp int, m *Mesh) *Slice
- func NilSlice(nComp int, m *Mesh) *Slice
- func Resample(in *Slice, N [3]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) Disable()
- func (s *Slice) Free()
- func (s *Slice) GPUAccess() bool
- func (s *Slice) Host() [][]float32
- func (s *Slice) HostCopy() *Slice
- func (s *Slice) IsNil() bool
- func (s *Slice) Len() int
- func (s *Slice) MemType() int
- func (s *Slice) Mesh() *Mesh
- func (s *Slice) NComp() int
- func (f *Slice) Scalars() [][][]float32
- func (s *Slice) Slice(a, b int) *Slice
- func (f *Slice) Tensors() [][][][]float32
- func (f *Slice) Vectors() [3][][][]float32
Constants ¶
const ( CPUMemory = 1 << 0 GPUMemory = 1 << 1 UnifiedMemory = CPUMemory | GPUMemory )
value for Slice.memType
const MAGIC = "#dump002" // identifies dump format
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 MustReadFile ¶
func MustWriteFile ¶
Write the slice to file in binary format, panic on error.
Types ¶
type Mesh ¶
type Mesh struct { Unit string // unit of cellSize, default: "m" // 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) 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. TODO: unified memory is not used anymore, can be removed. Then we can split cuda.Slice and data.Slice?
func NilSlice ¶
Return a slice without underlying storage. Used to represent a mask containing all 1's.
func Resample ¶
Resample returns a slice of new size N, using nearest neighbor interpolation over the input slice.
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) Disable ¶
func (s *Slice) Disable()
INTERNAL. Overwrite struct fields with zeros to avoid accidental use after Free.
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.
func (*Slice) Slice ¶
Slice returns a slice sharing memory with the original. Beware that it may contain less elements than would be expected from Mesh().NCell().