-
Notifications
You must be signed in to change notification settings - Fork 2
/
buffered.go
45 lines (37 loc) · 1.17 KB
/
buffered.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package engine
import (
"github.com/mumax/3/cuda"
"github.com/mumax/3/data"
"github.com/mumax/3/util"
)
// A buffered quantity is stored in GPU memory at all times.
type buffered struct {
info
buffer *data.Slice
}
// init metadata but does not allocate yet
func (b *buffered) init(nComp int, name, unit, doc_ string, mesh *data.Mesh) {
b.info = Info(nComp, name, unit, mesh)
}
// allocate storage (not done by init)
func (q *buffered) alloc() {
q.buffer = cuda.NewSlice(3, q.Mesh())
}
// get buffer (on GPU, no need to recycle)
func (b *buffered) Slice() (q *data.Slice, recycle bool) {
return b.buffer, false
}
// Set the value of one cell.
func (b *buffered) SetCell(ix, iy, iz int, v ...float64) {
nComp := b.NComp()
util.Argument(len(v) == nComp)
for c := 0; c < nComp; c++ {
cuda.SetCell(b.buffer, util.SwapIndex(c, nComp), iz, iy, ix, float32(v[c]))
}
}
// Get the value of one cell.
func (b *buffered) GetCell(comp, ix, iy, iz int) float64 {
return float64(cuda.GetCell(b.buffer, util.SwapIndex(comp, b.NComp()), iz, iy, ix))
}
func (q *buffered) Region(r int) *inRegion { return &inRegion{q, r} }
func (m *buffered) TableData() []float64 { return Average(m) }