data

package
v3.0.12+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2013 License: GPL-3.0 Imports: 10 Imported by: 266

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" // identifies dump format
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 MustReadFile

func MustReadFile(fname string) (data *Slice, info Meta)

func MustWriteFile

func MustWriteFile(fname string, s *Slice, info Meta)

Write the slice to file in binary format, panic on error.

func Read

func Read(in io.Reader) (data *Slice, info Meta, err error)

func ReadFile

func ReadFile(fname string) (data *Slice, info Meta, err error)

func Write

func Write(out io.Writer, s *Slice, info Meta) error

Write the slice to out in binary format. Add time stamp.

func WriteFile

func WriteFile(fname string, s *Slice, info Meta) error

Write the slice to file in binary format. Add time stamp.

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

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

type Meta struct {
	Name, Unit string
	Time       float64
}

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 Crop

func Crop(in *Slice, x1, x2, y1, y2, z1, z2 int) *Slice

Cut-out a piece between given bounds (incl, excl)

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 Resample

func Resample(in *Slice, N [3]int) *Slice

Resample returns a slice of new size N, using nearest neighbor interpolation over the input 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) 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

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

func (s *Slice) IsNil() bool

IsNil returns true if either s is nil or s.pointer[0] == nil

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 (s *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. Beware that it may contain less elements than would be expected from Mesh().NCell().

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

Jump to

Keyboard shortcuts

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