data

package
v0.0.0-...-d0c3c69 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2013 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package data provides structures to store arrays in a hardware-agnostic (GPU-CPU) way.

Index

Constants

View Source
const (
	CPUMemory     = 1 << 0
	GPUMemory     = 1 << 1
	UnifiedMemory = CPUMemory | GPUMemory
)

value for Slice.memType

View Source
const MAGIC = "#dump002"
View Source
const MAX_COMP = 3 // Maximum supported number of Slice components
View Source
const SIZEOF_FLOAT32 = 4

Variables

This section is empty.

Functions

func Copy

func Copy(dst, src *Slice)

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

func MustWriteFile(fname string, s *Slice, time float64)

func Write

func Write(out io.Writer, s *Slice, time float64) error

TODO: buffer? benchmark

func WriteFile

func WriteFile(fname string, s *Slice, time float64) error

Types

type Mesh

type Mesh struct {
	// contains filtered or unexported fields
}

Mesh stores info of a finite-difference mesh.

func NewMesh

func NewMesh(N0, N1, N2 int, cellx, celly, cellz float64, pbc ...int) *Mesh

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) CellSize

func (m *Mesh) CellSize() [3]float64

Returns cellx, celly, cellz, as passed to constructor.

func (*Mesh) InternString

func (m *Mesh) InternString() string

String representation in internal coordinates (ZYX)

func (*Mesh) NCell

func (m *Mesh) NCell() int

Total number of cells, not taking into account PBCs.

N0 * N1 * N2

func (*Mesh) PBC

func (m *Mesh) PBC() [3]int

Returns pbc (periodic boundary conditions), as passed to constructor.

func (*Mesh) Size

func (m *Mesh) Size() [3]int

Returns N0, N1, N2, as passed to constructor.

func (*Mesh) UserString

func (m *Mesh) UserString() string

String representation in user coordinates (XYZ)

func (*Mesh) WorldSize

func (m *Mesh) WorldSize() [3]float64

WorldSize equals (grid)Size x CellSize.

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 MustReadFile(fname string) (data *Slice, time float64)

func NewSlice

func NewSlice(nComp int, m *Mesh) *Slice

Make a CPU Slice with nComp components of size length.

func NilSlice

func NilSlice(nComp int, m *Mesh) *Slice

Return a slice without underlying storage. Used to represent a mask containing all 1's.

func Read

func Read(in io.Reader) (data *Slice, time float64, err error)

func ReadFile

func ReadFile(fname string) (data *Slice, time float64, err error)

func Resample

func Resample(in *Slice, N0, N1, N2 int) *Slice

func SliceFromList

func SliceFromList(data [][]float32, mesh *Mesh) *Slice

func SliceFromPtrs

func SliceFromPtrs(m *Mesh, memType int8, ptrs []unsafe.Pointer) *Slice

Internal: construct a Slice using bare memory pointers. Used by cuda.

func (*Slice) CPUAccess

func (s *Slice) CPUAccess() bool

CPUAccess returns whether the Slice is accessible by the CPU. true means it is stored in host memory.

func (*Slice) Comp

func (s *Slice) Comp(i int) *Slice

Comp returns a single component of the Slice.

func (*Slice) DevPtr

func (s *Slice) DevPtr(component int) unsafe.Pointer

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

func (s *Slice) GPUAccess() bool

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

func (s *Slice) Host() [][]float32

Host returns the Slice as a [][]float32, indexed by component, cell number. It should have CPUAccess() == true.

func (*Slice) HostCopy

func (s *Slice) HostCopy() *Slice

Returns a copy of the Slice, allocated on CPU.

func (*Slice) Len

func (s *Slice) Len() int

Len returns the number of elements per component.

func (*Slice) MemType

func (s *Slice) MemType() int

MemType returns the memory type of the underlying storage: CPUMemory, GPUMemory or UnifiedMemory

func (Slice) Mesh

func (i Slice) Mesh() *Mesh

Mesh on which the data is defined.

func (*Slice) NComp

func (s *Slice) NComp() int

NComp returns the number of components.

func (*Slice) Scalars

func (f *Slice) Scalars() [][][]float32

Floats returns the data as 3D array, indexed by cell position. Data should be scalar (1 component) and have CPUAccess() == true.

func (*Slice) Slice

func (s *Slice) Slice(a, b int) *Slice

Slice returns a slice sharing memory with the original.

func (Slice) Tag

func (i Slice) Tag() string

Human-readable tag to identify the data.

func (*Slice) Tensors

func (f *Slice) Tensors() [][][][]float32

Tensors returns the data as 4D array, indexed by component, cell position. Requires CPUAccess() == true.

func (Slice) Unit

func (i Slice) Unit() string

Physical unit of the data.

func (*Slice) Vectors

func (f *Slice) Vectors() [3][][][]float32

Vectors returns the data as 4D array, indexed by component, cell position. Data should have 3 components and have CPUAccess() == true.

type Synced

type Synced struct {
	// contains filtered or unexported fields
}

Slice + RWMutex combination.

func NewSynced

func NewSynced(slice *Slice) *Synced

NewSynced wraps the slice with an RWMutex. After construction, the Slice should only be used through the Synced anymore.

func (*Synced) Mesh

func (s *Synced) Mesh() *Mesh

func (*Synced) Read

func (s *Synced) Read() *Slice

Locks for reading and returns the (now locked) data Slice.

func (*Synced) ReadDone

func (s *Synced) ReadDone()

Unlocks for reading, to be called after Read.

func (*Synced) Write

func (s *Synced) Write() *Slice

Locks for writing and returns the (now locked) data Slice.

func (*Synced) WriteDone

func (s *Synced) WriteDone()

Unlocks for writing, to be called after Write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL