data

package
v3.9.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2016 License: CC-BY-3.0, Freetype, GPL-3.0-or-later Imports: 7 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
)

value for Slice.memType

View Source
const (
	X = 0
	Y = 1
	Z = 2
)
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 Downsample

func Downsample(In [][][][]float32, N [3]int) [][][][]float32

Downsample returns a slice of new size N, smaller than in.Size(). Averaging interpolation over the input slice. in is returned untouched if the sizes are equal.

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 Index

func Index(size [3]int, ix, iy, iz int) int

func SizeOf

func SizeOf(block [][][]float32) [3]int

Returns the 3D size of block

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

func (m *Mesh) PBC_code() byte

3 bools, packed in one byte, indicating whether there are periodic boundary conditions in X (LSB), Y(LSB<<1), Z(LSB<<2)

func (*Mesh) SetPBC

func (m *Mesh) SetPBC(nx, ny, nz int)

func (*Mesh) Size

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

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

func (*Mesh) String

func (m *Mesh) String() string

func (*Mesh) WorldSize

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

WorldSize equals (grid)Size x CellSize.

type Meta

type Meta struct {
	Name, Unit     string
	Time, TimeStep float64
	CellSize       [3]float64
	MeshUnit       string
}

Holds meta data to be saved together with a slice. Typically winds up in OVF or DUMP header

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 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, size [3]int) *Slice

Make a CPU Slice with nComp components of size length.

func NilSlice

func NilSlice(nComp int, size [3]int) *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 SliceFromArray

func SliceFromArray(data [][]float32, size [3]int) *Slice

func SliceFromPtrs

func SliceFromPtrs(size [3]int, memType int8, ptrs []unsafe.Pointer) *Slice

Internal: construct a Slice using bare memory pointers.

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

func (s *Slice) Get(comp, ix, iy, iz int) float64

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

func (s *Slice) Index(ix, iy, iz int) int

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

func (s *Slice) Set(comp, ix, iy, iz int, value float64)

func (*Slice) SetScalar

func (s *Slice) SetScalar(ix, iy, iz int, v float64)

func (*Slice) SetVector

func (s *Slice) SetVector(ix, iy, iz int, v Vector)

func (*Slice) Size

func (s *Slice) Size() [3]int

func (*Slice) String

func (s *Slice) String() string

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.

type Vector

type Vector [3]float64

3-component vector

func (Vector) Add

func (a Vector) Add(b Vector) Vector

Returns a+b.

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

Returns the cross (vector) product a x b in a right-handed coordinate system.

func (Vector) Div

func (v Vector) Div(a float64) Vector

Returns (1/a)*v.

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

Returns the dot (inner) product a.b.

func (Vector) Len

func (v Vector) Len() float64

Returns the norm of v.

func (Vector) MAdd

func (a Vector) MAdd(s float64, b Vector) Vector

Returns a+s*b.

func (Vector) Mul

func (v Vector) Mul(a float64) Vector

Returns a*v.

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

Returns a-b.

func (Vector) X

func (v Vector) X() float64

func (Vector) Y

func (v Vector) Y() float64

func (Vector) Z

func (v Vector) Z() float64

Jump to

Keyboard shortcuts

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