本文整理匯總了Golang中github.com/mumax/3/cuda.Recycle函數的典型用法代碼示例。如果您正苦於以下問題:Golang Recycle函數的具體用法?Golang Recycle怎麽用?Golang Recycle使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Recycle函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: EvalTo
func (d *dotProduct) EvalTo(dst *data.Slice) {
A := ValueOf(d.a)
defer cuda.Recycle(A)
B := ValueOf(d.b)
defer cuda.Recycle(B)
cuda.Zero(dst)
cuda.AddDotProduct(dst, 1, A, B)
}
示例2: Step
// Euler method, can be used as solver.Step.
func (s *BackwardEuler) Step() {
util.AssertMsg(MaxErr > 0, "Backward euler solver requires MaxErr > 0")
t0 := Time
y := M.Buffer()
y0 := cuda.Buffer(VECTOR, y.Size())
defer cuda.Recycle(y0)
data.Copy(y0, y)
dy0 := cuda.Buffer(VECTOR, y.Size())
defer cuda.Recycle(dy0)
if s.dy1 == nil {
s.dy1 = cuda.Buffer(VECTOR, y.Size())
}
dy1 := s.dy1
Dt_si = FixDt
dt := float32(Dt_si * GammaLL)
util.AssertMsg(dt > 0, "Backward Euler solver requires fixed time step > 0")
// Fist guess
Time = t0 + 0.5*Dt_si // 0.5 dt makes it implicit midpoint method
// with temperature, previous torque cannot be used as predictor
if Temp.isZero() {
cuda.Madd2(y, y0, dy1, 1, dt) // predictor euler step with previous torque
M.normalize()
}
torqueFn(dy0)
cuda.Madd2(y, y0, dy0, 1, dt) // y = y0 + dt * dy
M.normalize()
// One iteration
torqueFn(dy1)
cuda.Madd2(y, y0, dy1, 1, dt) // y = y0 + dt * dy1
M.normalize()
Time = t0 + Dt_si
err := cuda.MaxVecDiff(dy0, dy1) * float64(dt)
// adjust next time step
//if err < MaxErr || Dt_si <= MinDt || FixDt != 0 { // mindt check to avoid infinite loop
// step OK
NSteps++
setLastErr(err)
setMaxTorque(dy1)
//} else {
// undo bad step
// util.Assert(FixDt == 0)
// Time = t0
// data.Copy(y, y0)
// NUndone++
//}
}
示例3: dot
// vector dot product
func dot(a, b outputField) float64 {
A, recyA := a.Slice()
if recyA {
defer cuda.Recycle(A)
}
B, recyB := b.Slice()
if recyB {
defer cuda.Recycle(B)
}
return float64(cuda.Dot(A, B))
}
示例4: Step
func (mini *Minimizer) Step() {
m := M.Buffer()
size := m.Size()
k := mini.k
h := mini.h
// save original magnetization
m0 := cuda.Buffer(3, size)
defer cuda.Recycle(m0)
data.Copy(m0, m)
// make descent
cuda.Minimize(m, m0, k, h)
// calculate new torque for next step
k0 := cuda.Buffer(3, size)
defer cuda.Recycle(k0)
data.Copy(k0, k)
torqueFn(k)
setMaxTorque(k) // report to user
// just to make the following readable
dm := m0
dk := k0
// calculate step difference of m and k
cuda.Madd2(dm, m, m0, 1., -1.)
cuda.Madd2(dk, k, k0, -1., 1.) // reversed due to LLNoPrecess sign
// get maxdiff and add to list
max_dm := cuda.MaxVecNorm(dm)
mini.lastDm.Add(max_dm)
setLastErr(mini.lastDm.Max()) // report maxDm to user as LastErr
// adjust next time step
var nom, div float32
if NSteps%2 == 0 {
nom = cuda.Dot(dm, dm)
div = cuda.Dot(dm, dk)
} else {
nom = cuda.Dot(dm, dk)
div = cuda.Dot(dk, dk)
}
if div != 0. {
mini.h = nom / div
} else { // in case of division by zero
mini.h = 1e-4
}
M.normalize()
// as a convention, time does not advance during relax
NSteps++
}
示例5: Slice
func (d *dotProduct) Slice() (*data.Slice, bool) {
slice := cuda.Buffer(d.NComp(), d.Mesh().Size())
cuda.Zero(slice)
A, r := d.a.Slice()
if r {
defer cuda.Recycle(A)
}
B, r := d.b.Slice()
if r {
defer cuda.Recycle(B)
}
cuda.AddDotProduct(slice, 1, A, B)
return slice, true
}
示例6: makeEdensAdder
// returns a function that adds to dst the energy density:
// prefactor * dot (M_full, field)
func makeEdensAdder(field outputField, prefactor float64) func(*data.Slice) {
return func(dst *data.Slice) {
B, r1 := field.Slice()
if r1 {
defer cuda.Recycle(B)
}
m, r2 := M_full.Slice()
if r2 {
defer cuda.Recycle(m)
}
factor := float32(prefactor)
cuda.AddDotProduct(dst, factor, B, m)
}
}
示例7: Step
// Euler method, can be used as solver.Step.
func (_ *Euler) Step() {
y := M.Buffer()
dy0 := cuda.Buffer(VECTOR, y.Size())
defer cuda.Recycle(dy0)
torqueFn(dy0)
setMaxTorque(dy0)
// Adaptive time stepping: treat MaxErr as the maximum magnetization delta
// (proportional to the error, but an overestimation for sure)
var dt float32
if FixDt != 0 {
Dt_si = FixDt
dt = float32(Dt_si * GammaLL)
} else {
dt = float32(MaxErr / LastTorque)
Dt_si = float64(dt) / GammaLL
}
util.AssertMsg(dt > 0, "Euler solver requires fixed time step > 0")
setLastErr(float64(dt) * LastTorque)
cuda.Madd2(y, y, dy0, 1, dt) // y = y + dt * dy
M.normalize()
Time += Dt_si
NSteps++
}
示例8: GetMaxTorque
// Gets
func GetMaxTorque() float64 {
torque, recycle := Torque.Slice()
if recycle {
defer cuda.Recycle(torque)
}
return cuda.MaxVecNorm(torque)
}
示例9: qAverageUniverse
// average of quantity over universe
func qAverageUniverse(q Quantity) []float64 {
s, recycle := q.Slice()
if recycle {
defer cuda.Recycle(s)
}
return sAverageUniverse(s)
}
示例10: average
func (g *geom) average() []float64 {
s, r := g.Slice()
if r {
defer cuda.Recycle(s)
}
return sAverageUniverse(s)
}
示例11: AddCustomField
// AddCustomField evaluates the user-defined custom field terms
// and adds the result to dst.
func AddCustomField(dst *data.Slice) {
for _, term := range customTerms {
buf := ValueOf(term)
cuda.Add(dst, dst, buf)
cuda.Recycle(buf)
}
}
示例12: average
func (r *Regions) average() []float64 {
s, recycle := r.Slice()
if recycle {
defer cuda.Recycle(s)
}
return sAverageUniverse(s)
}
示例13: GetMaxAngle
func GetMaxAngle() float64 {
s, recycle := SpinAngle.Slice()
if recycle {
defer cuda.Recycle(s)
}
return float64(cuda.MaxAbs(s)) // just a max would be fine, but not currently implemented
}
示例14: qAverageUniverse
// average of quantity over universe
func qAverageUniverse(q outputField) []float64 {
s, recycle := q.Slice()
if recycle {
defer cuda.Recycle(s)
}
return sAverageUniverse(s)
}
示例15: shift
func (g *geom) shift(dx int) {
// empty mask, nothing to do
if g == nil || g.buffer.IsNil() {
return
}
// allocated mask: shift
s := g.buffer
s2 := cuda.Buffer(1, g.Mesh().Size())
defer cuda.Recycle(s2)
newv := float32(1) // initially fill edges with 1's
cuda.ShiftX(s2, s, dx, newv, newv)
data.Copy(s, s2)
n := Mesh().Size()
x1, x2 := shiftDirtyRange(dx)
for iz := 0; iz < n[Z]; iz++ {
for iy := 0; iy < n[Y]; iy++ {
for ix := x1; ix < x2; ix++ {
r := Index2Coord(ix, iy, iz) // includes shift
if !g.shape(r[X], r[Y], r[Z]) {
cuda.SetCell(g.buffer, 0, ix, iy, iz, 0) // a bit slowish, but hardly reached
}
}
}
}
}