Skip to content

Commit

Permalink
many updates, getting further
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Oct 9, 2024
1 parent 43ccf2d commit 6a7089c
Show file tree
Hide file tree
Showing 27 changed files with 1,723 additions and 1,323 deletions.
140 changes: 70 additions & 70 deletions axon/act.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions axon/act.goal
Original file line number Diff line number Diff line change
Expand Up @@ -1161,12 +1161,12 @@ func (ac *ActParams) GeFromSyn(ctx *Context, ni, di uint32, geSyn, geExt float32
Neurons[GeExt, ni, di] = 0
geS := geSyn
geE := geExt
if ac.Clamp.Add.IsTrue() && NrnHasFlag(ctx, ni, di, NeuronHasExt) {
if ac.Clamp.Add.IsTrue() && NrnHasFlag(ni, di, NeuronHasExt) {
Neurons[GeExt, ni, di] = Neurons[Ext, ni, di] * ac.Clamp.Ge
geS += Neurons[GeExt, ni, di]
}

if ac.Clamp.Add.IsFalse() && NrnHasFlag(ctx, ni, di, NeuronHasExt) { // todo: this flag check is not working
if ac.Clamp.Add.IsFalse() && NrnHasFlag(ni, di, NeuronHasExt) { // todo: this flag check is not working
geS = Neurons[Ext, ni, di] * ac.Clamp.Ge
Neurons[GeExt, ni, di] = geS
geE = 0 // no extra in this case
Expand Down
4 changes: 2 additions & 2 deletions axon/blanovelprjn.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (ot *BLANovelPath) Name() string {
return "BLANovelPath"
}

func (ot *BLANovelPath) Connect(send, recv *tensor.Shape, same bool) (sendn, recvn *tensor.Int32, cons *tensor.Bits) {
func (ot *BLANovelPath) Connect(send, recv *tensor.Shape, same bool) (sendn, recvn *tensor.Int32, cons *tensor.Bool) {
sendn, recvn, cons = paths.NewTensors(send, recv)
sNtot := send.Len()
// rNtot := recv.Len()
Expand All @@ -39,7 +39,7 @@ func (ot *BLANovelPath) Connect(send, recv *tensor.Shape, same bool) (sendn, rec
for sui := 0; sui < sNu; sui++ {
si := spi*sNu + sui
off := ri*sNtot + si
cons.Values.Set(off, true)
cons.Values.Set(true, off)
rnv[ri] = int32(sNu * (npl - 1))
snv[si] = int32(rNu)
}
Expand Down
139 changes: 8 additions & 131 deletions axon/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/emer/emergent/v2/etime"
)

// todo: remove this:

var (
// TheNetwork is the one current network in use, needed for GPU shader kernel
// compatible variable access in CPU mode, for !multinet build tags case.
Expand All @@ -23,96 +25,6 @@ var (
Networks []*Network
)

// NeuronAvgVars

// NrnAvgV is the CPU version of the neuron variable accessor
func NrnAvgV(ctx *Context, ni uint32, nvar NeuronAvgVars) float32 {
return GlobalNetwork(ctx).NeuronAvgs[ctx.NeuronAvgVars.Index(ni, nvar)]
}

// SetNrnAvgV is the CPU version of the neuron variable settor
func SetNrnAvgV(ctx *Context, ni uint32, nvar NeuronAvgVars, val float32) {
GlobalNetwork(ctx).NeuronAvgs[ctx.NeuronAvgVars.Index(ni, nvar)] = val
}

// AddNrnAvgV is the CPU version of the neuron variable addor
func AddNrnAvgV(ctx *Context, ni uint32, nvar NeuronAvgVars, val float32) {
GlobalNetwork(ctx).NeuronAvgs[ctx.NeuronAvgVars.Index(ni, nvar)] += val
}

// MulNrnAvgV is the CPU version of the neuron variable multiplier
func MulNrnAvgV(ctx *Context, ni uint32, nvar NeuronAvgVars, val float32) {
GlobalNetwork(ctx).NeuronAvgs[ctx.NeuronAvgVars.Index(ni, nvar)] *= val
}

// NeuronIndexes

// NrnI is the CPU version of the neuron idx accessor
func NrnI(ctx *Context, ni uint32, idx NeuronIndexes) uint32 {
return GlobalNetwork(ctx).NeuronIxs[ctx.NeuronIndexes.Index(ni, idx)]
}

// SetNrnI is the CPU version of the neuron idx settor
func SetNrnI(ctx *Context, ni uint32, idx NeuronIndexes, val uint32) {
GlobalNetwork(ctx).NeuronIxs[ctx.NeuronIndexes.Index(ni, idx)] = val
}

// SynapseVars

// SynV is the CPU version of the synapse variable accessor
func SynV(ctx *Context, syni uint32, svar SynapseVars) float32 {
return GlobalNetwork(ctx).Synapses[ctx.SynapseVars.Index(syni, svar)]
}

// SetSynV is the CPU version of the synapse variable settor
func SetSynV(ctx *Context, syni uint32, svar SynapseVars, val float32) {
GlobalNetwork(ctx).Synapses[ctx.SynapseVars.Index(syni, svar)] = val
}

// AddSynV is the CPU version of the synapse variable addor
func AddSynV(ctx *Context, syni uint32, svar SynapseVars, val float32) {
GlobalNetwork(ctx).Synapses[ctx.SynapseVars.Index(syni, svar)] += val
}

// MulSynV is the CPU version of the synapse variable multiplier
func MulSynV(ctx *Context, syni uint32, svar SynapseVars, val float32) {
GlobalNetwork(ctx).Synapses[ctx.SynapseVars.Index(syni, svar)] *= val
}

// SynapseCaVars

// SynCaV is the CPU version of the synapse variable accessor
func SynCaV(ctx *Context, syni, di uint32, svar SynapseCaVars) float32 {
return GlobalNetwork(ctx).SynapseCas[ctx.SynapseCaVars.Index(syni, di, svar)]
}

// SetSynCaV is the CPU version of the synapse variable settor
func SetSynCaV(ctx *Context, syni, di uint32, svar SynapseCaVars, val float32) {
GlobalNetwork(ctx).SynapseCas[ctx.SynapseCaVars.Index(syni, di, svar)] = val
}

// AddSynCaV is the CPU version of the synapse variable addor
func AddSynCaV(ctx *Context, syni, di uint32, svar SynapseCaVars, val float32) {
GlobalNetwork(ctx).SynapseCas[ctx.SynapseCaVars.Index(syni, di, svar)] += val
}

// MulSynCaV is the CPU version of the synapse variable multiplier
func MulSynCaV(ctx *Context, syni, di uint32, svar SynapseCaVars, val float32) {
GlobalNetwork(ctx).SynapseCas[ctx.SynapseCaVars.Index(syni, di, svar)] *= val
}

// SynapseIndexes

// SynI is the CPU version of the synapse idx accessor
func SynI(ctx *Context, syni uint32, idx SynapseIndexes) uint32 {
return GlobalNetwork(ctx).SynapseIxs[ctx.SynapseIndexes.Index(syni, idx)]
}

// SetSynI is the CPU version of the synapse idx settor
func SetSynI(ctx *Context, syni uint32, idx SynapseIndexes, val uint32) {
GlobalNetwork(ctx).SynapseIxs[ctx.SynapseIndexes.Index(syni, idx)] = val
}

/////////////////////////////////
// Global Vars

Expand Down Expand Up @@ -182,27 +94,8 @@ func AddGlbUSposV(ctx *Context, di uint32, gvar GlobalVars, posIndex uint32, val
// any compute methods with the context. See SetCtxStrides on Network.
func (ctx *Context) CopyNetStridesFrom(srcCtx *Context) {
ctx.NetIndexes = srcCtx.NetIndexes
ctx.NeuronVars = srcCtx.NeuronVars
ctx.NeuronAvgVars = srcCtx.NeuronAvgVars
ctx.NeuronIndexes = srcCtx.NeuronIndexes
ctx.SynapseVars = srcCtx.SynapseVars
ctx.SynapseCaVars = srcCtx.SynapseCaVars
ctx.SynapseIndexes = srcCtx.SynapseIndexes
}

//gosl:end

//gosl:wgsl context
// #include "etime.wgsl"
// #include "axonrand.wgsl"
// #include "neuron.wgsl"
// #include "synapse.wgsl"
// #include "globals.wgsl"
// #include "neuromod.wgsl"
//gosl:endwgsl context

//gosl:start context

// NetIndexes are indexes and sizes for processing network
type NetIndexes struct {

Expand Down Expand Up @@ -366,27 +259,11 @@ type Context struct {
// indexes and sizes of current network
NetIndexes NetIndexes `display:"inline"`

// stride offsets for accessing neuron variables
NeuronVars NeuronVarStrides `display:"-"`

// stride offsets for accessing neuron average variables
NeuronAvgVars NeuronAvgVarStrides `display:"-"`

// stride offsets for accessing neuron indexes
NeuronIndexes NeuronIndexStrides `display:"-"`

// stride offsets for accessing synapse variables
SynapseVars SynapseVarStrides `display:"-"`

// stride offsets for accessing synapse Ca variables
SynapseCaVars SynapseCaStrides `display:"-"`

// stride offsets for accessing synapse indexes
SynapseIndexes SynapseIndexStrides `display:"-"`

// random counter -- incremented by maximum number of possible random numbers generated per cycle, regardless of how many are actually used -- this is shared across all layers so must encompass all possible param settings.
// RandCtr slrand.Counter
// TODO:gosl
// RandCtr is the random counter, incremented by maximum number of
// possible random numbers generated per cycle, regardless of how
// many are actually used. This is shared across all layers so must
// encompass all possible param settings.
RandCtr uint64
}

// Defaults sets default values
Expand Down Expand Up @@ -480,7 +357,7 @@ void NrnClearFlag(in Context ctx, uint ni, uint di, NeuronFlags flag) {
}
fn NrnIsOff(ctx: ptr<function,Context>, ni: u32) -> bool {
return NrnHasFlag(ctx, ni, u32(0), NeuronOff);
return NrnHasFlag(ni, u32(0), NeuronOff);
}
// // NeuronAvgVars
Expand Down
344 changes: 0 additions & 344 deletions axon/enumgen.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion axon/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !offscreen && ((darwin && !ios) || windows || (linux && !android) || dragonfly || openbsd)
//go:build not

// old go:build !offscreen && ((darwin && !ios) || windows || (linux && !android) || dragonfly || openbsd)

package axon

Expand Down
16 changes: 8 additions & 8 deletions axon/hip_net.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package axon
import (
"cogentcore.org/core/base/errors"
"cogentcore.org/core/math32/vecint"
"cogentcore.org/core/tensor/stats/stats"
"github.com/emer/emergent/v2/emer"
"github.com/emer/emergent/v2/etime"
"github.com/emer/emergent/v2/looper"
Expand Down Expand Up @@ -233,7 +232,7 @@ func (net *Network) ConfigLoopsHip(ctx *Context, man *looper.Manager, hip *HipCo
ca3FromDg.Params.PathScale.Rel = dgPjScale * (1 - hip.MossyDelta) // turn off DG input to CA3 in first quarter

net.InitGScale(ctx) // update computed scaling factors
net.GPU.SyncParamsToGPU()
// net.GPU.SyncParamsToGPU() // todo:
})
beta1 := cyc.EventByName("Beta1")
beta1.OnEvent.Add("Hip:Beta1", func() {
Expand All @@ -243,7 +242,7 @@ func (net *Network) ConfigLoopsHip(ctx *Context, man *looper.Manager, hip *HipCo
ca3FromDg.Params.PathScale.Rel = dgPjScale * (1 - hip.MossyDeltaTest)
}
net.InitGScale(ctx) // update computed scaling factors
net.GPU.SyncParamsToGPU()
// net.GPU.SyncParamsToGPU() // TODO:
})
plus := cyc.EventByName("PlusPhase")

Expand All @@ -257,22 +256,23 @@ func (net *Network) ConfigLoopsHip(ctx *Context, man *looper.Manager, hip *HipCo
if mode != etime.Test || hip.EC5ClampTest {
for di := uint32(0); di < ctx.NetIndexes.NData; di++ {
clampSrc.UnitValues(&tmpValues, "Act", int(di))
if hip.EC5ClampThr > 0 {
stats.Binarize32(tmpValues, tensor.NewFloat64Scalar(hip.EC5ClampThr))
}
// TODO:
// if hip.EC5ClampThr > 0 {
// stats.Binarize(tmpValues, tensor.NewFloat64Scalar(hip.EC5ClampThr))
// }
ec5.ApplyExt1D32(ctx, di, tmpValues)
}
}
}
net.InitGScale(ctx) // update computed scaling factors
net.GPU.SyncParamsToGPU()
// net.GPU.SyncParamsToGPU()
net.ApplyExts(ctx) // essential for GPU
})

trl := stack.Loops[etime.Trial]
trl.OnEnd.Prepend("HipPlusPhase:End", func() {
ca1FromCa3.Params.PathScale.Rel = hip.ThetaHigh
net.InitGScale(ctx) // update computed scaling factors
net.GPU.SyncParamsToGPU()
// net.GPU.SyncParamsToGPU()
})
}
Loading

0 comments on commit 6a7089c

Please sign in to comment.