Skip to content

Commit

Permalink
improve various names and update to new core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Apr 5, 2024
1 parent 6be5a04 commit e99d169
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 66 deletions.
10 changes: 5 additions & 5 deletions examples/axon/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ func (dp *DtParams) GiSynFmRawSteady(giRaw float32) float32 {
return giRaw * dp.GiTau
}

// AvgVarUpdt updates the average and variance from current value, using LongAvgDt
func (dp *DtParams) AvgVarUpdt(avg, vr *float32, val float32) {
// AvgVarUpdate updates the average and variance from current value, using LongAvgDt
func (dp *DtParams) AvgVarUpdate(avg, vr *float32, val float32) {
if *avg == 0 { // first time -- set
*avg = val
*vr = 0
Expand Down Expand Up @@ -451,7 +451,7 @@ func (at *AttnParams) Update() {
}

// ModVal returns the attn-modulated value -- attn must be between 1-0
func (at *AttnParams) ModVal(val float32, attn float32) float32 {
func (at *AttnParams) ModValue(val float32, attn float32) float32 {
if val < 0 {
val = 0
}
Expand Down Expand Up @@ -788,7 +788,7 @@ func (ac *ActParams) GeFmSyn(ni int, nrn *Neuron, geSyn, geExt float32, randctr
nrn.GeExt = nrn.Ext * ac.Clamp.Ge
geSyn += nrn.GeExt
}
geSyn = ac.Attn.ModVal(geSyn, nrn.Attn)
geSyn = ac.Attn.ModValue(geSyn, nrn.Attn)

if ac.Clamp.Add.IsTrue() && nrn.HasFlag(NeuronHasExt) {
geSyn = nrn.Ext * ac.Clamp.Ge
Expand Down Expand Up @@ -846,7 +846,7 @@ func (ac *ActParams) InetFmG(vm, ge, gl, gi, gk float32) float32 {

// VmFmInet computes new Vm value from inet, clamping range
func (ac *ActParams) VmFmInet(vm, dt, inet float32) float32 {
return ac.VmRange.ClipVal(vm + dt*inet)
return ac.VmRange.ClipValue(vm + dt*inet)
}

// VmInteg integrates Vm over VmSteps to obtain a more stable value
Expand Down
14 changes: 7 additions & 7 deletions examples/axon/axon.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// note: on Mac can get away with 16 byte idx
// struct Idx {
// struct Index {
// uint X;
// uint Y;
// };
Expand All @@ -9,19 +9,19 @@
[[vk::binding(0, 0)]] RWStructuredBuffer<Layer> Layers;
[[vk::binding(0, 1)]] RWStructuredBuffer<Time> time;
[[vk::binding(0, 2)]] RWStructuredBuffer<Neuron> Neurons;
// [[vk::binding(0, 3)]] StructuredBuffer<Idx> Idxs;
// note: uniform declaration for Idxs doesn't work
// [[vk::binding(0, 3)]] StructuredBuffer<Index> Indexes;
// note: uniform declaration for Indexes doesn't work

// note: the only way to get a local var to struct is via a function call param
void CycleNeuron(int ni, inout Neuron nrn, inout Time ctime) {
Layers[nrn.LayIdx].CycleNeuron(ni, nrn, ctime);
Layers[nrn.LayIndex].CycleNeuron(ni, nrn, ctime);
if(ni == 0) {
Layers[nrn.LayIdx].CycleTimeInc(ctime);
Layers[nrn.LayIndex].CycleTimeInc(ctime);
// updating time completely within this loop does NOT work
// because the memory update is not shared!
}
// nrn.SpkSt1 = float(Idxs[ni].X); // debugging
// nrn.SpkSt2 = float(nrn.LayIdx);
// nrn.SpkSt1 = float(Indexes[ni].X); // debugging
// nrn.SpkSt2 = float(nrn.LayIndex);
}

// important: this must be right before main, and 64 is typical default
Expand Down
4 changes: 2 additions & 2 deletions examples/axon/kinase/kinase.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type CaParams struct {
SpikeG float32 `default:"12"`

// IMPORTANT: only used for SynSpkTheta learning mode: threshold on Act value for updating synapse-level Ca values -- this is purely a performance optimization that excludes random infrequent spikes -- 0.05 works well on larger networks but not smaller, which require the .01 default.
UpdtThr float32 `default:"0.01,0.02,0.5"`
UpdateThr float32 `default:"0.01,0.02,0.5"`

// maximum ISI for integrating in Opt mode -- above that just set to 0
MaxISI int32 `default:"100"`
Expand All @@ -67,7 +67,7 @@ type CaParams struct {

func (kp *CaParams) Defaults() {
kp.SpikeG = 12
kp.UpdtThr = 0.01
kp.UpdateThr = 0.01
kp.MaxISI = 100
kp.Dt.Defaults()
kp.Update()
Expand Down
6 changes: 3 additions & 3 deletions examples/axon/learn.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func (np *CaLrnParams) CaLrn(nrn *Neuron) {
// signals, starting with CaSyn that is integrated at the neuron level
// and drives synapse-level, pre * post Ca integration, which provides the Tr
// trace that multiplies error signals, and drives learning directly for Target layers.
// CaSpk* values are integrated separately at the Neuron level and used for UpdtThr
// CaSpk* values are integrated separately at the Neuron level and used for UpdateThr
// and RLRate as a proxy for the activation (spiking) based learning signal.
type CaSpkParams struct {

// gain multiplier on spike for computing CaSpk: increasing this directly affects the magnitude of the trace values, learning rate in Target layers, and other factors that depend on CaSpk values: RLRate, UpdtThr. Prjn.KinaseCa.SpikeG provides an additional gain factor specific to the synapse-level trace factors, without affecting neuron-level CaSpk values. Larger networks require higher gain factors at the neuron level -- 12, vs 8 for smaller.
// gain multiplier on spike for computing CaSpk: increasing this directly affects the magnitude of the trace values, learning rate in Target layers, and other factors that depend on CaSpk values: RLRate, UpdateThr. Prjn.KinaseCa.SpikeG provides an additional gain factor specific to the synapse-level trace factors, without affecting neuron-level CaSpk values. Larger networks require higher gain factors at the neuron level -- 12, vs 8 for smaller.
SpikeG float32 `default:"8,12"`

// time constant for integrating spike-driven calcium trace at sender and recv neurons, CaSyn, which then drives synapse-level integration of the joint pre * post synapse-level activity, in cycles (msec)
Expand Down Expand Up @@ -261,7 +261,7 @@ type LearnNeurParams struct {
// parameterizes the neuron-level calcium signals driving learning: CaLrn = NMDA + VGCC Ca sources, where VGCC can be simulated from spiking or use the more complex and dynamic VGCC channel directly. CaLrn is then integrated in a cascading manner at multiple time scales: CaM (as in calmodulin), CaP (ltP, CaMKII, plus phase), CaD (ltD, DAPK1, minus phase).
CaLrn CaLrnParams `view:"inline"`

// parameterizes the neuron-level spike-driven calcium signals, starting with CaSyn that is integrated at the neuron level, and drives synapse-level, pre * post Ca integration, which provides the Tr trace that multiplies error signals, and drives learning directly for Target layers. CaSpk* values are integrated separately at the Neuron level and used for UpdtThr and RLRate as a proxy for the activation (spiking) based learning signal.
// parameterizes the neuron-level spike-driven calcium signals, starting with CaSyn that is integrated at the neuron level, and drives synapse-level, pre * post Ca integration, which provides the Tr trace that multiplies error signals, and drives learning directly for Target layers. CaSpk* values are integrated separately at the Neuron level and used for UpdateThr and RLRate as a proxy for the activation (spiking) based learning signal.
CaSpk CaSpkParams `view:"inline"`

// NMDA channel parameters used for learning, vs. the ones driving activation -- allows exploration of learning parameters independent of their effects on active maintenance contributions of NMDA, and may be supported by different receptor subtypes
Expand Down
38 changes: 19 additions & 19 deletions examples/axon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func main() {
for i := range neur1 {
nrn := &neur1[i]
if i > nfirst {
nrn.LayIdx = 1
nrn.LayIndex = 1
}
ly := &lays[nrn.LayIdx]
ly := &lays[nrn.LayIndex]
ly.Act.InitActs(nrn)
nrn.GeBase = 0.4
}
neur2 := make([]Neuron, n)
for i := range neur2 {
nrn := &neur2[i]
if i > nfirst {
nrn.LayIdx = 1
nrn.LayIndex = 1
}
ly := &lays[nrn.LayIdx]
ly := &lays[nrn.LayIndex]
ly.Act.InitActs(nrn)
nrn.GeBase = 0.4
}
Expand All @@ -105,7 +105,7 @@ func main() {
threading.ParallelRun(func(st, ed int) {
for ni := st; ni < ed; ni++ {
nrn := &neur1[ni]
ly := &lays[nrn.LayIdx]
ly := &lays[nrn.LayIndex]
ly.CycleNeuron(ni, nrn, time)
}
}, len(neur1), cpuThreads)
Expand Down Expand Up @@ -137,36 +137,36 @@ func main() {
timev := sett.AddStruct("Time", int(unsafe.Sizeof(Time{})), 1, vgpu.Storage, vgpu.ComputeShader)
neurv := setn.AddStruct("Neurons", int(unsafe.Sizeof(Neuron{})), n, vgpu.Storage, vgpu.ComputeShader)
// var ui sltype.Uint2
// idxv := seti.AddStruct("Idxs", int(unsafe.Sizeof(ui)), n, vgpu.Storage, vgpu.ComputeShader)
// idxv := seti.AddStruct("Indexes", int(unsafe.Sizeof(ui)), n, vgpu.Storage, vgpu.ComputeShader)

setl.ConfigVals(1) // one val per var
sett.ConfigVals(1) // one val per var
setn.ConfigVals(1) // one val per var
// seti.ConfigVals(1) // one val per var
setl.ConfigValues(1) // one val per var
sett.ConfigValues(1) // one val per var
setn.ConfigValues(1) // one val per var
// seti.ConfigValues(1) // one val per var
sy.Config() // configures vars, allocates vals, configs pipelines..

gpuFullTmr := timer.Time{}
gpuFullTmr.Start()

// this copy is pretty fast -- most of time is below
lvl, _ := layv.Vals.ValByIdxTry(0)
lvl, _ := layv.Values.ValueByIndexTry(0)
lvl.CopyFromBytes(unsafe.Pointer(&lays[0]))
tvl, _ := timev.Vals.ValByIdxTry(0)
tvl, _ := timev.Values.ValueByIndexTry(0)
tvl.CopyFromBytes(unsafe.Pointer(time))
nvl, _ := neurv.Vals.ValByIdxTry(0)
nvl, _ := neurv.Values.ValueByIndexTry(0)
nvl.CopyFromBytes(unsafe.Pointer(&neur2[0]))
// ivl, _ := idxv.Vals.ValByIdxTry(0)
// ivl, _ := idxv.Values.ValueByIndexTry(0)
// ivl.CopyFromBytes(unsafe.Pointer(&idxs[0]))

// gpuFullTmr := timer.Time{}
// gpuFullTmr.Start()

sy.Mem.SyncToGPU()

vars.BindDynValIdx(0, "Layers", 0)
vars.BindDynValIdx(1, "Time", 0)
vars.BindDynValIdx(2, "Neurons", 0)
// vars.BindDynValIdx(3, "Idxs", 0)
vars.BindDynamicValueIndex(0, "Layers", 0)
vars.BindDynamicValueIndex(1, "Time", 0)
vars.BindDynamicValueIndex(2, "Neurons", 0)
// vars.BindDynamicValueIndex(3, "Indexes", 0)

cmd := sy.ComputeCmdBuff()
sy.CmdResetBindVars(cmd, 0)
Expand All @@ -184,7 +184,7 @@ func main() {

gpuTmr.Stop()

sy.Mem.SyncValIdxFmGPU(2, "Neurons", 0) // this is about same as SyncToGPU
sy.Mem.SyncValueIndexFromGPU(2, "Neurons", 0) // this is about same as SyncToGPU
nvl.CopyToBytes(unsafe.Pointer(&neur2[0]))

gpuFullTmr.Stop()
Expand Down
12 changes: 6 additions & 6 deletions examples/axon/minmax/minmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ func (mr *F32) Midpoint() float32 {

// NormVal normalizes value to 0-1 unit range relative to current Min / Max range
// Clips the value within Min-Max range first.
func (mr *F32) NormVal(val float32) float32 {
return (mr.ClipVal(val) - mr.Min) * mr.Scale()
func (mr *F32) NormValue(val float32) float32 {
return (mr.ClipValue(val) - mr.Min) * mr.Scale()
}

// ProjVal projects a 0-1 normalized unit value into current Min / Max range (inverse of NormVal)
func (mr *F32) ProjVal(val float32) float32 {
func (mr *F32) ProjValue(val float32) float32 {
return mr.Min + (val * mr.Range())
}

// ClipVal clips given value within Min / Max range
// Note: a NaN will remain as a NaN
func (mr *F32) ClipVal(val float32) float32 {
func (mr *F32) ClipValue(val float32) float32 {
if val < mr.Min {
return mr.Min
}
Expand All @@ -96,14 +96,14 @@ func (mr *F32) ClipVal(val float32) float32 {

// ClipNormVal clips then normalizes given value within 0-1
// Note: a NaN will remain as a NaN
func (mr *F32) ClipNormVal(val float32) float32 {
func (mr *F32) ClipNormValue(val float32) float32 {
if val < mr.Min {
return 0
}
if val > mr.Max {
return 1
}
return mr.NormVal(val)
return mr.NormValue(val)
}

// FitValInRange adjusts our Min, Max to fit given value within Min, Max range
Expand Down
14 changes: 7 additions & 7 deletions examples/axon/neuron.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Neuron struct {
Flags NeuronFlags

// index of the layer that this neuron belongs to -- needed for neuron-level parallel code.
LayIdx uint32
LayIndex uint32

// index of the sub-level inhibitory pool that this neuron is in (only for 4D shapes, the pool (unit-group / hypercolumn) structure level) -- indicies start at 1 -- 0 is layer-level pool (is 0 if no sub-pools).
SubPool int32
Expand Down Expand Up @@ -334,12 +334,12 @@ func init() {
NeuronVarsMap = make(map[string]int, len(NeuronVars))
typ := reflect.TypeOf((*Neuron)(nil)).Elem()
nf := typ.NumField()
startIdx := NeuronVarStart
for i := startIdx; i < nf; i++ {
startIndex := NeuronVarStart
for i := startIndex; i < nf; i++ {
fs := typ.FieldByIndex([]int{i})
v := fs.Name
NeuronVars = append(NeuronVars, v)
NeuronVarsMap[v] = i - startIdx
NeuronVarsMap[v] = i - startIndex
pstr := NeuronVarProps[v]
if fld, has := typ.FieldByName(v); has {
if desc, ok := fld.Tag.Lookup("desc"); ok {
Expand All @@ -354,8 +354,8 @@ func (nrn *Neuron) VarNames() []string {
return NeuronVars
}

// NeuronVarIdxByName returns the index of the variable in the Neuron, or error
func NeuronVarIdxByName(varNm string) (int, error) {
// NeuronVarIndexByName returns the index of the variable in the Neuron, or error
func NeuronVarIndexByName(varNm string) (int, error) {
i, ok := NeuronVarsMap[varNm]
if !ok {
return -1, fmt.Errorf("Neuron VarByName: variable name: %v not valid", varNm)
Expand All @@ -371,7 +371,7 @@ func (nrn *Neuron) VarByIndex(idx int) float32 {

// VarByName returns variable by name, or error
func (nrn *Neuron) VarByName(varNm string) (float32, error) {
i, err := NeuronVarIdxByName(varNm)
i, err := NeuronVarIndexByName(varNm)
if err != nil {
return mat32.NaN(), err
}
Expand Down
16 changes: 8 additions & 8 deletions examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ func main() {
parsv := setp.AddStruct("Params", int(unsafe.Sizeof(ParamStruct{})), 1, vgpu.Storage, vgpu.ComputeShader)
datav := setd.AddStruct("Data", int(unsafe.Sizeof(DataStruct{})), n, vgpu.Storage, vgpu.ComputeShader)

setp.ConfigVals(1) // one val per var
setd.ConfigVals(1) // one val per var
sy.Config() // configures vars, allocates vals, configs pipelines..
setp.ConfigValues(1) // one val per var
setd.ConfigValues(1) // one val per var
sy.Config() // configures vars, allocates vals, configs pipelines..

gpuFullTmr := timer.Time{}
gpuFullTmr.Start()

// this copy is pretty fast -- most of time is below
pvl, _ := parsv.Vals.ValByIdxTry(0)
pvl, _ := parsv.Values.ValueByIndexTry(0)
pvl.CopyFromBytes(unsafe.Pointer(pars))
dvl, _ := datav.Vals.ValByIdxTry(0)
dvl, _ := datav.Values.ValueByIndexTry(0)
dvl.CopyFromBytes(unsafe.Pointer(&data[0]))

// gpuFullTmr := timer.Time{}
// gpuFullTmr.Start()

sy.Mem.SyncToGPU()

vars.BindDynValIdx(0, "Params", 0)
vars.BindDynValIdx(1, "Data", 0)
vars.BindDynamicValueIndex(0, "Params", 0)
vars.BindDynamicValueIndex(1, "Data", 0)

cmd := sy.ComputeCmdBuff()
sy.CmdResetBindVars(cmd, 0)
Expand All @@ -107,7 +107,7 @@ func main() {

gpuTmr.Stop()

sy.Mem.SyncValIdxFmGPU(1, "Data", 0) // this is about same as SyncToGPU
sy.Mem.SyncValueIndexFromGPU(1, "Data", 0) // this is about same as SyncToGPU
dvl.CopyToBytes(unsafe.Pointer(&data[0]))

gpuFullTmr.Stop()
Expand Down
18 changes: 9 additions & 9 deletions examples/rand/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@ func main() {
ctrv := setc.AddStruct("Counter", int(unsafe.Sizeof(seed)), 1, vgpu.Storage, vgpu.ComputeShader)
datav := setd.AddStruct("Data", int(unsafe.Sizeof(Rnds{})), n, vgpu.Storage, vgpu.ComputeShader)

setc.ConfigVals(1) // one val per var
setd.ConfigVals(1) // one val per var
sy.Config() // configures vars, allocates vals, configs pipelines..
setc.ConfigValues(1) // one val per var
setd.ConfigValues(1) // one val per var
sy.Config() // configures vars, allocates vals, configs pipelines..

gpuFullTmr := timer.Time{}
gpuFullTmr.Start()

// this copy is pretty fast -- most of time is below
cvl, _ := ctrv.Vals.ValByIdxTry(0)
cvl, _ := ctrv.Values.ValueByIndexTry(0)
cvl.CopyFromBytes(unsafe.Pointer(&seed))
dvl, _ := datav.Vals.ValByIdxTry(0)
dvl, _ := datav.Values.ValueByIndexTry(0)
dvl.CopyFromBytes(unsafe.Pointer(&dataG[0]))

// gpuFullTmr := timer.Time{}
// gpuFullTmr.Start()

sy.Mem.SyncToGPU()

vars.BindDynValIdx(0, "Counter", 0)
vars.BindDynValIdx(1, "Data", 0)
vars.BindDynamicValueIndex(0, "Counter", 0)
vars.BindDynamicValueIndex(1, "Data", 0)

cmd := sy.ComputeCmdBuff()
sy.CmdResetBindVars(cmd, 0)
Expand All @@ -106,15 +106,15 @@ func main() {

gpuTmr.Stop()

sy.Mem.SyncValIdxFmGPU(1, "Data", 0) // this is about same as SyncToGPU
sy.Mem.SyncValueIndexFromGPU(1, "Data", 0) // this is about same as SyncToGPU
dvl.CopyToBytes(unsafe.Pointer(&dataG[0]))

gpuFullTmr.Stop()

anyDiffEx := false
anyDiffTol := false
mx := min(n, 5)
fmt.Printf("Idx\tDif(Ex,Tol)\t CPU \t then GPU\n")
fmt.Printf("Index\tDif(Ex,Tol)\t CPU \t then GPU\n")
for i := 0; i < n; i++ {
dc := &dataC[i]
dg := &dataG[i]
Expand Down

0 comments on commit e99d169

Please sign in to comment.