From a32f6c3285164077a202ccdf8911636f57824a19 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Tue, 3 Dec 2024 15:03:18 -0800 Subject: [PATCH] update to new TensorStrides indexing: massive speedup! like 2x previous on bench_lvis. needs a couple of other minor fixes for tint to be happy. --- axon/gosl.go | 59 +++ axon/init-net.go | 2 - axon/init-net.goal | 2 - axon/network.go | 38 +- axon/network.goal | 38 +- axon/shaders/ApplyExtsNeuron.wgsl | 169 ++++--- axon/shaders/Beta1Neuron.wgsl | 156 ++++--- axon/shaders/Beta2Neuron.wgsl | 156 ++++--- axon/shaders/BetweenGi.wgsl | 159 ++++--- axon/shaders/CycleInc.wgsl | 152 +++---- axon/shaders/CycleNeuron.wgsl | 591 +++++++++++++------------ axon/shaders/CyclePost.wgsl | 255 ++++++----- axon/shaders/DWtFromDiSyn.wgsl | 159 ++++--- axon/shaders/DWtSubMeanNeuron.wgsl | 170 ++++--- axon/shaders/DWtSyn.wgsl | 407 ++++++++--------- axon/shaders/GPUTestWrite.wgsl | 154 ++++--- axon/shaders/GatherSpikes.wgsl | 238 +++++----- axon/shaders/InitGBuffsPath.wgsl | 156 ++++--- axon/shaders/LayerGi.wgsl | 265 ++++++----- axon/shaders/MinusPhaseNeuron.wgsl | 156 ++++--- axon/shaders/MinusPhasePool.wgsl | 178 ++++---- axon/shaders/MinusPhasePost.wgsl | 310 +++++++------ axon/shaders/NewStateLayer.wgsl | 201 ++++----- axon/shaders/NewStateNeuron.wgsl | 293 ++++++------ axon/shaders/PlusPhaseNeuron.wgsl | 198 ++++----- axon/shaders/PlusPhasePool.wgsl | 158 ++++--- axon/shaders/PlusPhasePost.wgsl | 384 ++++++++-------- axon/shaders/PlusPhaseStartNeuron.wgsl | 169 ++++--- axon/shaders/PoolGi.wgsl | 281 ++++++------ axon/shaders/SendSpike.wgsl | 271 ++++++------ axon/shaders/SlowAdaptLayer.wgsl | 215 +++++---- axon/shaders/SlowAdaptNeuron.wgsl | 207 +++++---- axon/shaders/WtFromDWtLayer.wgsl | 175 ++++---- axon/shaders/WtFromDWtSyn.wgsl | 186 ++++---- examples/ra25/ra25.go | 2 +- 35 files changed, 3323 insertions(+), 3387 deletions(-) diff --git a/axon/gosl.go b/axon/gosl.go index 828cf3ea..2c1efa18 100644 --- a/axon/gosl.go +++ b/axon/gosl.go @@ -6,6 +6,7 @@ import ( "embed" "unsafe" "cogentcore.org/core/gpu" + "cogentcore.org/core/tensor" ) //go:embed shaders/*.wgsl @@ -49,6 +50,9 @@ const ( SynapseTracesVar GPUVars = 21 ) +// Tensor stride variables +var TensorStrides tensor.Uint32 + // GPUInit initializes the GPU compute system, // configuring system(s), variables and kernels. // It is safe to call multiple times: detects if already run. @@ -95,6 +99,8 @@ func GPUInit() { sgp := vars.AddGroup(gpu.Storage) var vr *gpu.Var _ = vr + vr = sgp.Add("TensorStrides", gpu.Uint32, 1, gpu.ComputeShader) + vr.ReadOnly = true vr = sgp.AddStruct("Layers", int(unsafe.Sizeof(LayerParams{})), 1, gpu.ComputeShader) vr.ReadOnly = true vr = sgp.AddStruct("Paths", int(unsafe.Sizeof(PathParams{})), 1, gpu.ComputeShader) @@ -1477,6 +1483,59 @@ func ToGPU(vars ...GPUVars) { } } +// ToGPUTensorStrides gets tensor strides and starts copying to the GPU. +func ToGPUTensorStrides() { + if !UseGPU { + return + } + sy := GPUSystem + syVars := sy.Vars() + TensorStrides.SetShapeSizes(180) + TensorStrides.SetInt1D(NeuronIxs.Shape().Strides[0], 0) + TensorStrides.SetInt1D(NeuronIxs.Shape().Strides[1], 1) + TensorStrides.SetInt1D(SynapseIxs.Shape().Strides[0], 10) + TensorStrides.SetInt1D(SynapseIxs.Shape().Strides[1], 11) + TensorStrides.SetInt1D(PathSendCon.Shape().Strides[0], 20) + TensorStrides.SetInt1D(PathSendCon.Shape().Strides[1], 21) + TensorStrides.SetInt1D(RecvPathIxs.Shape().Strides[0], 30) + TensorStrides.SetInt1D(PathRecvCon.Shape().Strides[0], 40) + TensorStrides.SetInt1D(PathRecvCon.Shape().Strides[1], 41) + TensorStrides.SetInt1D(RecvSynIxs.Shape().Strides[0], 50) + TensorStrides.SetInt1D(Neurons.Shape().Strides[0], 60) + TensorStrides.SetInt1D(Neurons.Shape().Strides[1], 61) + TensorStrides.SetInt1D(Neurons.Shape().Strides[2], 62) + TensorStrides.SetInt1D(NeuronAvgs.Shape().Strides[0], 70) + TensorStrides.SetInt1D(NeuronAvgs.Shape().Strides[1], 71) + TensorStrides.SetInt1D(LayerStates.Shape().Strides[0], 80) + TensorStrides.SetInt1D(LayerStates.Shape().Strides[1], 81) + TensorStrides.SetInt1D(LayerStates.Shape().Strides[2], 82) + TensorStrides.SetInt1D(GlobalScalars.Shape().Strides[0], 90) + TensorStrides.SetInt1D(GlobalScalars.Shape().Strides[1], 91) + TensorStrides.SetInt1D(GlobalVectors.Shape().Strides[0], 100) + TensorStrides.SetInt1D(GlobalVectors.Shape().Strides[1], 101) + TensorStrides.SetInt1D(GlobalVectors.Shape().Strides[2], 102) + TensorStrides.SetInt1D(Exts.Shape().Strides[0], 110) + TensorStrides.SetInt1D(Exts.Shape().Strides[1], 111) + TensorStrides.SetInt1D(Pools.Shape().Strides[0], 120) + TensorStrides.SetInt1D(Pools.Shape().Strides[1], 121) + TensorStrides.SetInt1D(Pools.Shape().Strides[2], 122) + TensorStrides.SetInt1D(PoolsInt.Shape().Strides[0], 130) + TensorStrides.SetInt1D(PoolsInt.Shape().Strides[1], 131) + TensorStrides.SetInt1D(PoolsInt.Shape().Strides[2], 132) + TensorStrides.SetInt1D(PathGBuf.Shape().Strides[0], 140) + TensorStrides.SetInt1D(PathGBuf.Shape().Strides[1], 141) + TensorStrides.SetInt1D(PathGBuf.Shape().Strides[2], 142) + TensorStrides.SetInt1D(PathGSyns.Shape().Strides[0], 150) + TensorStrides.SetInt1D(PathGSyns.Shape().Strides[1], 151) + TensorStrides.SetInt1D(Synapses.Shape().Strides[0], 160) + TensorStrides.SetInt1D(Synapses.Shape().Strides[1], 161) + TensorStrides.SetInt1D(SynapseTraces.Shape().Strides[0], 170) + TensorStrides.SetInt1D(SynapseTraces.Shape().Strides[1], 171) + TensorStrides.SetInt1D(SynapseTraces.Shape().Strides[2], 172) + v, _ := syVars.ValueByIndex(0, "TensorStrides", 0) + gpu.SetValueFrom(v, TensorStrides.Values) +} + // ReadFromGPU starts the process of copying vars to the GPU. func ReadFromGPU(vars ...GPUVars) { sy := GPUSystem diff --git a/axon/init-net.go b/axon/init-net.go index 3e9f952b..f2fb2540 100644 --- a/axon/init-net.go +++ b/axon/init-net.go @@ -54,8 +54,6 @@ func (nt *Network) InitWeights() { //types:add ToGPUAll() ToGPU(SynapseTracesVar) // only time we call this ToGPU(PathGBufVar, PathGSynsVar) // and this - // nt.GPU.SyncAllToGPU() - // nt.GPU.SyncGBufToGPU() } // InitTopoSWts initializes SWt structural weight parameters from diff --git a/axon/init-net.goal b/axon/init-net.goal index 81e25bc5..aa3c1ace 100644 --- a/axon/init-net.goal +++ b/axon/init-net.goal @@ -52,8 +52,6 @@ func (nt *Network) InitWeights() { //types:add ToGPUAll() ToGPU(SynapseTracesVar) // only time we call this ToGPU(PathGBufVar, PathGSynsVar) // and this - // nt.GPU.SyncAllToGPU() - // nt.GPU.SyncGBufToGPU() } // InitTopoSWts initializes SWt structural weight parameters from diff --git a/axon/network.go b/axon/network.go index b75a95e3..dc621456 100644 --- a/axon/network.go +++ b/axon/network.go @@ -28,7 +28,6 @@ import ( "cogentcore.org/core/base/slicesx" "cogentcore.org/core/base/timer" "cogentcore.org/core/core" - "cogentcore.org/core/goal/gosl/sltensor" "cogentcore.org/core/gpu" "cogentcore.org/core/icons" "cogentcore.org/core/tensor" @@ -740,18 +739,18 @@ func (nt *Network) Build() error { //types:add nix.RubiconNNegUSs = nt.Rubicon.NNegUSs nt.LayParams = make([]LayerParams, nLayers) - sltensor.SetShapeSizes(&nt.LayerStates, nLayers, maxData, int(LayerVarsN)) - sltensor.SetShapeSizes(&nt.Pools, totPools, maxData, int(PoolVarsN)) - sltensor.SetShapeSizes(&nt.PoolsInt, totPools, maxData, int(PoolIntVarsTot)) - sltensor.SetShapeSizes(&nt.Neurons, totNeurons, maxData, int(NeuronVarsN)) - sltensor.SetShapeSizes(&nt.NeuronAvgs, totNeurons, int(NeuronAvgVarsN)) - sltensor.SetShapeSizes(&nt.NeuronIxs, totNeurons, int(NeuronIndexVarsN)) nt.Paths = make([]*Path, totPaths) nt.PathParams = make([]PathParams, totPaths) - sltensor.SetShapeSizes(&nt.Exts, totExts, maxData) - sltensor.SetShapeSizes(&nt.GlobalScalars, int(GlobalScalarVarsN), maxData) - sltensor.SetShapeSizes(&nt.GlobalVectors, int(GlobalVectorVarsN), int(MaxGlobalVecN), maxData) + nt.LayerStates.SetShapeSizes(nLayers, maxData, int(LayerVarsN)) + nt.Pools.SetShapeSizes(totPools, maxData, int(PoolVarsN)) + nt.PoolsInt.SetShapeSizes(totPools, maxData, int(PoolIntVarsTot)) + nt.Neurons.SetShapeSizes(totNeurons, maxData, int(NeuronVarsN)) + nt.NeuronAvgs.SetShapeSizes(totNeurons, int(NeuronAvgVarsN)) + nt.NeuronIxs.SetShapeSizes(totNeurons, int(NeuronIndexVarsN)) + nt.Exts.SetShapeSizes(totExts, maxData) + nt.GlobalScalars.SetShapeSizes(int(GlobalScalarVarsN), maxData) + nt.GlobalVectors.SetShapeSizes(int(GlobalVectorVarsN), int(MaxGlobalVecN), maxData) nt.SetAsCurrent() @@ -835,13 +834,13 @@ func (nt *Network) Build() error { //types:add } nt.NetworkIxs[0].NSyns = uint32(totSynapses) - sltensor.SetShapeSizes(&nt.Synapses, totSynapses, int(SynapseVarsN)) - sltensor.SetShapeSizes(&nt.SynapseTraces, totSynapses, int(SynapseTraceVarsN), maxData) - sltensor.SetShapeSizes(&nt.SynapseIxs, totSynapses, int(SynapseIndexVarsN)) - sltensor.SetShapeSizes(&nt.PathSendCon, totSendCon, 2) - sltensor.SetShapeSizes(&nt.PathRecvCon, totRecvCon, 2) - sltensor.SetShapeSizes(&nt.RecvPathIxs, rpathIndex) - sltensor.SetShapeSizes(&nt.RecvSynIxs, totSynapses) + nt.Synapses.SetShapeSizes(totSynapses, int(SynapseVarsN)) + nt.SynapseTraces.SetShapeSizes(totSynapses, int(SynapseTraceVarsN), maxData) + nt.SynapseIxs.SetShapeSizes(totSynapses, int(SynapseIndexVarsN)) + nt.PathSendCon.SetShapeSizes(totSendCon, 2) + nt.PathRecvCon.SetShapeSizes(totRecvCon, 2) + nt.RecvPathIxs.SetShapeSizes(rpathIndex) + nt.RecvSynIxs.SetShapeSizes(totSynapses) // distribute synapses, send syIndex := 0 @@ -954,6 +953,7 @@ func ToGPUSynapses() { // ToGPUAll copies all state up to the GPU. Only for InitWeights. func ToGPUAll() { + ToGPUTensorStrides() ToGPUIndexes() ToGPUParams() ToGPULayersNeurons() @@ -1005,8 +1005,8 @@ func (nt *Network) BuildPathGBuf() { } nix.MaxDelay = maxDel mxlen := maxDel + 1 - sltensor.SetShapeSizes(&nt.PathGBuf, int(nptneur), int(maxData), int(mxlen)) - sltensor.SetShapeSizes(&nt.PathGSyns, int(nptneur), int(maxData)) + nt.PathGBuf.SetShapeSizes(int(nptneur), int(maxData), int(mxlen)) + nt.PathGSyns.SetShapeSizes(int(nptneur), int(maxData)) npti := uint32(0) for _, ly := range nt.Layers { diff --git a/axon/network.goal b/axon/network.goal index ad563dbd..e6204971 100644 --- a/axon/network.goal +++ b/axon/network.goal @@ -26,7 +26,6 @@ import ( "cogentcore.org/core/base/slicesx" "cogentcore.org/core/base/timer" "cogentcore.org/core/core" - "cogentcore.org/core/goal/gosl/sltensor" "cogentcore.org/core/gpu" "cogentcore.org/core/icons" "cogentcore.org/core/tensor" @@ -737,18 +736,18 @@ func (nt *Network) Build() error { //types:add nix.RubiconNNegUSs = nt.Rubicon.NNegUSs nt.LayParams = make([]LayerParams, nLayers) - sltensor.SetShapeSizes(&nt.LayerStates, nLayers, maxData, int(LayerVarsN)) - sltensor.SetShapeSizes(&nt.Pools, totPools, maxData, int(PoolVarsN)) - sltensor.SetShapeSizes(&nt.PoolsInt, totPools, maxData, int(PoolIntVarsTot)) - sltensor.SetShapeSizes(&nt.Neurons, totNeurons, maxData, int(NeuronVarsN)) - sltensor.SetShapeSizes(&nt.NeuronAvgs, totNeurons, int(NeuronAvgVarsN)) - sltensor.SetShapeSizes(&nt.NeuronIxs, totNeurons, int(NeuronIndexVarsN)) nt.Paths = make([]*Path, totPaths) nt.PathParams = make([]PathParams, totPaths) - sltensor.SetShapeSizes(&nt.Exts, totExts, maxData) - sltensor.SetShapeSizes(&nt.GlobalScalars, int(GlobalScalarVarsN), maxData) - sltensor.SetShapeSizes(&nt.GlobalVectors, int(GlobalVectorVarsN), int(MaxGlobalVecN), maxData) + nt.LayerStates.SetShapeSizes(nLayers, maxData, int(LayerVarsN)) + nt.Pools.SetShapeSizes(totPools, maxData, int(PoolVarsN)) + nt.PoolsInt.SetShapeSizes(totPools, maxData, int(PoolIntVarsTot)) + nt.Neurons.SetShapeSizes(totNeurons, maxData, int(NeuronVarsN)) + nt.NeuronAvgs.SetShapeSizes(totNeurons, int(NeuronAvgVarsN)) + nt.NeuronIxs.SetShapeSizes(totNeurons, int(NeuronIndexVarsN)) + nt.Exts.SetShapeSizes(totExts, maxData) + nt.GlobalScalars.SetShapeSizes(int(GlobalScalarVarsN), maxData) + nt.GlobalVectors.SetShapeSizes(int(GlobalVectorVarsN), int(MaxGlobalVecN), maxData) nt.SetAsCurrent() @@ -832,13 +831,13 @@ func (nt *Network) Build() error { //types:add } nt.NetworkIxs[0].NSyns = uint32(totSynapses) - sltensor.SetShapeSizes(&nt.Synapses, totSynapses, int(SynapseVarsN)) - sltensor.SetShapeSizes(&nt.SynapseTraces, totSynapses, int(SynapseTraceVarsN), maxData) - sltensor.SetShapeSizes(&nt.SynapseIxs, totSynapses, int(SynapseIndexVarsN)) - sltensor.SetShapeSizes(&nt.PathSendCon, totSendCon, 2) - sltensor.SetShapeSizes(&nt.PathRecvCon, totRecvCon, 2) - sltensor.SetShapeSizes(&nt.RecvPathIxs, rpathIndex) - sltensor.SetShapeSizes(&nt.RecvSynIxs, totSynapses) + nt.Synapses.SetShapeSizes(totSynapses, int(SynapseVarsN)) + nt.SynapseTraces.SetShapeSizes(totSynapses, int(SynapseTraceVarsN), maxData) + nt.SynapseIxs.SetShapeSizes(totSynapses, int(SynapseIndexVarsN)) + nt.PathSendCon.SetShapeSizes(totSendCon, 2) + nt.PathRecvCon.SetShapeSizes(totRecvCon, 2) + nt.RecvPathIxs.SetShapeSizes(rpathIndex) + nt.RecvSynIxs.SetShapeSizes(totSynapses) // distribute synapses, send syIndex := 0 @@ -951,6 +950,7 @@ func ToGPUSynapses() { // ToGPUAll copies all state up to the GPU. Only for InitWeights. func ToGPUAll() { + ToGPUTensorStrides() ToGPUIndexes() ToGPUParams() ToGPULayersNeurons() @@ -1002,8 +1002,8 @@ func (nt *Network) BuildPathGBuf() { } nix.MaxDelay = maxDel mxlen := maxDel + 1 - sltensor.SetShapeSizes(&nt.PathGBuf, int(nptneur), int(maxData), int(mxlen)) - sltensor.SetShapeSizes(&nt.PathGSyns, int(nptneur), int(maxData)) + nt.PathGBuf.SetShapeSizes(int(nptneur), int(maxData), int(mxlen)) + nt.PathGSyns.SetShapeSizes(int(nptneur), int(maxData)) npti := uint32(0) for _, ly := range nt.Layers { diff --git a/axon/shaders/ApplyExtsNeuron.wgsl b/axon/shaders/ApplyExtsNeuron.wgsl index e7baabfa..14ed4bc3 100644 --- a/axon/shaders/ApplyExtsNeuron.wgsl +++ b/axon/shaders/ApplyExtsNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { ApplyExtsNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_ApplyExtFlags(ly: ptr, clearMask: ptr,setMask: ptr, toTarg: ptr) { *clearMask = NeuronHasExt | NeuronHasTarg | NeuronHasCmpr; *toTarg = false; @@ -99,8 +93,8 @@ fn LayerParams_ApplyExtFlags(ly: ptr, clearMask: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Target))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Target))] = 0.0; NeuronClearFlag(NeuronHasExt|NeuronHasTarg|NeuronHasCmpr, ni, di); } fn LayerParams_ApplyExtValue(ly: ptr, ni: u32,di: u32, val: f32) { @@ -112,9 +106,9 @@ fn LayerParams_ApplyExtValue(ly: ptr, ni: u32,di: u32, val var toTarg: bool; LayerParams_ApplyExtFlags(ly, &clearMask, &setMask, &toTarg); if (toTarg) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Target))] = val; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Target))] = val; } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = val; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = val; } NeuronClearFlag(clearMask, ni, di); NeuronSetFlag(setMask, ni, di); @@ -124,21 +118,22 @@ fn LayerParams_ApplyExtsNeuron(ly: ptr, ni: u32,di: u32) { LayerParams_InitExt(ly, ni, di); if (IsExtLayerType((*ly).Type)) { var ei = (*ly).Indexes.ExtsSt + lni; - LayerParams_ApplyExtValue(ly, ni, di, Exts[IndexF322D(Exts[0], Exts[1], u32(ei),u32(di))]); + LayerParams_ApplyExtValue(ly, ni, di, Exts[Index2D(TensorStrides[110], TensorStrides[111], + u32(ei), u32(di))]); } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn ApplyExtsNeuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_ApplyExtsNeuron(&layers, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -158,12 +153,12 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" fn NeuronSetFlag(flag: NeuronFlags, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))] = bitcast(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))]) | u32(flag)); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))] = bitcast(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))]) | u32(flag)); } fn NeuronClearFlag(flag: NeuronFlags, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))] = bitcast(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))]) & ~ u32(flag)); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))] = bitcast(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))]) & ~ u32(flag)); } struct SpikeParams { Thr: f32, @@ -289,7 +284,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -301,7 +296,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -309,7 +304,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -325,7 +320,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -337,7 +332,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -357,7 +352,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -369,7 +364,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -381,7 +376,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -393,7 +388,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -409,7 +404,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -417,7 +412,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -444,7 +439,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -464,9 +459,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -490,10 +485,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -513,7 +508,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -532,7 +527,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -604,7 +599,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -616,7 +611,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -633,9 +628,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -679,7 +674,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -723,7 +718,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -761,7 +756,7 @@ fn IsExtLayerType(lt: LayerTypes) -> bool { }return false; } -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -775,13 +770,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -875,7 +870,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -885,9 +880,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -901,7 +896,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -909,7 +904,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -925,7 +920,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -950,7 +945,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1059,7 +1054,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1106,7 +1101,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1121,7 +1116,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1147,7 +1142,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1155,7 +1150,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1188,14 +1183,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1218,7 +1213,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1226,7 +1221,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1244,7 +1239,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1252,11 +1247,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1272,7 +1267,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1362,7 +1357,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/Beta1Neuron.wgsl b/axon/shaders/Beta1Neuron.wgsl index 37e88d39..9764c737 100644 --- a/axon/shaders/Beta1Neuron.wgsl +++ b/axon/shaders/Beta1Neuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,45 +59,37 @@ fn main(@builtin(global_invocation_id) idx: vec3) { Beta1Neuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_Beta1Neuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Beta1))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Beta1))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn Beta1Neuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_Beta1Neuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -115,7 +109,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -240,7 +234,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -252,7 +246,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -260,7 +254,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -276,7 +270,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -288,7 +282,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -308,7 +302,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -320,7 +314,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -332,7 +326,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -344,7 +338,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -360,7 +354,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -368,7 +362,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -395,7 +389,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -415,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -441,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -464,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -483,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -555,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -567,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -584,9 +578,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -630,7 +624,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -674,7 +668,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -707,7 +701,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -721,13 +715,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -821,7 +815,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -831,9 +825,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -847,7 +841,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -855,7 +849,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -871,7 +865,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -896,7 +890,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1005,7 +999,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1052,7 +1046,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1067,7 +1061,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1093,7 +1087,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1101,7 +1095,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1134,14 +1128,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1164,7 +1158,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1172,7 +1166,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1190,7 +1184,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1198,11 +1192,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1218,7 +1212,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1308,7 +1302,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/Beta2Neuron.wgsl b/axon/shaders/Beta2Neuron.wgsl index a3d5f6ee..f0d3b6a1 100644 --- a/axon/shaders/Beta2Neuron.wgsl +++ b/axon/shaders/Beta2Neuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,45 +59,37 @@ fn main(@builtin(global_invocation_id) idx: vec3) { Beta2Neuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_Beta2Neuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Beta2))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Beta2))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn Beta2Neuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_Beta2Neuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -115,7 +109,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -240,7 +234,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -252,7 +246,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -260,7 +254,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -276,7 +270,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -288,7 +282,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -308,7 +302,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -320,7 +314,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -332,7 +326,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -344,7 +338,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -360,7 +354,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -368,7 +362,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -395,7 +389,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -415,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -441,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -464,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -483,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -555,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -567,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -584,9 +578,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -630,7 +624,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -674,7 +668,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -707,7 +701,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -721,13 +715,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -821,7 +815,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -831,9 +825,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -847,7 +841,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -855,7 +849,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -871,7 +865,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -896,7 +890,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1005,7 +999,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1052,7 +1046,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1067,7 +1061,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1093,7 +1087,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1101,7 +1095,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1134,14 +1128,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1164,7 +1158,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1172,7 +1166,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1190,7 +1184,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1198,11 +1192,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1218,7 +1212,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1308,7 +1302,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/BetweenGi.wgsl b/axon/shaders/BetweenGi.wgsl index 0281aa80..6429782d 100644 --- a/axon/shaders/BetweenGi.wgsl +++ b/axon/shaders/BetweenGi.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,38 +59,31 @@ fn main(@builtin(global_invocation_id) idx: vec3) { BetweenGi(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_BetweenGi(ly: ptr, ctx: ptr, di: u32) { var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); - var maxGi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(lpi),u32(di),u32(TotalGi))]; + var maxGi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(lpi), u32(di), u32(TotalGi))]; maxGi = LayerParams_BetweenLayerGiMax(ly, di, maxGi, (*ly).LayInhib.Index1); maxGi = LayerParams_BetweenLayerGiMax(ly, di, maxGi, (*ly).LayInhib.Index2); maxGi = LayerParams_BetweenLayerGiMax(ly, di, maxGi, (*ly).LayInhib.Index3); maxGi = LayerParams_BetweenLayerGiMax(ly, di, maxGi, (*ly).LayInhib.Index4); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(lpi),u32(di),u32(TotalGi))] = maxGi; // our inhib is max of us and everyone in the layer pool + Pools[Index3D(TensorStrides[120], TensorStrides[121], // our inhib is max of us and everyone in the layer pool + TensorStrides[122], u32(lpi), u32(di), u32(TotalGi))] = maxGi; } fn LayerParams_BetweenLayerGiMax(ly: ptr, di: u32, maxGi: f32, layIndex: i32) -> f32 { if (layIndex < 0) { @@ -96,13 +91,13 @@ fn LayerParams_BetweenLayerGiMax(ly: ptr, di: u32, maxGi: } var oly = Layers[u32(layIndex)]; var opi = LayerParams_PoolIndex(&oly, u32(u32(0))); - var ogi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(opi),u32(di),u32(TotalGi))]; + var ogi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(opi), u32(di), u32(TotalGi))]; if (ogi > maxGi) { return ogi; }return maxGi; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn BetweenGi(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); @@ -111,7 +106,7 @@ fn BetweenGi(i: u32) { //gosl:kernel Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -131,7 +126,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -256,7 +251,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -268,7 +263,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -276,7 +271,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -292,7 +287,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -304,7 +299,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -324,7 +319,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -336,7 +331,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -348,7 +343,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -360,7 +355,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -376,7 +371,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -384,7 +379,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -411,7 +406,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -431,9 +426,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -457,10 +452,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -480,7 +475,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -499,7 +494,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -571,7 +566,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -583,7 +578,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -600,9 +595,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -646,7 +641,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -693,7 +688,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -726,7 +721,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -740,13 +735,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -840,7 +835,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -850,9 +845,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -866,7 +861,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -874,7 +869,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -890,7 +885,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -915,7 +910,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1024,7 +1019,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1071,7 +1066,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1086,7 +1081,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1112,7 +1107,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1120,7 +1115,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1153,14 +1148,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1183,7 +1178,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1191,7 +1186,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1209,7 +1204,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1217,11 +1212,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1237,7 +1232,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1327,7 +1322,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/CycleInc.wgsl b/axon/shaders/CycleInc.wgsl index 4bae4b81..b93b5645 100644 --- a/axon/shaders/CycleInc.wgsl +++ b/axon/shaders/CycleInc.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,32 +59,24 @@ fn main(@builtin(global_invocation_id) idx: vec3) { CycleInc(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" fn CycleInc(i: u32) { //gosl:kernel if (i != 0) { return; @@ -92,7 +86,7 @@ fn CycleInc(i: u32) { //gosl:kernel Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -112,7 +106,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -237,7 +231,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -249,7 +243,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -257,7 +251,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -273,7 +267,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -285,7 +279,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -305,7 +299,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -317,7 +311,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -329,7 +323,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -341,7 +335,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -357,7 +351,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -365,7 +359,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -393,7 +387,7 @@ fn Context_CycleInc(ctx: ptr) { RandCounter_Add(&(*ctx).RandCounter, u32(RandFunIndexN)); } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -413,9 +407,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -439,10 +433,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -462,7 +456,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -481,7 +475,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -553,7 +547,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -565,7 +559,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -582,9 +576,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -628,7 +622,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -672,7 +666,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -705,7 +699,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -719,13 +713,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -819,7 +813,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -829,9 +823,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -845,7 +839,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -853,7 +847,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -869,7 +863,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -894,7 +888,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1003,7 +997,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1050,7 +1044,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1065,7 +1059,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1091,7 +1085,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1099,7 +1093,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1132,14 +1126,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1162,7 +1156,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1170,7 +1164,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1188,7 +1182,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1196,11 +1190,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1216,7 +1210,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1306,7 +1300,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/CycleNeuron.wgsl b/axon/shaders/CycleNeuron.wgsl index 6bf45630..03f53d73 100644 --- a/axon/shaders/CycleNeuron.wgsl +++ b/axon/shaders/CycleNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,47 +59,40 @@ fn main(@builtin(global_invocation_id) idx: vec3) { CycleNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; -} +//////// import: "vars.go" -///////////// import: "vars.go" - -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn SetNeuronExtPosNeg(ctx: ptr, ni: u32,di: u32, val: f32) { if (ni == 0) { if (val >= 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = val; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = val; } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = f32(0); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = f32(0); } } else { if (val >= 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = f32(0); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = f32(0); } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = -val; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Ext))] = -val; } } } fn LayerParams_CycleNeuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - var pi = LayerParams_PoolIndex(ly, NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnSubPool))]); + var pi = LayerParams_PoolIndex(ly, NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnSubPool))]); var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); LayerParams_GInteg(ly, ctx, pi, ni, di); LayerParams_SpikeFromG(ly, ctx, lpi, ni, di); @@ -108,7 +103,7 @@ fn LayerParams_PulvinarDriver(ly: ptr, ctx: ptr, ctx: ptr, pi: u32,ni: u32,di: u32) { @@ -116,7 +111,8 @@ fn LayerParams_GInteg(ly: ptr, ctx: ptr, var nonDrivePct = f32(0); if ((*ly).Type == PulvinarLayer) { LayerParams_PulvinarDriver(ly, ctx, ni-(*ly).Indexes.NeurSt, di, &drvGe, &nonDrivePct); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = nonDrivePct; // use for regulating inhibition + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // use for regulating inhibition + u32(ni), u32(di), u32(Ext))] = nonDrivePct; } var saveVal = LayerParams_SpecialPreGs(ly, ctx, pi, ni, di, drvGe, nonDrivePct); LayerParams_GFromRawSyn(ly, ctx, ni, di); @@ -128,84 +124,84 @@ fn LayerParams_SpecialPreGs(ly: ptr, ctx: ptr 0; + var pni = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnNeurIndex))] - u32(PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolNeurSt))]); + var nrnCtxtGe = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))]; + var nrnGeRaw = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))]; + var hasRew = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0; switch ((*ly).Type) { case PTPredLayer, CTLayer: { var geCtxt = (*ly).CT.GeGain * nrnCtxtGe; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] += geCtxt; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] += geCtxt; if ((*ly).CT.DecayDt > 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))] -= (*ly).CT.DecayDt * nrnCtxtGe; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))] -= (*ly).CT.DecayDt * nrnCtxtGe; } var ctxExt = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geCtxt); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] += ctxExt; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] += ctxExt; saveVal = ctxExt; } // used In PostGs to set nrn.GeExt case PTMaintLayer: { if ((*ly).Acts.SMaint.On == 1) { - saveVal = (*ly).Acts.SMaint.Inhib * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // used In PostGs to set nrn.GeExt - 2], u32(ni),u32(di),u32(GMaintRaw))]; + saveVal = (*ly).Acts.SMaint.Inhib * Neurons[Index3D(TensorStrides[60], TensorStrides[61], // used In PostGs to set nrn.GeExt + TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))]; } } case PulvinarLayer: { if ((*ctx).PlusPhase == 0) { break; } - saveVal = nonDrivePct*Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] + DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, drvGe); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = nonDrivePct*nrnGeRaw + drvGe; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = saveVal; + saveVal = nonDrivePct*Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] + DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, drvGe); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = nonDrivePct*nrnGeRaw + drvGe; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = saveVal; } case VSGatedLayer: { var dr = f32(0); if (pil == 0) { - dr = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixJustGated),u32(di))]; + dr = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixJustGated), u32(di))]; } else { - dr = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixHasGated),u32(di))]; + dr = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixHasGated), u32(di))]; } dr = abs(dr); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = dr; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, dr); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = dr; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, dr); } case BLALayer: { if (NeuroModParams_IsBLAExt(&(*ly).Learn.NeuroMod)) { - var md = max(-GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // ext is modulated by negative da - 1], u32(GvDA),u32(di))], f32(0)); - var geCtxt = md * (*ly).CT.GeGain * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] += geCtxt; + var md = max(-GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // ext is modulated by negative da + u32(GvDA), u32(di))], f32(0)); + var geCtxt = md * (*ly).CT.GeGain * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] += geCtxt; var ctxExt = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geCtxt); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] += ctxExt; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] += ctxExt; saveVal = ctxExt; // used In PostGs to set nrn.GeExt } } case LHbLayer: { var geRaw = f32(0); if (ni == 0) { - geRaw = 0.2 * abs(GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvLHbDip),u32(di))]); + geRaw = 0.2 * abs(GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvLHbDip), u32(di))]); } else { - geRaw = 0.2 * abs(GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvLHbBurst),u32(di))]); + geRaw = 0.2 * abs(GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvLHbBurst), u32(di))]); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = geRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = geRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); } case DrivesLayer: { - var dr = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvDrives),u32(pil - 1),u32(di))]; + var dr = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvDrives), u32(pil - 1), u32(di))]; var geRaw = dr; if (dr > 0) { geRaw = PopCodeParams_EncodeGe(&(*ly).Acts.PopCode, pni, pnn, dr); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = geRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = geRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); } case UrgencyLayer: { - var ur = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvUrgency),u32(di))]; + var ur = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvUrgency), u32(di))]; var geRaw = ur; if (ur > 0) { geRaw = PopCodeParams_EncodeGe(&(*ly).Acts.PopCode, pni, pnn, ur); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = geRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = geRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, geRaw); } case USLayer: { var us = RubiconUSStimValue(di, pil-1, (*ly).Learn.NeuroMod.Valence); @@ -214,51 +210,51 @@ fn LayerParams_SpecialPreGs(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr, ni: u32,di: u32, saveVal: f32) { switch ((*ly).Type) { case PulvinarLayer, PTMaintLayer, CTLayer, BLALayer: { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = saveVal; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = saveVal; } case PTPredLayer: { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = saveVal; - var orig = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = saveVal; + var orig = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))]; if (orig < 0.05) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Ge))] = 0.0; } } default: { @@ -283,9 +280,9 @@ fn LayerParams_SpecialPostGs(ly: ptr, ctx: ptr, ctx: ptr, ni: u32,di: u32) { var extraRaw = f32(0); var extraSyn = f32(0); - var nrnGModRaw = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))]; - var nrnGModSyn = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))]; - var ach = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]; + var nrnGModRaw = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))]; + var nrnGModSyn = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))]; + var ach = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]; switch ((*ly).Type) { case PTMaintLayer: { var md = (*ly).Acts.Dend.ModGain * nrnGModSyn; @@ -293,8 +290,8 @@ fn LayerParams_GFromRawSyn(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr 1) { md = f32(1); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] *= md; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] *= md; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] *= md; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] *= md; } } } - var geRaw = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))]; - var geSyn = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))]; + var geRaw = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))]; + var geSyn = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))]; ActParams_NMDAFromRaw(&(*ly).Acts, ctx, ni, di, geRaw+extraRaw); ActParams_MaintNMDAFromRaw(&(*ly).Acts, ctx, ni, di); // uses GMaintRaw directly LearnNeurParams_LrnNMDAFromRaw(&(*ly).Learn, ctx, ni, di, geRaw); ActParams_GvgccFromVm(&(*ly).Acts, ctx, ni, di); - var ege = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))] + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))] + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))] + extraSyn; + var ege = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))] + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))] + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))] + extraSyn; ActParams_GeFromSyn(&(*ly).Acts, ctx, ni, di, geSyn, ege); // sets nrn.GeExt too ActParams_GkFromVm(&(*ly).Acts, ctx, ni, di); ActParams_GSkCaFromCa(&(*ly).Acts, ctx, ni, di); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] = ActParams_GiFromSyn(&(*ly).Acts, ctx, ni, di, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] = ActParams_GiFromSyn(&(*ly).Acts, ctx, ni, di, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))]); } fn LayerParams_GiInteg(ly: ptr, ctx: ptr, pi: u32,ni: u32,di: u32) { - var giMult = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerGiMult))]; - var gi = giMult*Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))] + NeuroModParams_GiFromACh(&(*ly).Learn.NeuroMod, GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]); - var ssgi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] = gi; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = 0.0; + var giMult = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerGiMult))]; + var gi = giMult*Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))] + NeuroModParams_GiFromACh(&(*ly).Learn.NeuroMod, GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]); + var ssgi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] = gi; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = 0.0; if ((*ctx).PlusPhase == 1 && (*ly).Type == PulvinarLayer) { - var ext = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // nonDrivePct - 2], u32(ni),u32(di),u32(Ext))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = ext * (*ly).Acts.Dend.SSGi * ssgi; + var ext = Neurons[Index3D(TensorStrides[60], TensorStrides[61], // nonDrivePct + TensorStrides[62], u32(ni), u32(di), u32(Ext))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = ext * (*ly).Acts.Dend.SSGi * ssgi; } else { if (!((*ly).Acts.Clamp.IsInput == 1 || (*ly).Acts.Clamp.IsTarget == 1)) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = (*ly).Acts.Dend.SSGi * ssgi; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = (*ly).Acts.Dend.SSGi * ssgi; } } - var vm = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))]; - var nrnGABAB = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))]; - var nrnGABABx = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))]; + var vm = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))]; + var nrnGABAB = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))]; + var nrnGABABx = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))]; GABABParams_GABAB(&(*ly).Acts.GabaB, gi, &nrnGABAB, &nrnGABABx); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))] = nrnGABAB; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))] = nrnGABABx; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))] = nrnGABAB; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))] = nrnGABABx; var nrnGgabaB = GABABParams_GgabaB(&(*ly).Acts.GabaB, nrnGABAB, vm); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))] = nrnGgabaB; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] += nrnGgabaB; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(GgabaB))] = nrnGgabaB; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Gk))] += nrnGgabaB; } fn LayerParams_GNeuroMod(ly: ptr, ctx: ptr, ni: u32,di: u32) { - var ggain = NeuroModParams_GGain(&(*ly).Learn.NeuroMod, GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvDA),u32(di))] + GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvDAtonic),u32(di))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] *= ggain; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] *= ggain; + var ggain = NeuroModParams_GGain(&(*ly).Learn.NeuroMod, GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvDA), u32(di))] + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvDAtonic), u32(di))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] *= ggain; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Gi))] *= ggain; } fn LayerParams_SpikeFromG(ly: ptr, ctx: ptr, lpi: u32,ni: u32,di: u32) { ActParams_VmFromG(&(*ly).Acts, ctx, ni, di); @@ -366,36 +366,36 @@ fn LayerParams_SpikeFromG(ly: ptr, ctx: ptr 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))] / lmax; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))] / lmax; } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))]; } if ((*ctx).Cycle >= (*ly).Acts.Dt.MaxCycStart) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMaxCa))] += (*ly).Learn.CaSpk.Dt.PDt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMaxCa))]); - var spkmax = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMaxCa))]; - if (spkmax > Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMax))]) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMax))] = spkmax; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMaxCa))] += (*ly).Learn.CaSpk.Dt.PDt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMaxCa))]); + var spkmax = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMaxCa))]; + if (spkmax > Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMax))]) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMax))] = spkmax; } } - var spk = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))]; + var spk = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))]; if (spk > 0) { var spksper = (*ctx).ThetaCycles / 8; var bin = min((*ctx).Cycle/spksper, 7); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SpikeBin0 + NeuronVars(bin)))] += spk; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SpikeBin0 + NeuronVars(bin)))] += spk; } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn CycleNeuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_CycleNeuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -415,12 +415,13 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" fn NeuronHasFlag(flag: NeuronFlags, ni: u32,di: u32) -> bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronSetFlag(flag: NeuronFlags, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))] = bitcast(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))]) | u32(flag)); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))] = bitcast(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))]) | u32(flag)); } struct SpikeParams { Thr: f32, @@ -634,8 +635,8 @@ fn ActParams_NMDAFromRaw(ac: ptr, ctx: ptr return; } var geT = max(geTot, 0.0); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))] = NMDAParams_NMDASyn(&(*ac).NMDA, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))], geT); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))] = NMDAParams_Gnmda(&(*ac).NMDA, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))] = NMDAParams_NMDASyn(&(*ac).NMDA, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))], geT); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))] = NMDAParams_Gnmda(&(*ac).NMDA, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))]); } fn ActParams_MaintNMDAFromRaw(ac: ptr, ctx: ptr, ni: u32,di: u32) { if ((*ac).MaintNMDA.Gbar == 0) { @@ -644,94 +645,96 @@ fn ActParams_MaintNMDAFromRaw(ac: ptr, ctx: ptr, ctx: ptr, ni: u32,di: u32) { var nix = NetworkIxs[0]; - var isi = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))]; + var isi = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))]; if (isi < (*ac).SMaint.ISI.Min || isi > (*ac).SMaint.ISI.Max) { return; } var ndi = di*nix.NNeurons + ni; - var smp = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SMaintP))]; + var smp = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SMaintP))]; smp *= GetRandomNumber(ndi, (*ctx).RandCounter.Counter, RandFunActSMaintP); var trg = SMaintParams_ExpInt(&(*ac).SMaint, isi); if (smp <= trg) { smp = f32(1); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] += (*ac).SMaint.Gbar; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))] += (*ac).SMaint.Gbar; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SMaintP))] = smp; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(SMaintP))] = smp; } fn ActParams_GvgccFromVm(ac: ptr, ctx: ptr, ni: u32,di: u32) { if ((*ac).VGCC.Gbar == 0) { return; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))] = VGCCParams_Gvgcc(&(*ac).VGCC, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))] = VGCCParams_Gvgcc(&(*ac).VGCC, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))]); var dm: f32; var dh: f32; - VGCCParams_DMHFromV(&(*ac).VGCC, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))], &dm, &dh); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))] += dm; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], - u32(ni),u32(di),u32(VgccH))] += dh; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] = VGCCParams_CaFromG(&(*ac).VGCC, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))]); + VGCCParams_DMHFromV(&(*ac).VGCC, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))], &dm, &dh); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))] += dm; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], + TensorStrides[62], u32(ni), u32(di), u32(VgccH))] += dh; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] = VGCCParams_CaFromG(&(*ac).VGCC, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))]); } fn ActParams_GkFromVm(ac: ptr, ctx: ptr, ni: u32,di: u32) { - var vm = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))]; - var vmd = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))]; - var mahpN = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))]; + var vm = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))]; + var vmd = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))]; + var mahpN = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))]; var gmahp = MahpParams_GmAHP(&(*ac).Mahp, vm, &mahpN); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))] = gmahp; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))] = mahpN; - var gsahp = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))] = gmahp; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))] = mahpN; + var gsahp = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))]; var gak = AKsParams_Gak(&(*ac).AK, vmd); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))] = gak; - var nkirM = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))] = gak; + var nkirM = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))]; var gkir = KirParams_Gkir(&(*ac).Kir, vm, nkirM); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))] = gkir; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))] = gkir; nkirM += KirParams_DM(&(*ac).Kir, VToBio(vm), nkirM); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))] = nkirM; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))] = nkirM; var gktot = gmahp + gsahp + gak + gkir; if ((*ac).KNa.On == 1) { - var gknaMed = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))]; - var gknaSlow = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))]; - KNaMedSlow_GcFromSpike(&(*ac).KNa, &gknaMed, &gknaSlow, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] > .5); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))] = gknaMed; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))] = gknaSlow; + var gknaMed = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))]; + var gknaSlow = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))]; + KNaMedSlow_GcFromSpike(&(*ac).KNa, &gknaMed, &gknaSlow, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] > .5); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))] = gknaMed; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))] = gknaSlow; gktot += gknaMed + gknaSlow; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], - u32(ni),u32(di),u32(Gk))] = gktot; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], + TensorStrides[62], u32(ni), u32(di), u32(Gk))] = gktot; } fn ActParams_GSkCaFromCa(ac: ptr, ctx: ptr, ni: u32,di: u32) { if ((*ac).SKCa.Gbar == 0) { return; } - var skcar = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))]; - var skcain = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))] = SKCaParams_MFromCa(&(*ac).SKCa, skcar, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))]); - SKCaParams_CaInRFromSpike(&(*ac).SKCa, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))], Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))], &skcain, &skcar); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))] = skcar; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))] = skcain; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))] = (*ac).SKCa.Gbar * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] += Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))]; + var skcar = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))]; + var skcain = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))] = SKCaParams_MFromCa(&(*ac).SKCa, skcar, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))]); + SKCaParams_CaInRFromSpike(&(*ac).SKCa, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))], Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))], &skcain, &skcar); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))] = skcar; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))] = skcain; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))] = (*ac).SKCa.Gbar * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))] += Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))]; } fn ActParams_GeFromSyn(ac: ptr, ctx: ptr, ni: u32,di: u32, geSyn: f32,geExt: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = 0.0; var geS = geSyn; var geE = geExt; if ((*ac).Clamp.Add == 1 && NeuronHasFlag(NeuronHasExt, ni, di)) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] * (*ac).Clamp.Ge; - geS += Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] * (*ac).Clamp.Ge; + geS += Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))]; } if ((*ac).Clamp.Add == 0 && NeuronHasFlag(NeuronHasExt, ni, di)) { - geS = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] * (*ac).Clamp.Ge; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = geS; - geE = f32(0); // no extra in this case + geS = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] * (*ac).Clamp.Ge; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(GeExt))] = geS; + geE = f32(0); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] = geS + geE; - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] < 0.0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] = geS + geE; + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] < 0.0) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] = 0.0; } ActParams_AddGeNoise(ac, ctx, ni, di); } @@ -739,20 +742,20 @@ fn ActParams_AddGeNoise(ac: ptr, ctx: ptr, if ((*ac).Noise.On == 0 || (*ac).Noise.Ge == 0) { return; } - var p = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoiseP))]; + var p = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoiseP))]; var ge = SpikeNoiseParams_PGe(&(*ac).Noise, ctx, &p, ni, di); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoiseP))] = p; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))] = DtParams_GeSynFromRaw(&(*ac).Dt, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))], ge); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] += Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoiseP))] = p; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))] = DtParams_GeSynFromRaw(&(*ac).Dt, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))], ge); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] += Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))]; } fn ActParams_AddGiNoise(ac: ptr, ctx: ptr, ni: u32,di: u32) { if ((*ac).Noise.On == 0 || (*ac).Noise.Gi == 0) { return; } - var p = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoiseP))]; + var p = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoiseP))]; var gi = SpikeNoiseParams_PGi(&(*ac).Noise, ctx, &p, ni, di); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoiseP))] = p; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))] = DtParams_GiSynFromRaw(&(*ac).Dt, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))], gi); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoiseP))] = p; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))] = DtParams_GiSynFromRaw(&(*ac).Dt, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))], gi); } fn ActParams_GiFromSyn(ac: ptr, ctx: ptr, ni: u32,di: u32, giSyn: f32) -> f32 { ActParams_AddGiNoise(ac, ctx, ni, di); @@ -781,22 +784,22 @@ fn ActParams_VmInteg(ac: ptr, vm: f32,dt: f32,ge: f32,gl: f3 } fn ActParams_VmFromG(ac: ptr, ctx: ptr, ni: u32,di: u32) { var updtVm = true; - var isi = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISI))]; + var isi = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISI))]; if ((*ac).Spikes.Tr > 0 && isi >= 0 && isi < f32((*ac).Spikes.Tr)) { updtVm = false; // don't update the spiking vm during refract } - var ge = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] * (*ac).Gbar.E; - var gi = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] * (*ac).Gbar.I; - var gk = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] * (*ac).Gbar.K; + var ge = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] * (*ac).Gbar.E; + var gi = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] * (*ac).Gbar.I; + var gk = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))] * (*ac).Gbar.K; var nvm: f32; var inet: f32; var expi: f32; if (updtVm) { - ActParams_VmInteg(ac, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))], (*ac).Dt.VmDt, ge, f32(f32(1)), gi, gk, &nvm, &inet); + ActParams_VmInteg(ac, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))], (*ac).Dt.VmDt, ge, f32(f32(1)), gi, gk, &nvm, &inet); if (updtVm && (*ac).Spikes.Exp == 1) { // add spike current if relevant var exVm: f32; - exVm = 0.5 * (nvm + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // midpoint for this - 2], u32(ni),u32(di),u32(Vm))]); + exVm = 0.5 * (nvm + Neurons[Index3D(TensorStrides[60], TensorStrides[61], // midpoint for this + TensorStrides[62], u32(ni), u32(di), u32(Vm))]); expi = (*ac).Gbar.L * (*ac).Spikes.ExpSlope * FastExp((exVm-(*ac).Spikes.Thr)/(*ac).Spikes.ExpSlope); if (expi > (*ac).Dt.VmTau) { @@ -805,30 +808,31 @@ fn ActParams_VmFromG(ac: ptr, ctx: ptr, ni inet += expi; nvm = ActParams_VmFromInet(ac, nvm, (*ac).Dt.VmDt, expi); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] = nvm; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Inet))] = inet; - } else { // decay back to VmR + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] = nvm; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Inet))] = inet; + } else { var dvm: f32; if (i32(isi) == (*ac).Spikes.Tr-1) { - dvm = (*ac).Spikes.VmR - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))]; + dvm = (*ac).Spikes.VmR - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))]; } else { - dvm = (*ac).Spikes.RDt * ((*ac).Spikes.VmR - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))]); + dvm = (*ac).Spikes.RDt * ((*ac).Spikes.VmR - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))]); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] += dvm; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Inet))] = dvm * (*ac).Dt.VmTau; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] += dvm; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Inet))] = dvm * (*ac).Dt.VmTau; } var glEff = f32(1); if (!updtVm) { glEff += (*ac).Dend.GbarR; } var giEff: f32; - giEff = gi + (*ac).Gbar.I*Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))]; - ActParams_VmInteg(ac, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))], (*ac).Dt.VmDendDt, ge, glEff, giEff, gk, &nvm, &inet); + giEff = gi + (*ac).Gbar.I*Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))]; + ActParams_VmInteg(ac, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))], (*ac).Dt.VmDendDt, ge, glEff, giEff, gk, &nvm, &inet); if (updtVm) { nvm = ActParams_VmFromInet(ac, nvm, (*ac).Dt.VmDendDt, (*ac).Dend.GbarExp*expi); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], - u32(ni),u32(di),u32(VmDend))] = nvm; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], + TensorStrides[62], u32(ni), u32(di), u32(VmDend))] = nvm; } fn ActParams_SpikeFromVmVars(ac: ptr, nrnISI: ptr,nrnISIAvg: ptr,nrnSpike: ptr,nrnSpiked: ptr,nrnAct: ptr, nrnVm: f32) { var thr: f32; @@ -872,21 +876,21 @@ fn ActParams_SpikeFromVmVars(ac: ptr, nrnISI: ptr, ctx: ptr, ni: u32,di: u32) { - var nrnISI = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISI))]; - var nrnISIAvg = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))]; - var nrnSpike = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))]; - var nrnSpiked = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spiked))]; - var nrnAct = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))]; - var nrnVm = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))]; + var nrnISI = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISI))]; + var nrnISIAvg = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))]; + var nrnSpike = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))]; + var nrnSpiked = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spiked))]; + var nrnAct = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))]; + var nrnVm = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))]; ActParams_SpikeFromVmVars(ac, &nrnISI, &nrnISIAvg, &nrnSpike, &nrnSpiked, &nrnAct, nrnVm); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISI))] = nrnISI; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))] = nrnISIAvg; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] = nrnSpike; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spiked))] = nrnSpiked; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = nrnAct; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISI))] = nrnISI; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))] = nrnISIAvg; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] = nrnSpike; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spiked))] = nrnSpiked; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = nrnAct; } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -910,7 +914,7 @@ fn AKsParams_Gak(ap: ptr, v: f32) -> f32 { return (*ap).Gbar * AKsParams_MFromVnorm(ap, v); } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -921,7 +925,7 @@ fn VToBio(vm: f32) -> f32 { return vm*100 - 100; } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -963,7 +967,7 @@ fn GABABParams_GgabaB(gp: ptr, gabaB: f32,vm: f32) -> f32 return (*gp).Gbar * GABABParams_GFromV(gp, vm) * (gabaB + (*gp).Gbase); } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -987,7 +991,7 @@ fn KirParams_Gkir(kp: ptr, v: f32, m: f32) -> f32 { return (*kp).Gbar * m; } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -1024,7 +1028,7 @@ fn KNaMedSlow_GcFromSpike(ka: ptr, gKNaM: ptr } } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -1064,7 +1068,7 @@ fn MahpParams_GmAHP(mp: ptr, v: f32, n: ptr) var g = (*mp).Tadj * (*mp).Gbar * *n;return g; } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -1100,7 +1104,7 @@ fn NMDAParams_Gnmda(np: ptr, nmda: f32,vm: f32) -> f32 { return (*np).Gbar * NMDAParams_MgGFromV(np, vm) * nmda; } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -1112,7 +1116,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -1149,7 +1153,7 @@ fn SKCaParams_MFromCa(sp: ptr, caR: f32,mcur: f32) -> f32 { }return mcur + (*sp).DeDt*(mas-mcur); } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -1193,7 +1197,7 @@ fn VGCCParams_CaFromG(np: ptr, v: f32,g: f32,ca: f32) -> f3 var vbio = VToBio(v);return -vbio * (*np).Ca * g; } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -1220,7 +1224,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -1246,9 +1250,9 @@ fn PulvParams_NonDrivePct(tp: ptr, drvMax: f32) -> f32 { return 1.0 - min(1.0, drvMax/(*tp).FullDriveAct); } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -1272,10 +1276,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -1295,7 +1299,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -1314,7 +1318,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -1386,7 +1390,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -1398,7 +1402,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -1415,9 +1419,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -1471,7 +1475,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -1518,7 +1522,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -1551,7 +1555,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -1565,13 +1569,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -1585,17 +1589,17 @@ struct LearnCaParams { } fn LearnCaParams_VgccCaFromSpike(np: ptr, ctx: ptr, ni: u32,di: u32) { if ((*np).SpkVGCC == 1) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] = (*np).SpkVgccCa * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] = (*np).SpkVgccCa * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))] += Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] - (*np).VgccDt*Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))] += Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] - (*np).VgccDt*Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))]; } fn LearnCaParams_LearnCas(np: ptr, ctx: ptr, ni: u32,di: u32) { LearnCaParams_VgccCaFromSpike(np, ctx, ni, di); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))] = (*np).NormInv * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))] + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))] += (*np).Dt.MDt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] += (*np).Dt.PDt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))] += (*np).Dt.DDt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaDiff))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))] = (*np).NormInv * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))] + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))] += (*np).Dt.MDt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] += (*np).Dt.PDt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))] += (*np).Dt.DDt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaDiff))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))]; } struct TrgAvgActParams { GiBaseInit: f32, @@ -1628,20 +1632,20 @@ struct LearnNeurParams { } fn LearnNeurParams_LrnNMDAFromRaw(ln: ptr, ctx: ptr, ni: u32,di: u32, geTot: f32) { var geEff = max(geTot, 0.0); - var vmd = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))] = NMDAParams_NMDASyn(&(*ln).LrnNMDA, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))], geEff); - var gnmda = NMDAParams_Gnmda(&(*ln).LrnNMDA, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))], vmd); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))] = f32(gnmda * NMDAParams_CaFromV(&(*ln).LrnNMDA, vmd)); + var vmd = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))] = NMDAParams_NMDASyn(&(*ln).LrnNMDA, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))], geEff); + var gnmda = NMDAParams_Gnmda(&(*ln).LrnNMDA, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))], vmd); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))] = f32(gnmda * NMDAParams_CaFromV(&(*ln).LrnNMDA, vmd)); } fn LearnNeurParams_CaFromSpike(ln: ptr, ctx: ptr, ni: u32,di: u32) { var caSyn: f32; - var caSpkM = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))]; - var caSpkP = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; - var caSpkD = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - NeurCaParams_CaFromSpike(&(*ln).CaSpk, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))], &caSyn, &caSpkM, &caSpkP, &caSpkD); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))] = caSpkM; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))] = caSpkP; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))] = caSpkD; + var caSpkM = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))]; + var caSpkP = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; + var caSpkD = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + NeurCaParams_CaFromSpike(&(*ln).CaSpk, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))], &caSyn, &caSpkM, &caSpkP, &caSpkD); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))] = caSpkM; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))] = caSpkP; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))] = caSpkD; LearnCaParams_LearnCas(&(*ln).CaLearn, ctx, ni, di); } struct SWtInitParams { @@ -1697,7 +1701,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -1707,7 +1711,7 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" fn FastExp(x: f32) -> f32 { if (x <= -88.02969) { // this doesn't add anything and -exp is main use-case anyway return f32(0.0); @@ -1717,7 +1721,7 @@ fn FastExp(x: f32) -> f32 { i += (((((((((((3537 * m) >> 16) + 13668) * m) >> 18) + 15817) * m) >> 14) - 80470) * m) >> 11);return bitcast(u32(i)); } -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -1731,7 +1735,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -1747,7 +1751,7 @@ fn F32_ClipValue(mr: ptr, val: f32) -> f32 { }return val; } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1763,7 +1767,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1825,7 +1829,7 @@ fn NeuroModParams_GiFromACh(nm: ptr, ach: f32) -> f32 { }return (*nm).AChDisInhib * ai; } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1934,7 +1938,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1981,7 +1985,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1996,7 +2000,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -2022,7 +2026,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -2030,7 +2034,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -2066,14 +2070,15 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } fn PoolNNeurons(pi: u32) -> i32 { - return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(0),u32(PoolNeurSt))]; + return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; @@ -2083,7 +2088,7 @@ fn GetRandomNumber(index: u32, counter: su64, funIndex: RandFunIndex) -> f32 { return RandFloat32(counter, u32(funIndex), index); } -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -2115,7 +2120,7 @@ fn TDDaParams_GeFromDA(tp: ptr, da: f32) -> f32 { return (*tp).TonicGe * (1.0 + da); } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -2123,7 +2128,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -2141,7 +2146,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -2149,24 +2154,24 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" fn RubiconUSStimValue(di: u32, usIndex: u32, valence: ValenceTypes) -> f32 { var nix = NetworkIxs[0]; var us = f32(0); switch (valence) { case Positive: { if (usIndex < nix.RubiconNPosUSs) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvUSpos),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvUSpos), u32(usIndex), u32(di))]; } } case Negative: { if (usIndex < nix.RubiconNNegUSs) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvUSneg),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvUSneg), u32(usIndex), u32(di))]; } } case Cost: { if (usIndex < nix.RubiconNCosts) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvCost),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvCost), u32(usIndex), u32(di))]; } } default: { @@ -2174,9 +2179,9 @@ fn RubiconUSStimValue(di: u32, usIndex: u32, valence: ValenceTypes) -> f32 { }return us; } -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -2192,7 +2197,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -2282,7 +2287,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/CyclePost.wgsl b/axon/shaders/CyclePost.wgsl index 2ddb8bdd..cbd0fd0d 100644 --- a/axon/shaders/CyclePost.wgsl +++ b/axon/shaders/CyclePost.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { CyclePost(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_CyclePost(ly: ptr, ctx: ptr, di: u32) { var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); LayerParams_CyclePostLayer(ly, ctx, lpi, di); @@ -126,8 +120,8 @@ fn LayerParams_CyclePost(ly: ptr, ctx: ptr, ctx: ptr, lpi: u32,di: u32) { var casp = PoolAvgMax(AMCaP, AMCycle, Max, lpi, di); if ((*ctx).Cycle >= (*ly).Acts.Dt.MaxCycStart && casp > 0.5) { // todo: param - if (LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRT))] <= 0) { - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRT))] = f32((*ctx).Cycle); + if (LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerRT))] <= 0) { + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerRT))] = f32((*ctx).Cycle); } } } @@ -140,82 +134,85 @@ fn LayerParams_LDTSrcLayAct(ly: ptr, layIndex: i32, di: u3 } fn LayerParams_CyclePostLDTLayer(ly: ptr, ctx: ptr, di: u32, srcLay1Act: f32,srcLay2Act: f32,srcLay3Act: f32,srcLay4Act: f32) { var ach = LDTParams_ACh(&(*ly).LDT, ctx, di, srcLay1Act, srcLay2Act, srcLay3Act, srcLay4Act); - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvAChRaw),u32(di))] = ach; - if (ach > GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // instant up - 1], u32(GvACh),u32(di))]) { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))] = ach; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvAChRaw), u32(di))] = ach; + if (ach > GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // instant up + u32(GvACh), u32(di))]) { + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))] = ach; } else { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))] += (*ly).Acts.Dt.IntDt * (ach - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]); + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))] += (*ly).Acts.Dt.IntDt * (ach - GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]); } } fn LayerParams_CyclePostRWDaLayer(ly: ptr, ctx: ptr, di: u32) { var pli = u32((*ly).RWDa.RWPredLayIndex); - var pred = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(pli),u32(di),u32(LayerRewPredPos))] - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(pli),u32(di),u32(LayerRewPredNeg))]; - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // record - 1], u32(GvRewPred),u32(di))] = pred; + var pred = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(pli), u32(di), u32(LayerRewPredPos))] - LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(pli), u32(di), u32(LayerRewPredNeg))]; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // record + u32(GvRewPred), u32(di))] = pred; var da = f32(0); - if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))] > 0) { - da = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvRew),u32(di))] - pred; + if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0) { + da = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvRew), u32(di))] - pred; } - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // updates global value that will be copied to layers next cycle. - 1], u32(GvDA),u32(di))] = da; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // updates global value that will be copied to layers next cycle. + u32(GvDA), u32(di))] = da; } fn LayerParams_CyclePostTDPredLayer(ly: ptr, ctx: ptr, di: u32) { if ((*ctx).PlusPhase == 0) { return; } - var pred = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRewPredPos))] - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRewPredNeg))]; - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvPrevPred),u32(di))] = pred; + var pred = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerRewPredPos))] - LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerRewPredNeg))]; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvPrevPred), u32(di))] = pred; } fn LayerParams_CyclePostTDIntegLayer(ly: ptr, ctx: ptr, di: u32) { var rew = f32(0); - if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))] > 0) { - rew = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvRew),u32(di))]; + if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0) { + rew = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvRew), u32(di))]; } var rpval = f32(0); if ((*ctx).PlusPhase == 1) { var pli = u32((*ly).TDInteg.TDPredLayIndex); - var pred = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(pli),u32(di),u32(LayerRewPredPos))] - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(pli),u32(di),u32(LayerRewPredNeg))]; + var pred = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(pli), u32(di), u32(LayerRewPredPos))] - LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(pli), u32(di), u32(LayerRewPredNeg))]; rpval = rew + (*ly).TDInteg.Discount*(*ly).TDInteg.PredGain*pred; - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRewPredPos))] = rpval; // our plus phase = new integrated value + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], // our plus phase = new integrated value + u32((*ly).Index), u32(di), u32(LayerRewPredPos))] = rpval; } else { - rpval = (*ly).TDInteg.PredGain * GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvPrevPred),u32(di))]; - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerRewPredNeg))] = rpval; // our minus phase = prior integrated value + rpval = (*ly).TDInteg.PredGain * GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvPrevPred), u32(di))]; + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], // our minus phase = prior integrated value + u32((*ly).Index), u32(di), u32(LayerRewPredNeg))] = rpval; } - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // global value will be copied to layers next cycle - 1], u32(GvRewPred),u32(di))] = rpval; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // global value will be copied to layers next cycle + u32(GvRewPred), u32(di))] = rpval; } fn LayerParams_CyclePostTDDaLayer(ly: ptr, ctx: ptr, di: u32) { var ili = u32((*ly).TDDa.TDIntegLayIndex); - var da = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(ili),u32(di),u32(LayerRewPredPos))] - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(ili),u32(di),u32(LayerRewPredNeg))]; + var da = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(ili), u32(di), u32(LayerRewPredPos))] - LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(ili), u32(di), u32(LayerRewPredNeg))]; if ((*ctx).PlusPhase == 0) { da = f32(0); } - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // updates global value that will be copied to layers next cycle. - 1], u32(GvDA),u32(di))] = da; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // updates global value that will be copied to layers next cycle. + u32(GvDA), u32(di))] = da; } fn LayerParams_CyclePostCeMLayer(ly: ptr, ctx: ptr, lpi: u32,di: u32) { var casd = PoolAvgMax(AMCaD, AMCycle, Max, lpi, di); if ((*ly).Learn.NeuroMod.Valence == Positive) { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvCeMpos),u32(di))] = casd; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvCeMpos), u32(di))] = casd; } else { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvCeMneg),u32(di))] = casd; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvCeMneg), u32(di))] = casd; } } fn LayerParams_CyclePostVTALayer(ly: ptr, ctx: ptr, di: u32) { - VTAParams_VTADA(&(*ly).VTA, ctx, di, GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))], (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ - 1], u32(GvHasRew),u32(di))] > 0)); + VTAParams_VTADA(&(*ly).VTA, ctx, di, GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))], (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], + u32(GvHasRew), u32(di))] > 0)); } fn LayerParams_CyclePostVSPatchLayer(ly: ptr, ctx: ptr, pi: u32,di: u32, spi: i32) { var casd = PoolAvgMax(AMCaD, AMCycle, Avg, pi, di); if ((*ly).Learn.NeuroMod.DAMod == D1Mod) { - GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvVSPatchD1),u32(u32(pi - 1)),u32(di))] = casd; + GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvVSPatchD1), u32(u32(pi - 1)), u32(di))] = casd; } else { - GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvVSPatchD2),u32(u32(pi - 1)),u32(di))] = casd; + GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], + u32(GvVSPatchD2), u32(u32(pi - 1)), u32(di))] = casd; } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn CyclePost(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); @@ -224,7 +221,7 @@ fn CyclePost(i: u32) { //gosl:kernel Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -244,7 +241,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -369,7 +366,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -381,7 +378,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -389,7 +386,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -405,7 +402,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -417,7 +414,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -437,7 +434,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -449,7 +446,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -461,7 +458,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -473,7 +470,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -489,7 +486,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -497,7 +494,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -524,7 +521,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -544,9 +541,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -570,10 +567,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -593,7 +590,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -612,7 +609,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -684,7 +681,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -696,7 +693,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -713,9 +710,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -759,7 +756,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -806,7 +803,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -839,7 +836,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -853,13 +850,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -953,7 +950,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -963,9 +960,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -979,7 +976,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -987,7 +984,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1003,7 +1000,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1028,7 +1025,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1137,7 +1134,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1184,7 +1181,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1199,7 +1196,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1235,9 +1232,9 @@ fn LayerParams_GatedFromCaPMax(ly: ptr, ctx: ptr thr; if (gthr) { anyGated = true; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] = 1; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] = 1; } else { - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] = 0; } } } else { @@ -1247,13 +1244,14 @@ fn LayerParams_GatedFromCaPMax(ly: ptr, ctx: ptr u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1330,7 +1329,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1338,7 +1337,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1368,14 +1367,14 @@ fn LDTParams_ACh(lp: ptr, ctx: ptr, di: u3 maxSrcAct = LDTParams_MaxSrcAct(lp, maxSrcAct, srcLay2Act); maxSrcAct = LDTParams_MaxSrcAct(lp, maxSrcAct, srcLay3Act); maxSrcAct = LDTParams_MaxSrcAct(lp, maxSrcAct, srcLay4Act); - var maintInh = (*lp).MaintInhib * GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvGoalMaint),u32(di))]; + var maintInh = (*lp).MaintInhib * GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvGoalMaint), u32(di))]; maintInh = min(1.0, maintInh); maxSrcAct *= (1.0 - maintInh); var ach = maxSrcAct; - if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))] > 0) { + if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0) { ach = f32(1); } else { - ach = max(ach, GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvUrgency),u32(di))]); + ach = max(ach, GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvUrgency), u32(di))]); }return ach; } struct VTAParams { @@ -1385,14 +1384,14 @@ struct VTAParams { pad: f32, } fn VTAParams_VTADA(vt: ptr, ctx: ptr, di: u32, ach: f32, hasRew: bool) { - var pvDA = (*vt).LHbGain * GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvLHbPVDA),u32(di))]; - var csNet = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvCeMpos),u32(di))] - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvCeMneg),u32(di))]; + var pvDA = (*vt).LHbGain * GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvLHbPVDA), u32(di))]; + var csNet = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvCeMpos), u32(di))] - GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvCeMneg), u32(di))]; var achMod = f32(0); if (ach >= (*vt).AChThr) { achMod = ach; } - var vsPatch = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // note: critical to use thresholded version - 1], u32(GvVSPatchPosThr),u32(di))]; + var vsPatch = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // note: critical to use thresholded version + u32(GvVSPatchPosThr), u32(di))]; if (csNet > 0) { csNet = max(0.0, csNet-vsPatch); // vspatch can shunt positive CS DA, but no dipping! that is lhb } @@ -1403,13 +1402,13 @@ fn VTAParams_VTADA(vt: ptr, ctx: ptr, di: } else { netDA = csDA; } - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // note: keeping this separately just for semantics - 1], u32(GvVtaDA),u32(di))] = netDA; - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // general neuromod DA - 1], u32(GvDA),u32(di))] = netDA; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // note: keeping this separately just for semantics + u32(GvVtaDA), u32(di))] = netDA; + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // general neuromod DA + u32(GvDA), u32(di))] = netDA; } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1417,11 +1416,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1437,7 +1436,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1527,7 +1526,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/DWtFromDiSyn.wgsl b/axon/shaders/DWtFromDiSyn.wgsl index b2f173a4..f666fb97 100644 --- a/axon/shaders/DWtFromDiSyn.wgsl +++ b/axon/shaders/DWtFromDiSyn.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,34 +59,26 @@ fn main(@builtin(global_invocation_id) idx: vec3) { DWtFromDiSyn(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -104,7 +98,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -229,7 +223,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -241,7 +235,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -249,7 +243,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -265,7 +259,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -277,7 +271,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -297,7 +291,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -309,7 +303,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -321,7 +315,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -333,7 +327,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -349,7 +343,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -357,7 +351,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -378,7 +372,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -398,9 +392,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -424,10 +418,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -447,7 +441,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -466,7 +460,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -538,7 +532,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -550,7 +544,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -567,9 +561,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -613,7 +607,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -657,7 +651,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -690,7 +684,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -704,26 +698,27 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn DWtFromDiSyn(syni: u32) { //gosl:kernel var ctx = Ctx[0]; - var pti = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynPathIndex))]; + var pti = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynPathIndex))]; var paths=Paths[pti]; PathParams_DWtFromDi(&paths, &ctx, syni); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" fn PathParams_DWtFromDi(pt: ptr, ctx: ptr, syni: u32) { var dwt = f32(0); for (var di = u32(0); di < (*ctx).NData; di++) { - dwt += SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))]; + dwt += SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))]; } - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DWt))] += dwt; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], + u32(syni), u32(DWt))] += dwt; } -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -817,7 +812,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -827,9 +822,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -843,7 +838,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -851,7 +846,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -867,7 +862,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -892,7 +887,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1001,7 +996,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1048,7 +1043,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1063,7 +1058,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1089,7 +1084,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1097,7 +1092,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1130,14 +1125,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1160,7 +1155,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1168,7 +1163,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1186,7 +1181,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1194,11 +1189,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1214,7 +1209,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1304,7 +1299,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/DWtSubMeanNeuron.wgsl b/axon/shaders/DWtSubMeanNeuron.wgsl index c38d82f5..f23590f5 100644 --- a/axon/shaders/DWtSubMeanNeuron.wgsl +++ b/axon/shaders/DWtSubMeanNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,34 +59,26 @@ fn main(@builtin(global_invocation_id) idx: vec3) { DWtSubMeanNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -104,7 +98,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -229,7 +223,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -241,7 +235,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -249,7 +243,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -265,7 +259,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -277,7 +271,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -297,7 +291,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -309,7 +303,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -321,7 +315,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -333,7 +327,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -349,7 +343,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -357,7 +351,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -378,7 +372,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -398,9 +392,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -424,10 +418,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -447,7 +441,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -466,7 +460,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -538,7 +532,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -550,7 +544,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -567,9 +561,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -613,7 +607,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -657,7 +651,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -690,7 +684,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -704,25 +698,25 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" fn LayerParams_DWtSubMean(ly: ptr, ctx: ptr, ri: u32) { var lni = ri - (*ly).Indexes.NeurSt; var rn = (*ly).Indexes.RecvN; for (var pi = u32(0); pi < rn; pi++) { - var pti = RecvPathIxs[IndexU321D(RecvPathIxs[0], u32((*ly).Indexes.RecvSt + pi))]; + var pti = RecvPathIxs[Index1D(TensorStrides[30], u32((*ly).Indexes.RecvSt + pi))]; var paths=Paths[pti]; PathParams_DWtSubMean(&paths, ctx, pti, ri, lni); } } -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn DWtSubMeanNeuron(ni: u32) { //gosl:kernel var ctx = Ctx[0]; - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_DWtSubMean(&layers, &ctx, ni); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" fn PathParams_DWtSubMean(pt: ptr, ctx: ptr, pti: u32,ri: u32,lni: u32) { if ((*pt).Learn.Learn == 0) { return; @@ -732,16 +726,16 @@ fn PathParams_DWtSubMean(pt: ptr, ctx: ptr, ctx: ptr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1340,7 +1334,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/DWtSyn.wgsl b/axon/shaders/DWtSyn.wgsl index 0e22ca9b..f97dcd40 100644 --- a/axon/shaders/DWtSyn.wgsl +++ b/axon/shaders/DWtSyn.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,34 +59,26 @@ fn main(@builtin(global_invocation_id) idx: vec3) { DWtSyn(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -104,7 +98,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -229,7 +223,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -241,7 +235,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -249,7 +243,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -265,7 +259,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -277,7 +271,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -297,7 +291,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -309,7 +303,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -321,7 +315,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -333,7 +327,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -349,7 +343,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -357,7 +351,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -384,7 +378,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -404,9 +398,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -430,10 +424,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -453,7 +447,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -472,7 +466,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -544,7 +538,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -556,7 +550,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -573,9 +567,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -626,7 +620,7 @@ fn SynCaLinear_FinalCa(kp: ptr, b0: f32,b1: f32,b2: f32,b3 *caD = (*kp).CaGain * BinWeights_Product(&(*kp).CaD, b0, b1, b2, b3, b4, b5, b6, b7); } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -673,7 +667,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -706,7 +700,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -720,27 +714,27 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn DWtSyn(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var syni = Context_ItemIndex(&ctx, i); - var pti = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynPathIndex))]; - var si = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynSendIndex))]; - var ri = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynRecvIndex))]; + var pti = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynPathIndex))]; + var si = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynSendIndex))]; + var ri = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynRecvIndex))]; var paths=Paths[pti]; var layers=Layers[Paths[pti].Indexes.RecvLayer]; PathParams_DWtSyn(&paths, &ctx, &layers, syni, si, ri, di); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" fn PathParams_DWtSyn(pt: ptr, ctx: ptr, rlay: ptr, syni: u32,si: u32,ri: u32,di: u32) { if ((*pt).Learn.Learn == 0) { return; } var isTarget = (*rlay).Acts.Clamp.IsTarget > 0; - var spi = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ri),u32(NrnSubPool))]; + var spi = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ri), u32(NrnSubPool))]; var pi = LayerParams_PoolIndex(rlay, spi); var lpi = LayerParams_PoolIndex(rlay, u32(u32(0))); switch ((*pt).Type) { @@ -775,22 +769,22 @@ fn PathParams_DWtSyn(pt: ptr, ctx: ptr, r } } fn PathParams_SynCa(pt: ptr, ctx: ptr, si: u32,ri: u32,di: u32, syCaP: ptr,syCaD: ptr) { - var rb0 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin0))]; - var sb0 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin0))]; - var rb1 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin1))]; - var sb1 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin1))]; - var rb2 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin2))]; - var sb2 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin2))]; - var rb3 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin3))]; - var sb3 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin3))]; - var rb4 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin4))]; - var sb4 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin4))]; - var rb5 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin5))]; - var sb5 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin5))]; - var rb6 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin6))]; - var sb6 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin6))]; - var rb7 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(SpikeBin7))]; - var sb7 = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(SpikeBin7))]; + var rb0 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin0))]; + var sb0 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin0))]; + var rb1 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin1))]; + var sb1 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin1))]; + var rb2 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin2))]; + var sb2 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin2))]; + var rb3 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin3))]; + var sb3 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin3))]; + var rb4 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin4))]; + var sb4 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin4))]; + var rb5 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin5))]; + var sb5 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin5))]; + var rb6 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin6))]; + var sb6 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin6))]; + var rb7 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(SpikeBin7))]; + var sb7 = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(SpikeBin7))]; var b0 = 0.1 * (rb0 * sb0); var b1 = 0.1 * (rb1 * sb1); var b2 = 0.1 * (rb2 * sb2); @@ -807,155 +801,161 @@ fn PathParams_DWtSynCortex(pt: ptr, ctx: ptr 0) { err *= (1 - lwt); } else { err *= lwt; } if ((*pt).Type == CTCtxtPath) { // rn.RLRate IS needed for other pathways, just not the context one - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = (*pt).Learn.LRate.Eff * err; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = (*pt).Learn.LRate.Eff * err; } else { - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))] * (*pt).Learn.LRate.Eff * err; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))] * (*pt).Learn.LRate.Eff * err; } } fn PathParams_DWtSynHebb(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var rLearnCaP = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(LearnCaP))]; - var sNrnCap = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(LearnCaP))]; - var lwt = Synapses[IndexF322D(Synapses[0], Synapses[ // linear weight - 1], u32(syni),u32(LWt))]; + var rLearnCaP = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(LearnCaP))]; + var sNrnCap = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(LearnCaP))]; + var lwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], // linear weight + u32(syni), u32(LWt))]; var hebb = rLearnCaP * ((*pt).Learn.Hebb.Up*sNrnCap*(1-lwt) - (*pt).Learn.Hebb.Down*(1-sNrnCap)*lwt); - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = (*pt).Learn.LRate.Eff * hebb; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], + u32(syni), u32(DiDWt), u32(di))] = (*pt).Learn.LRate.Eff * hebb; } fn PathParams_DWtSynHip(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32, isTarget: bool) { var syCaP: f32; var syCaD: f32; PathParams_SynCa(pt, ctx, si, ri, di, &syCaP, &syCaD); var dtr = syCaD; // delta trace, caD reflects entire window - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[ - 1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = dtr; - var tr = TraceParams_TrFromCa(&(*pt).Learn.Trace, SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], - SynapseTraces[2], u32(syni),u32(Tr),u32(di))], dtr); - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[ - 1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))] = tr; - if (Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] == 0) { + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], + TensorStrides[172], u32(syni), u32(DTr), u32(di))] = dtr; + var tr = TraceParams_TrFromCa(&(*pt).Learn.Trace, SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], + TensorStrides[172], u32(syni), u32(Tr), u32(di))], dtr); + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], + TensorStrides[172], u32(syni), u32(Tr), u32(di))] = tr; + if (Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] == 0) { return; } - var rLearnCaP = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(LearnCaP))]; - var rLearnCaD = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(LearnCaD))]; + var rLearnCaP = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(LearnCaP))]; + var rLearnCaD = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(LearnCaD))]; var err: f32; if (isTarget) { err = syCaP - syCaD; // for target layers, syn Ca drives error signal directly } else { err = tr * (rLearnCaP - rLearnCaD); // hiddens: recv NMDA Ca drives error signal w/ trace credit } - var lwt = Synapses[IndexF322D(Synapses[0], Synapses[ // linear weight - 1], u32(syni),u32(LWt))]; + var lwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], // linear weight + u32(syni), u32(LWt))]; if (err > 0) { err *= (1 - lwt); } else { err *= lwt; } - var sNrnCap = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(LearnCaP))]; + var sNrnCap = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(LearnCaP))]; var savg = 0.5 + (*pt).Hip.SAvgCor*((*pt).Hip.SNominal-0.5); savg = 0.5 / max((*pt).Hip.SAvgThr, savg); // keep this Sending Average Correction term within bounds (SAvgThr) var hebb = rLearnCaP * (sNrnCap*(savg-lwt) - (1-sNrnCap)*lwt); - var dwt = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))] * (*pt).Learn.LRate.Eff * ((*pt).Hip.Hebb*hebb + (*pt).Hip.Err*err); - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], - SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = dwt; + var dwt = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))] * (*pt).Learn.LRate.Eff * ((*pt).Hip.Hebb*hebb + (*pt).Hip.Err*err); + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], + TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = dwt; } fn PathParams_DWtSynBLA(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { var dwt = f32(0); - var ach = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]; - if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // learn and reset - 1], u32(GvHasRew),u32(di))] > 0) { - var ract = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaD))]; + var ach = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]; + if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // learn and reset + u32(GvHasRew), u32(di))] > 0) { + var ract = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaD))]; if (ract < (*pt).Learn.Trace.LearnThr) { ract = f32(0); } - var tr = SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))]; + var tr = SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))]; var ustr = (*pt).BLA.USTrace; - tr = ustr*Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(Burst))] + (1.0-ustr)*tr; - var delta = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaP))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaDPrev))]; - if (delta < 0) { // neg delta learns slower in Acq, not Ext + tr = ustr*Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(Burst))] + (1.0-ustr)*tr; + var delta = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaP))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ri), u32(di), u32(CaDPrev))]; + if (delta < 0) { delta *= (*pt).BLA.NegDeltaLRate; } dwt = tr * delta * ract; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))] = 0.0; } else if (ach > (*pt).BLA.AChThr) { - var dtr = ach * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(Burst))]; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = dtr; - var tr = TraceParams_TrFromCa(&(*pt).Learn.Trace, SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))], dtr); - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))] = tr; + var dtr = ach * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(Burst))]; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = dtr; + var tr = TraceParams_TrFromCa(&(*pt).Learn.Trace, SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))], dtr); + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))] = tr; } else { - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = 0.0; } - var lwt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))]; + var lwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))]; if (dwt > 0) { dwt *= (1 - lwt); } else { dwt *= lwt; } - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))] * (*pt).Learn.LRate.Eff * dwt; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))] * (*pt).Learn.LRate.Eff * dwt; } fn PathParams_DWtSynRWPred(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var lda = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvDA),u32(di))]; + var lda = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvDA), u32(di))]; var da = lda; var lr = (*pt).Learn.LRate.Eff; var eff_lr = lr; - if (NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ri),u32(NrnNeurIndex))] == 0) { - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Ge))] > Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Act))] && da > 0) { // clipped at top, saturate up + if (NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ri), u32(NrnNeurIndex))] == 0) { + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(Ge))] > Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // clipped at top, saturate up + u32(ri), u32(di), u32(Act))] && da > 0) { da = f32(0); } - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Ge))] < Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Act))] && da < 0) { // clipped at bottom, saturate down + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(Ge))] < Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // clipped at bottom, saturate down + u32(ri), u32(di), u32(Act))] && da < 0) { da = f32(0); } if (da < 0) { eff_lr *= (*pt).RLPred.OppSignLRate; } } else { - eff_lr = -eff_lr; // negative case - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Ge))] > Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Act))] && da < 0) { // clipped at top, saturate up + eff_lr = -eff_lr; // negative case + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(Ge))] > Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // clipped at top, saturate up + u32(ri), u32(di), u32(Act))] && da < 0) { da = f32(0); } - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Ge))] < Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(Act))] && da > 0) { // clipped at bottom, saturate down + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(Ge))] < Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // clipped at bottom, saturate down + u32(ri), u32(di), u32(Act))] && da > 0) { da = f32(0); } if (da >= 0) { eff_lr *= (*pt).RLPred.OppSignLRate; } } - var dwt = da * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // no recv unit activation - 2], u32(si),u32(di),u32(CaP))]; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[ - 2], u32(syni),u32(DiDWt),u32(di))] = eff_lr * dwt; + var dwt = da * Neurons[Index3D(TensorStrides[60], TensorStrides[61], // no recv unit activation + TensorStrides[62], u32(si), u32(di), u32(CaP))]; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], + u32(syni), u32(DiDWt), u32(di))] = eff_lr * dwt; } fn PathParams_DWtSynTDPred(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var lda = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvDA),u32(di))]; + var lda = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvDA), u32(di))]; var da = lda; var lr = (*pt).Learn.LRate.Eff; var eff_lr = lr; - var ni = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ri),u32(NrnNeurIndex))]; + var ni = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ri), u32(NrnNeurIndex))]; if (ni == 0) { if (da < 0) { eff_lr *= (*pt).RLPred.OppSignLRate; @@ -966,78 +966,79 @@ fn PathParams_DWtSynTDPred(pt: ptr, ctx: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var hasRew = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))] > 0; - var ach = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]; + var hasRew = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0; + var ach = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]; if (!hasRew && ach < 0.1) { - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = 0.0;return; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = 0.0;return; } - var rlr = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))]; - var rplus = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaP))]; - var rminus = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaD))]; - var sact = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(CaD))]; + var rlr = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))]; + var rplus = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaP))]; + var rminus = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaD))]; + var sact = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(CaD))]; var dtr = ach * ((*pt).Matrix.Delta * sact * (rplus - rminus)); if (rminus > (*pt).Learn.Trace.LearnThr) { // key: prevents learning if < threshold dtr += ach * ((*pt).Matrix.Credit * sact * rminus); } if (hasRew) { - var tr = SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))]; + var tr = SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))]; if ((*pt).Matrix.VSRewLearn == 1) { - tr += (1 - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvGoalMaint),u32(di))]) * dtr; + tr += (1 - GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvGoalMaint), u32(di))]) * dtr; } var dwt = rlr * (*pt).Learn.LRate.Eff * tr; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = dwt; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))] = 0.0; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = dwt; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = 0.0; } else { dtr *= rlr; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = dtr; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[ - 2], u32(syni),u32(Tr),u32(di))] += dtr; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = dtr; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], + u32(syni), u32(Tr), u32(di))] += dtr; } } fn PathParams_DWtSynDSMatrix(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var rlr = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))]; - if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // US time -- use DA and current recv activity - 1], u32(GvHasRew),u32(di))] > 0) { - var tr = SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))]; + var rlr = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))]; + if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // US time -- use DA and current recv activity + u32(GvHasRew), u32(di))] > 0) { + var tr = SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))]; var dwt = rlr * (*pt).Learn.LRate.Eff * tr; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = dwt; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(Tr),u32(di))] = 0.0; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DiDWt), u32(di))] = dwt; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(Tr), u32(di))] = 0.0; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = 0.0; } else { - var pfmod = (*pt).Matrix.BasePF + Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(GModSyn))]; - var rplus = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaP))]; - var rminus = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(CaD))]; - var sact = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(si),u32(di),u32(CaD))]; + var pfmod = (*pt).Matrix.BasePF + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(GModSyn))]; + var rplus = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaP))]; + var rminus = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(CaD))]; + var sact = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(si), u32(di), u32(CaD))]; var dtr = rlr * ((*pt).Matrix.Delta * sact * (rplus - rminus)); if (rminus > (*pt).Learn.Trace.LearnThr) { // key: prevents learning if < threshold dtr += rlr * ((*pt).Matrix.Credit * pfmod * sact * rminus); } - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[2], u32(syni),u32(DTr),u32(di))] = dtr; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], SynapseTraces[ - 2], u32(syni),u32(Tr),u32(di))] += dtr; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], u32(syni), u32(DTr), u32(di))] = dtr; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], TensorStrides[172], + u32(syni), u32(Tr), u32(di))] += dtr; } } fn PathParams_DWtSynVSPatch(pt: ptr, ctx: ptr, syni: u32,si: u32,ri: u32,lpi: u32,pi: u32,di: u32) { - var ract = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // t-1 - 2], u32(ri),u32(di),u32(CaDPrev))]; + var ract = Neurons[Index3D(TensorStrides[60], TensorStrides[61], // t-1 + TensorStrides[62], u32(ri), u32(di), u32(CaDPrev))]; if (ract < (*pt).Learn.Trace.LearnThr) { ract = f32(0); } - var sact = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // t-1 - 2], u32(si),u32(di),u32(CaDPrev))]; - var dwt = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ri),u32(di),u32(RLRate))] * (*pt).Learn.LRate.Eff * sact * ract; - SynapseTraces[IndexF323D(SynapseTraces[0], SynapseTraces[1], - SynapseTraces[2], u32(syni),u32(DiDWt),u32(di))] = dwt; + var sact = Neurons[Index3D(TensorStrides[60], TensorStrides[61], // t-1 + TensorStrides[62], u32(si), u32(di), u32(CaDPrev))]; + var dwt = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ri), u32(di), u32(RLRate))] * (*pt).Learn.LRate.Eff * sact * ract; + SynapseTraces[Index3D(TensorStrides[170], TensorStrides[171], + TensorStrides[172], + u32(syni), u32(DiDWt), u32(di))] = dwt; } -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -1134,7 +1135,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -1144,9 +1145,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -1160,7 +1161,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -1168,7 +1169,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1184,7 +1185,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1209,7 +1210,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1318,7 +1319,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1365,7 +1366,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1380,7 +1381,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1406,7 +1407,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1414,7 +1415,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1447,14 +1448,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1477,7 +1478,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1485,7 +1486,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1503,7 +1504,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1511,11 +1512,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1531,7 +1532,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1621,7 +1622,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/GPUTestWrite.wgsl b/axon/shaders/GPUTestWrite.wgsl index dccf8138..6340b05e 100644 --- a/axon/shaders/GPUTestWrite.wgsl +++ b/axon/shaders/GPUTestWrite.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,43 +59,35 @@ fn main(@builtin(global_invocation_id) idx: vec3) { GPUTestWrite(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" fn GPUTestWrite(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); for (var vi = Spike; vi < NeuronVarsN; vi++) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(vi))] = f32(ni*1000 + u32(vi)); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(vi))] = f32(ni*1000 + u32(vi)); } Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -113,7 +107,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -238,7 +232,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -250,7 +244,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -258,7 +252,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -274,7 +268,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -286,7 +280,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -306,7 +300,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -318,7 +312,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -330,7 +324,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -342,7 +336,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -358,7 +352,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -366,7 +360,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -393,7 +387,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -413,9 +407,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -439,10 +433,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -462,7 +456,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -481,7 +475,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -553,7 +547,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -565,7 +559,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -582,9 +576,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -628,7 +622,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -672,7 +666,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -705,7 +699,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -719,13 +713,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -819,7 +813,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -829,9 +823,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -845,7 +839,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -853,7 +847,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -869,7 +863,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -894,7 +888,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1003,7 +997,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1050,7 +1044,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1065,7 +1059,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1091,7 +1085,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1099,7 +1093,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1132,14 +1126,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1162,7 +1156,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1170,7 +1164,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1188,7 +1182,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1196,11 +1190,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1216,7 +1210,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1306,7 +1300,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/GatherSpikes.wgsl b/axon/shaders/GatherSpikes.wgsl index 0e566f78..d912cf29 100644 --- a/axon/shaders/GatherSpikes.wgsl +++ b/axon/shaders/GatherSpikes.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,75 +59,68 @@ fn main(@builtin(global_invocation_id) idx: vec3) { GatherSpikes(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_GatherSpikes(ly: ptr, ctx: ptr, ni: u32,di: u32) { var lni = ni - (*ly).Indexes.NeurSt; LayerParams_GatherSpikesInit(ly, ctx, ni, di); for (var pti = u32(0); pti < (*ly).Indexes.RecvN; pti++) { - var npti = RecvPathIxs[IndexU321D(RecvPathIxs[0], u32((*ly).Indexes.RecvSt + pti))]; + var npti = RecvPathIxs[Index1D(TensorStrides[30], u32((*ly).Indexes.RecvSt + pti))]; var pt = Paths[npti]; PathParams_GatherSpikes(&pt, ctx, ly, ni, di, lni); } LayerParams_GiFromSpikes(ly, ctx, ni, di); } fn LayerParams_GatherSpikesInit(ly: ptr, ctx: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] = NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GiBase))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] = NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GiBase))]; } fn LayerParams_GiFromSpikes(ly: ptr, ctx: ptr, ni: u32,di: u32) { - var pi = LayerParams_PoolIndex(ly, NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnSubPool))]); - var spk = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))]; - var geRaw = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))]; - var geExt = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))]; + var pi = LayerParams_PoolIndex(ly, NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnSubPool))]); + var spk = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))]; + var geRaw = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))]; + var geExt = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))]; PoolInhibRawIncrInt(pi, di, spk, geRaw, geExt); PoolAvgMaxUpdate(pi, di, ni); - if (PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolIsLayer))] == 0) { // also update layer pool if I am a subpool + if (PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], // also update layer pool if I am a subpool + u32(pi), u32(di), u32(PoolIsLayer))] == 0) { var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); PoolInhibRawIncrInt(lpi, di, spk, geRaw, geExt); PoolAvgMaxUpdate(lpi, di, ni); } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn GatherSpikes(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_GatherSpikes(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -162,43 +157,44 @@ struct PathScaleParams { fn PathParams_GatherSpikes(pt: ptr, ctx: ptr, ly: ptr, ni: u32,di: u32,lni: u32) { var deli = SynComParams_ReadOff(&(*pt).Com, (*ctx).CyclesTotal); var npti = (*pt).Indexes.NPathNeurSt + lni; - var gRaw = SynComParams_FloatFromGBuf(&(*pt).Com, PathGBuf[IndexI323D(PathGBuf[0], PathGBuf[1], PathGBuf[2], u32(npti),u32(di),u32(deli))]); - PathGBuf[IndexI323D(PathGBuf[0], PathGBuf[1], PathGBuf[2], u32(npti),u32(di),u32(deli))] = 0; - var gsyn = PathGSyns[IndexF322D(PathGSyns[0], PathGSyns[1], u32(npti),u32(di))]; + var gRaw = SynComParams_FloatFromGBuf(&(*pt).Com, PathGBuf[Index3D(TensorStrides[140], TensorStrides[141], TensorStrides[142], u32(npti), u32(di), u32(deli))]); + PathGBuf[Index3D(TensorStrides[140], TensorStrides[141], TensorStrides[142], u32(npti), u32(di), u32(deli))] = 0; + var gsyn = PathGSyns[Index2D(TensorStrides[150], TensorStrides[151], u32(npti), u32(di))]; PathParams_GatherSpikesGSyn(pt, ctx, ly, ni, di, gRaw, &gsyn); - PathGSyns[IndexF322D(PathGSyns[0], PathGSyns[ - 1], u32(npti),u32(di))] = gsyn; + PathGSyns[Index2D(TensorStrides[150], TensorStrides[151], + u32(npti), u32(di))] = gsyn; } fn PathParams_GatherSpikesGSyn(pt: ptr, ctx: ptr, ly: ptr, ni: u32,di: u32, gRaw: f32, gSyn: ptr) { switch ((*pt).Com.GType) { case ExcitatoryG: { *gSyn = DtParams_GeSynFromRaw(&(*ly).Acts.Dt, *gSyn, gRaw); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] += gRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] += *gSyn; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] += gRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] += *gSyn; } case InhibitoryG: { *gSyn = DtParams_GiSynFromRaw(&(*ly).Acts.Dt, *gSyn, gRaw); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiRaw))] += gRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] += *gSyn; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiRaw))] += gRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] += *gSyn; } case ModulatoryG: { *gSyn = DtParams_GeSynFromRaw(&(*ly).Acts.Dt, *gSyn, gRaw); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))] += gRaw; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))] += *gSyn; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))] += gRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))] += *gSyn; } case MaintG: { *gSyn = DtParams_GeSynFromRaw(&(*ly).Acts.Dt, *gSyn, gRaw); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] += gRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(GMaintRaw))] += gRaw; } case ContextG: { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeRaw))] += gRaw; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeRaw))] += gRaw; } default: { } } } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -329,7 +325,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -341,7 +337,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -349,7 +345,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -365,7 +361,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -377,7 +373,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -397,7 +393,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -409,7 +405,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -421,7 +417,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -433,7 +429,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -449,7 +445,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -457,7 +453,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -484,7 +480,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -504,9 +500,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -530,10 +526,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -553,7 +549,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -572,7 +568,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -644,7 +640,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -656,7 +652,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -675,14 +671,14 @@ struct InhibParams { fn PoolInhibRawIncrInt(pi: u32,di: u32, spike: f32,geRaw: f32,geExt: f32) { var floatToInt = f32(u32(1) << 24); var fnn = f32(PoolNNeurons(pi)); - atomicAdd(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FBsRawInt))], i32(spike)); - atomicAdd(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FFsRawInt))], i32((geRaw/fnn)*floatToInt)); - atomicAdd(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(GeExtRawInt))], i32((geExt/fnn)*floatToInt)); + atomicAdd(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FBsRawInt))], i32(spike)); + atomicAdd(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FFsRawInt))], i32((geRaw/fnn)*floatToInt)); + atomicAdd(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(GeExtRawInt))], i32((geExt/fnn)*floatToInt)); } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -726,7 +722,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -773,7 +769,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -806,7 +802,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -820,13 +816,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -920,7 +916,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -930,9 +926,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -946,7 +942,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -954,7 +950,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -970,7 +966,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -995,7 +991,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1104,7 +1100,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1151,7 +1147,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1166,7 +1162,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1192,7 +1188,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1200,7 +1196,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1233,34 +1229,36 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); fn AvgMaxIntVarIndex(vr: AvgMaxVars, am: AvgMax) -> u32 { return u32(PoolIntAvgMaxStart) + u32(vr)*u32(AvgMaxN) + u32(am); } -fn PoolNNeurons(pi: u32) -> i32 { return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ -2], u32(pi),u32(0),u32(PoolNeurSt))]; } +fn PoolNNeurons(pi: u32) -> i32 { return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], +TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } fn PoolAvgMaxUpdateVar(vr: AvgMaxVars, pi: u32,di: u32, val: f32) { var n = f32(PoolNNeurons(pi)); var floatToInt = f32(u32(1) << 20); var floatToSum = floatToInt / n; var vis = AvgMaxIntVarIndex(vr, Avg); var vim = AvgMaxIntVarIndex(vr, Max); - atomicAdd(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))], i32(val*floatToSum)); - atomicMax(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))], i32(val*floatToInt)); + atomicAdd(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))], i32(val*floatToSum)); + atomicMax(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], + u32(pi), u32(di), u32(vim))], i32(val*floatToInt)); } fn PoolAvgMaxUpdate(pi: u32,di: u32,ni: u32) { - PoolAvgMaxUpdateVar(AMCaP, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMCaP]))])); - PoolAvgMaxUpdateVar(AMCaD, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMCaD]))])); - PoolAvgMaxUpdateVar(AMCaPMax, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMCaPMax]))])); - PoolAvgMaxUpdateVar(AMAct, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMAct]))])); - PoolAvgMaxUpdateVar(AMGeInt, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMGeInt]))])); - PoolAvgMaxUpdateVar(AMGiInt, pi, di, abs(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(avgMaxToNeuron[AMGiInt]))])); + PoolAvgMaxUpdateVar(AMCaP, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(avgMaxToNeuron[AMCaP]))])); + PoolAvgMaxUpdateVar(AMCaD, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(avgMaxToNeuron[AMCaD]))])); + PoolAvgMaxUpdateVar(AMCaPMax, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(avgMaxToNeuron[AMCaPMax]))])); + PoolAvgMaxUpdateVar(AMAct, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(avgMaxToNeuron[AMAct]))])); + PoolAvgMaxUpdateVar(AMGeInt, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(avgMaxToNeuron[AMGeInt]))])); + PoolAvgMaxUpdateVar(AMGiInt, pi, di, abs(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(avgMaxToNeuron[AMGiInt]))])); } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1283,7 +1281,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1291,7 +1289,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1309,7 +1307,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1317,11 +1315,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1337,7 +1335,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1427,7 +1425,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/InitGBuffsPath.wgsl b/axon/shaders/InitGBuffsPath.wgsl index 062d5ae8..d51ee3d4 100644 --- a/axon/shaders/InitGBuffsPath.wgsl +++ b/axon/shaders/InitGBuffsPath.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,39 +59,31 @@ fn main(@builtin(global_invocation_id) idx: vec3) { InitGBuffsPath(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" fn InitGBuffsPath(pti: u32) { //gosl:kernel var ctx = Ctx[0]; var paths=Paths[pti]; PathParams_InitGBuffs(&paths, &ctx); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -117,14 +111,14 @@ fn PathParams_InitGBuffs(pt: ptr, ctx: ptr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1311,7 +1305,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/LayerGi.wgsl b/axon/shaders/LayerGi.wgsl index 0aff4868..6efed5a7 100644 --- a/axon/shaders/LayerGi.wgsl +++ b/axon/shaders/LayerGi.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { LayerGi(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_LayerGi(ly: ptr, ctx: ptr, li: u32,di: u32) { var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); PoolAvgMaxCalc(lpi, di); @@ -89,11 +83,11 @@ fn LayerParams_LayerGi(ly: ptr, ctx: ptr } fn LayerParams_LayPoolGiFromSpikes(ly: ptr, ctx: ptr, lpi: u32,di: u32) { PoolInhibSpikesFromRaw(lpi, di); - PoolInhib(&(*ly).Inhib.Layer, lpi, di, LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[ - 2], u32((*ly).Index),u32(di),u32(LayerGiMult))]); + PoolInhib(&(*ly).Inhib.Layer, lpi, di, LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], + u32((*ly).Index), u32(di), u32(LayerGiMult))]); } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn LayerGi(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); @@ -102,7 +96,7 @@ fn LayerGi(i: u32) { //gosl:kernel Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -122,7 +116,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -247,7 +241,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -259,7 +253,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -267,7 +261,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -283,7 +277,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -295,7 +289,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -315,7 +309,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -327,7 +321,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -339,7 +333,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -351,7 +345,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -367,7 +361,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -375,7 +369,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -402,7 +396,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -422,9 +416,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -448,10 +442,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -486,7 +480,7 @@ fn GiParams_SSFromFBs(fb: ptr, ssf: ptr,ssi: pt *ssf += fbs*(1-*ssf) - (*fb).SSfDt**ssf; } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -505,7 +499,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -577,7 +571,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -589,7 +583,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -609,73 +603,74 @@ fn PoolInhib(fb: ptr, pi: u32,di: u32, gimult: f32) { if ((*fb).On == 0) { PoolInhibZero(pi, di);return; } - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] += (*fb).FFAvgDt * (Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]); - var fsi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))]; - fsi = GiParams_FSiFromFFs(fb, fsi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))], Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] = fsi; - var clamped = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(Clamped))] > 0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] = (*fb).Gi * GiParams_FS(fb, fsi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))], clamped); - var ssf = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))]; - var ssi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))]; - GiParams_SSFromFBs(fb, &ssf, &ssi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] = (*fb).Gi * (*fb).SS * ssi; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] = ssf; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] = ssi; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = PoolInhibGiFromFSSS(pi, di) + (*fb).FFPrv*Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] += (*fb).FFAvgDt * (Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] - Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]); + var fsi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))]; + fsi = GiParams_FSiFromFFs(fb, fsi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))], Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] = fsi; + var clamped = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(Clamped))] > 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] = (*fb).Gi * GiParams_FS(fb, fsi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))], clamped); + var ssf = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))]; + var ssi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))]; + GiParams_SSFromFBs(fb, &ssf, &ssi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] = (*fb).Gi * (*fb).SS * ssi; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] = ssf; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] = ssi; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = PoolInhibGiFromFSSS(pi, di) + (*fb).FFPrv*Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))]; PoolInhibSaveOrig(pi, di); } fn PoolInhibInitRaw(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))] = 0.0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FFsRawInt))] = 0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FBsRawInt))] = 0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], - u32(pi),u32(di),u32(GeExtRawInt))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))] = 0.0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FFsRawInt))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FBsRawInt))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], + u32(pi), u32(di), u32(GeExtRawInt))] = 0; } fn PoolInhibZero(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GiOrig))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(LayGi))] = 0.0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(di),u32(Clamped))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GiOrig))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(LayGi))] = 0.0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(di), u32(Clamped))] = 0; } fn PoolInhibSpikesFromRaw(pi: u32,di: u32) { var fnn = f32(PoolNNeurons(pi)); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] / fnn; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] / fnn; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))]; PoolInhibInitRaw(pi, di); } fn PoolInhibSaveOrig(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GiOrig))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GiOrig))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))]; } fn PoolInhibGiFromFSSS(pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] + Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] + Pools[Index3D(TensorStrides[120], TensorStrides[121], + TensorStrides[122], u32(pi), u32(di), u32(SSGi))]; } fn PoolInhibIntToRaw(pi: u32,di: u32) { var floatFromInt = 1.0 / f32(u32(1)<<24); - var fbs = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FBsRawInt))]; - var ffs = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FFsRawInt))]; - var geExt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(GeExtRawInt))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] = f32(fbs); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))] = f32(ffs) * floatFromInt; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))] = f32(geExt) * floatFromInt; + var fbs = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FBsRawInt))]; + var ffs = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FFsRawInt))]; + var geExt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(GeExtRawInt))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] = f32(fbs); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))] = f32(ffs) * floatFromInt; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))] = f32(geExt) * floatFromInt; } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -719,7 +714,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -766,7 +761,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -799,7 +794,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -813,13 +808,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -913,7 +908,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -923,9 +918,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -939,7 +934,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -947,7 +942,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -963,7 +958,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -988,7 +983,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1097,7 +1092,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1144,7 +1139,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1159,7 +1154,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1185,7 +1180,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1193,7 +1188,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1232,25 +1227,25 @@ fn AvgMaxIntVarIndex(vr: AvgMaxVars, am: AvgMax) -> u32 { return u32(PoolIntAvgMaxStart) + u32(vr)*u32(AvgMaxN) + u32(am); } fn PoolNNeurons(pi: u32) -> i32 { - return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(0),u32(PoolNeurSt))]; + return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } fn PoolAvgMaxCalcVar(vr: AvgMaxVars, pi: u32,di: u32) { var floatFromInt = f32(1.0) / f32(u32(1)<<20); var vis = AvgMaxIntVarIndex(vr, Avg); - var sum = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))]; + var sum = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))]; if (sum < 0) { sum = i32(u32(1) << 20); } - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))] = 0; var vim = AvgMaxIntVarIndex(vr, Max); - var mx = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))]; + var mx = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))]; if (mx < 0) { mx = i32(u32(1) << 20); } - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))] = 0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; } fn PoolAvgMaxCalc(pi: u32,di: u32) { for (var vr=0; vr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1432,7 +1427,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/MinusPhaseNeuron.wgsl b/axon/shaders/MinusPhaseNeuron.wgsl index b711676b..d8a74124 100644 --- a/axon/shaders/MinusPhaseNeuron.wgsl +++ b/axon/shaders/MinusPhaseNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,45 +59,37 @@ fn main(@builtin(global_invocation_id) idx: vec3) { MinusPhaseNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_MinusPhaseNeuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActM))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActM))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))]; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn MinusPhaseNeuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_MinusPhaseNeuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -115,7 +109,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -240,7 +234,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -252,7 +246,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -260,7 +254,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -276,7 +270,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -288,7 +282,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -308,7 +302,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -320,7 +314,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -332,7 +326,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -344,7 +338,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -360,7 +354,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -368,7 +362,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -395,7 +389,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -415,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -441,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -464,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -483,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -555,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -567,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -584,9 +578,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -630,7 +624,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -674,7 +668,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -707,7 +701,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -721,13 +715,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -821,7 +815,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -831,9 +825,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -847,7 +841,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -855,7 +849,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -871,7 +865,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -896,7 +890,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1005,7 +999,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1052,7 +1046,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1067,7 +1061,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1093,7 +1087,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1101,7 +1095,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1134,14 +1128,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1164,7 +1158,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1172,7 +1166,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1190,7 +1184,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1198,11 +1192,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1218,7 +1212,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1308,7 +1302,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/MinusPhasePool.wgsl b/axon/shaders/MinusPhasePool.wgsl index d2af1795..f3cc2a3f 100644 --- a/axon/shaders/MinusPhasePool.wgsl +++ b/axon/shaders/MinusPhasePool.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,38 +59,30 @@ fn main(@builtin(global_invocation_id) idx: vec3) { MinusPhasePool(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_MinusPhasePool(ly: ptr, ctx: ptr, pi: u32) { for (var di = u32(0); di < (*ctx).NData; di++) { PoolCycleToMinus(pi, di); if ((*ly).Acts.Clamp.Add == 0 && (*ly).Acts.Clamp.IsTarget == 1) { - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(Clamped))] = 1; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(Clamped))] = 1; } } - if (PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolIsLayer))] == 0) { + if (PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolIsLayer))] == 0) { return; } var geIntMinusMax = f32(0); @@ -102,23 +96,24 @@ fn LayerParams_MinusPhasePool(ly: ptr, ctx: ptr, ctx: ptr, di: u32, geIntMinusMax: f32,giIntMinusMax: f32) { - var gem = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerAvgMaxGeM))]; - var gim = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerAvgMaxGiM))]; + var gem = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerAvgMaxGeM))]; + var gim = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerAvgMaxGiM))]; gem += (*ly).Acts.Dt.LongAvgDt * (geIntMinusMax - gem); gim += (*ly).Acts.Dt.LongAvgDt * (giIntMinusMax - gim); - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerAvgMaxGeM))] = gem; - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerAvgMaxGiM))] = gim; + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerAvgMaxGeM))] = gem; + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], + u32((*ly).Index), u32(di), u32(LayerAvgMaxGiM))] = gim; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn MinusPhasePool(pi: u32) { //gosl:kernel var ctx = Ctx[0]; - var li = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolLayerIdx))]; + var li = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolLayerIdx))]; var layers=Layers[li]; LayerParams_MinusPhasePool(&layers, &ctx, pi); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -138,7 +133,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -263,7 +258,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -275,7 +270,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -283,7 +278,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -299,7 +294,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -311,7 +306,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -331,7 +326,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -343,7 +338,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -355,7 +350,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -367,7 +362,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -383,7 +378,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -391,7 +386,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -412,7 +407,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -432,9 +427,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -458,10 +453,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -481,7 +476,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -500,7 +495,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -572,7 +567,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -584,7 +579,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -601,9 +596,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -647,7 +642,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -691,7 +686,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -724,7 +719,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -738,13 +733,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -838,7 +833,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -848,9 +843,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -864,7 +859,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -872,7 +867,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -888,7 +883,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -913,7 +908,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1022,7 +1017,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1069,7 +1064,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1084,7 +1079,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1110,7 +1105,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1118,7 +1113,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1154,25 +1149,26 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } fn PoolCycleToMinus(pi: u32,di: u32) { for (var vr=0; vr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1339,7 +1335,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/MinusPhasePost.wgsl b/axon/shaders/MinusPhasePost.wgsl index 7d24a47c..927ee1c9 100644 --- a/axon/shaders/MinusPhasePost.wgsl +++ b/axon/shaders/MinusPhasePost.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { MinusPhasePost(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; -} +//////// import: "vars.go" -///////////// import: "vars.go" - -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_DecayStateNeuronsAll(ly: ptr, ctx: ptr, decay: f32,glong: f32,ahp: f32) { var nn = (*ly).Indexes.NNeurons; for (var lni = u32(0); lni < nn; lni++) { @@ -106,14 +100,14 @@ fn LayerParams_MinusPhasePost(ly: ptr, ctx: ptr bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronIsOff(ni: u32) -> bool { return NeuronHasFlag(NeuronOff, ni, u32(u32(0))); @@ -264,84 +259,85 @@ struct ActParams { PopCode: PopCodeParams, } fn ActParams_DecayLearnCa(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))] += decay * (1.0 - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))] += decay * (1.0 - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))]; } fn ActParams_DecayAHP(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))]; var kirMrest = (*ac).Kir.Mrest; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))] += decay * (kirMrest - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))] += decay * (kirMrest - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))]; } fn ActParams_DecayState(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32,glong: f32,ahp: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))] = -1.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] = (*ac).Init.Act; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spiked))] = 0.0; - if (decay > 0) { // no-op for most, but not all.. - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GiBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] - (*ac).Init.Vm); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))] = -1.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] = (*ac).Init.Act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Spiked))] = 0.0; + if (decay > 0) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GiBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] -= glong * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] -= glong * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] - (*ac).Init.Vm); if (ahp > 0) { ActParams_DecayAHP(ac, ctx, ni, di, ahp); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))]; if ((*ac).Decay.LearnCa > 0) { // learning-based Ca values -- not usual ActParams_DecayLearnCa(ac, ctx, ni, di, (*ac).Decay.LearnCa); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Inet))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))]; -} - -///////////// import: "chans-ak.go" + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Inet))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))]; +} + +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -353,7 +349,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -361,7 +357,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -377,7 +373,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -389,7 +385,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -409,7 +405,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -421,7 +417,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -433,7 +429,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -445,7 +441,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -461,7 +457,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -469,7 +465,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -490,7 +486,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -510,9 +506,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -536,10 +532,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -559,7 +555,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -578,7 +574,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -650,7 +646,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -662,7 +658,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -679,9 +675,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -725,7 +721,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -772,7 +768,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -805,7 +801,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -819,13 +815,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -919,7 +915,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -929,9 +925,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -945,7 +941,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -953,7 +949,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -969,7 +965,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -994,7 +990,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1103,7 +1099,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1150,7 +1146,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1165,7 +1161,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1196,74 +1192,74 @@ fn LayerParams_MatrixGated(ly: ptr, ctx: ptr 0; + var mtxGated = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(lpi), u32(di), u32(PoolGated))] > 0; var thalGated = false; if ((*ly).Matrix.ThalLay1Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay1Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay2Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay2Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay3Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay3Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay4Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay4Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay5Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay5Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay6Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay6Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } mtxGated = mtxGated && thalGated; if (!mtxGated) { // nobody did if thal didn't for (var spi = u32(0); spi < (*ly).Indexes.NPools; spi++) { var pi = LayerParams_PoolIndex(ly, spi); - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] = 0; } } if ((*ctx).PlusPhase == 1 && (*ly).Matrix.IsVS == 1) { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixJustGated),u32(di))] = f32(mtxGated); + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixJustGated), u32(di))] = f32(mtxGated); if (mtxGated) { var poolIndex = i32(-1); for (var spi = u32(1); spi < (*ly).Indexes.NPools; spi++) { var pi = LayerParams_PoolIndex(ly, spi); - if (poolIndex < 0 && PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] > 0) { + if (poolIndex < 0 && PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] > 0) { poolIndex = i32(pi); } } if (poolIndex > 0) { - GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvVSMatrixPoolGated),u32(poolIndex),u32(di))] = f32(1.0); + GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvVSMatrixPoolGated), u32(poolIndex), u32(di))] = f32(1.0); } } } } } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1271,7 +1267,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1304,14 +1300,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1334,7 +1330,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1342,7 +1338,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1360,7 +1356,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1368,11 +1364,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1388,7 +1384,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1478,7 +1474,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/NewStateLayer.wgsl b/axon/shaders/NewStateLayer.wgsl index e8ad777a..b65187f4 100644 --- a/axon/shaders/NewStateLayer.wgsl +++ b/axon/shaders/NewStateLayer.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { NewStateLayer(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_IsTarget(ly: ptr) -> bool { switch ((*ly).Type) { case TargetLayer: { @@ -114,7 +108,7 @@ fn LayerParams_NewStateLayer(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr, di: u32, actMinusAvg: f32,actPlusAvg: f32) { - var mavg = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerActMAvg))]; - var pavg = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerActPAvg))]; + var mavg = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerActMAvg))]; + var pavg = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerActPAvg))]; ActAvgParams_AvgFromAct(&(*ly).Inhib.ActAvg, &mavg, actMinusAvg, (*ly).Acts.Dt.LongAvgDt); ActAvgParams_AvgFromAct(&(*ly).Inhib.ActAvg, &pavg, actPlusAvg, (*ly).Acts.Dt.LongAvgDt); - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerActMAvg))] = mavg; - LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32((*ly).Index),u32(di),u32(LayerActPAvg))] = pavg; + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerActMAvg))] = mavg; + LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32((*ly).Index), u32(di), u32(LayerActPAvg))] = pavg; } fn LayerParams_NewStatePool(ly: ptr, ctx: ptr, pi: u32,di: u32) { - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(Clamped))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(Clamped))] = 0; if ((*ly).Acts.Clamp.Add == 0 && (*ly).Acts.Clamp.IsInput == 1) { - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(Clamped))] = 1; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(Clamped))] = 1; } PoolInhibDecay(pi, di, (*ly).Acts.Decay.Act); - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], - u32(pi),u32(di),u32(PoolGated))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] = 0; } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn NewStateLayer(li: u32) { //gosl:kernel var ctx = Ctx[0]; var layers=Layers[li]; LayerParams_NewStateLayer(&layers, &ctx); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -172,7 +166,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -297,7 +291,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -309,7 +303,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -317,7 +311,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -333,7 +327,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -345,7 +339,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -365,7 +359,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -377,7 +371,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -389,7 +383,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -401,7 +395,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -417,7 +411,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -425,7 +419,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -446,7 +440,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -466,9 +460,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -492,10 +486,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -515,7 +509,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -534,7 +528,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -606,7 +600,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -618,7 +612,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -641,22 +635,22 @@ struct InhibParams { Pool: GiParams, } fn PoolInhibDecay(pi: u32,di: u32, decay: f32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]; // capture prior to decay - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]; -} - -///////////// import: "init-layer.go" - -///////////// import: "kinase-params.go" + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]; // capture prior to decay + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]; +} + +//////// import: "init-layer.go" + +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -700,7 +694,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -747,7 +741,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -780,7 +774,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -794,13 +788,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -894,7 +888,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -904,9 +898,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -920,7 +914,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -928,7 +922,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -944,7 +938,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -969,7 +963,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1078,7 +1072,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1125,7 +1119,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1140,7 +1134,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1166,7 +1160,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1174,7 +1168,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1210,17 +1204,18 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1243,7 +1238,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1251,7 +1246,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1269,7 +1264,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1277,11 +1272,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1297,7 +1292,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1387,7 +1382,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/NewStateNeuron.wgsl b/axon/shaders/NewStateNeuron.wgsl index bec0f809..0809d09f 100644 --- a/axon/shaders/NewStateNeuron.wgsl +++ b/axon/shaders/NewStateNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,53 +59,45 @@ fn main(@builtin(global_invocation_id) idx: vec3) { NewStateNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_NewStateNeuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(BurstPrv))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Burst))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaDPrev))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMax))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaPMaxCa))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(BurstPrv))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Burst))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaDPrev))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMax))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaPMaxCa))] = 0.0; ActParams_DecayState(&(*ly).Acts, ctx, ni, di, (*ly).Acts.Decay.Act, (*ly).Acts.Decay.Glong, (*ly).Acts.Decay.AHP); ActParams_KNaNewState(&(*ly).Acts, ctx, ni, di); for (var i=0; i<8; i++) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SpikeBin0 + NeuronVars(i)))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SpikeBin0 + NeuronVars(i)))] = 0.0; } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn NewStateNeuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_NewStateNeuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -123,7 +117,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -248,89 +242,90 @@ struct ActParams { PopCode: PopCodeParams, } fn ActParams_DecayLearnCa(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))] += decay * (1.0 - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))] += decay * (1.0 - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))]; } fn ActParams_DecayAHP(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))]; var kirMrest = (*ac).Kir.Mrest; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))] += decay * (kirMrest - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))] += decay * (kirMrest - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))]; } fn ActParams_DecayState(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32,glong: f32,ahp: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))] = -1.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] = (*ac).Init.Act; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spiked))] = 0.0; - if (decay > 0) { // no-op for most, but not all.. - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GiBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] - (*ac).Init.Vm); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))] = -1.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] = (*ac).Init.Act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Spiked))] = 0.0; + if (decay > 0) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GiBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] -= glong * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] -= glong * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] - (*ac).Init.Vm); if (ahp > 0) { ActParams_DecayAHP(ac, ctx, ni, di, ahp); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))]; if ((*ac).Decay.LearnCa > 0) { // learning-based Ca values -- not usual ActParams_DecayLearnCa(ac, ctx, ni, di, (*ac).Decay.LearnCa); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Inet))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Inet))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))]; } fn ActParams_KNaNewState(ac: ptr, ctx: ptr, ni: u32,di: u32) { if ((*ac).KNa.On == 1 && (*ac).KNa.TrialSlow == 1) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))] += (*ac).KNa.Slow.Max * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaDPrev))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))] += (*ac).KNa.Slow.Max * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaDPrev))]; } } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -342,7 +337,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -350,7 +345,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -366,7 +361,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -378,7 +373,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -398,7 +393,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -410,7 +405,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -422,7 +417,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -434,7 +429,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -450,7 +445,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -458,7 +453,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -485,7 +480,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -505,9 +500,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -531,10 +526,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -554,7 +549,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -573,7 +568,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -645,7 +640,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -657,7 +652,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -674,9 +669,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -720,7 +715,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -764,7 +759,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -797,7 +792,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -811,13 +806,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -911,7 +906,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -921,9 +916,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -937,7 +932,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -945,7 +940,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -961,7 +956,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -986,7 +981,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1095,7 +1090,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1142,7 +1137,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1157,7 +1152,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1183,7 +1178,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1191,7 +1186,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1224,14 +1219,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1254,7 +1249,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1262,7 +1257,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1280,7 +1275,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1288,11 +1283,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1308,7 +1303,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1398,7 +1393,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/PlusPhaseNeuron.wgsl b/axon/shaders/PlusPhaseNeuron.wgsl index 6e9453e5..09bceba8 100644 --- a/axon/shaders/PlusPhaseNeuron.wgsl +++ b/axon/shaders/PlusPhaseNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,56 +59,49 @@ fn main(@builtin(global_invocation_id) idx: vec3) { PlusPhaseNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_PlusPhaseNeuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { - var pi = LayerParams_PoolIndex(ly, NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnSubPool))]); + var pi = LayerParams_PoolIndex(ly, NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnSubPool))]); var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActP))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))]; - var nrnCaP = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; - var nrnCaD = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - var da = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvDA),u32(di))]; - var ach = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActP))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))]; + var nrnCaP = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; + var nrnCaD = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + var da = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvDA), u32(di))]; + var ach = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))]; var mlr = RLRateParams_RLRateSigDeriv(&(*ly).Learn.RLRate, nrnCaD, PoolAvgMax(AMCaD, AMCycle, Max, lpi, di)); var modlr = NeuroModParams_LRMod(&(*ly).Learn.NeuroMod, da, ach); var dlr = f32(1); - var hasRew = (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))]) > 0; + var hasRew = (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))]) > 0; switch ((*ly).Type) { case BLALayer: { - dlr = RLRateParams_RLRateDiff(&(*ly).Learn.RLRate, nrnCaP, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], // delta on previous trial - u32(ni),u32(di),u32(CaDPrev))]); - if (!NeuroModParams_IsBLAExt(&(*ly).Learn.NeuroMod) && PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurSt))] == 0) { // first pool + dlr = RLRateParams_RLRateDiff(&(*ly).Learn.RLRate, nrnCaP, Neurons[Index3D(TensorStrides[60], TensorStrides[61], // delta on previous trial + TensorStrides[62], u32(ni), u32(di), u32(CaDPrev))]); + if (!NeuroModParams_IsBLAExt(&(*ly).Learn.NeuroMod) && PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], // first pool + u32(pi), u32(0), u32(PoolNeurSt))] == 0) { dlr = f32(0); // first pool is novelty / curiosity -- no learn } } case VSPatchLayer: { - da = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[ // our own personal - 1], u32(GvVSPatchPosRPE),u32(di))]; + da = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], // our own personal + u32(GvVSPatchPosRPE), u32(di))]; modlr = NeuroModParams_LRMod(&(*ly).Learn.NeuroMod, da, ach); - mlr = RLRateParams_RLRateSigDeriv(&(*ly).Learn.RLRate, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], // note: don't have proper max here - u32(ni),u32(di),u32(CaDPrev))], f32(f32(1))); + mlr = RLRateParams_RLRateSigDeriv(&(*ly).Learn.RLRate, Neurons[Index3D(TensorStrides[60], TensorStrides[61], // note: don't have proper max here + TensorStrides[62], u32(ni), u32(di), u32(CaDPrev))], f32(f32(1))); } case MatrixLayer: { if (hasRew) { // reward time @@ -119,28 +114,28 @@ fn LayerParams_PlusPhaseNeuron(ly: ptr, ctx: ptr, n: f32) -> f32 { return (*mp).Gbar * n; } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -424,7 +419,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -432,7 +427,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -459,7 +454,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -479,9 +474,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -505,10 +500,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -528,7 +523,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -547,7 +542,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -619,7 +614,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -631,7 +626,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -648,9 +643,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -694,7 +689,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -741,7 +736,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -774,7 +769,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -788,13 +783,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -919,7 +914,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -929,7 +924,7 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" fn FastExp(x: f32) -> f32 { if (x <= -88.02969) { // this doesn't add anything and -exp is main use-case anyway return f32(0.0); @@ -939,7 +934,7 @@ fn FastExp(x: f32) -> f32 { i += (((((((((((3537 * m) >> 16) + 13668) * m) >> 18) + 15817) * m) >> 14) - 80470) * m) >> 11);return bitcast(u32(i)); } -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -953,7 +948,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -961,7 +956,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -977,7 +972,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1030,7 +1025,7 @@ fn NeuroModParams_LRMod(nm: ptr, da: f32,ach: f32) -> f }return lmod; } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1139,7 +1134,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1186,7 +1181,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1201,7 +1196,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1227,7 +1222,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1235,7 +1230,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1271,17 +1266,18 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1304,7 +1300,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1312,7 +1308,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1330,7 +1326,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1338,11 +1334,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1358,7 +1354,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1448,7 +1444,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/PlusPhasePool.wgsl b/axon/shaders/PlusPhasePool.wgsl index 289341d3..52f7837f 100644 --- a/axon/shaders/PlusPhasePool.wgsl +++ b/axon/shaders/PlusPhasePool.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,45 +59,37 @@ fn main(@builtin(global_invocation_id) idx: vec3) { PlusPhasePool(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_PlusPhasePool(ly: ptr, ctx: ptr, pi: u32,di: u32) { PoolCycleToPlus(pi, di); } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn PlusPhasePool(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var pi = Context_ItemIndex(&ctx, i); - var li = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolLayerIdx))]; + var li = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolLayerIdx))]; var layers=Layers[li]; LayerParams_PlusPhasePool(&layers, &ctx, pi, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -115,7 +109,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -240,7 +234,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -252,7 +246,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -260,7 +254,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -276,7 +270,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -288,7 +282,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -308,7 +302,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -320,7 +314,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -332,7 +326,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -344,7 +338,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -360,7 +354,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -368,7 +362,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -395,7 +389,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -415,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -441,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -464,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -483,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -555,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -567,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -584,9 +578,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -630,7 +624,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -674,7 +668,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -707,7 +701,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -721,13 +715,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -821,7 +815,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -831,9 +825,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -847,7 +841,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -855,7 +849,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -871,7 +865,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -896,7 +890,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1005,7 +999,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1052,7 +1046,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1067,7 +1061,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1093,7 +1087,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1101,7 +1095,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1138,19 +1132,19 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { } fn PoolCycleToPlus(pi: u32,di: u32) { for (var vr=0; vr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1317,7 +1311,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/PlusPhasePost.wgsl b/axon/shaders/PlusPhasePost.wgsl index e20b1eb2..02b0bfd0 100644 --- a/axon/shaders/PlusPhasePost.wgsl +++ b/axon/shaders/PlusPhasePost.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { PlusPhasePost(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_IsLearnTrgAvg(ly: ptr) -> bool { if ((*ly).Acts.Clamp.IsInput == 1 || (*ly).Acts.Clamp.IsTarget == 1 || (*ly).Learn.TrgAvgAct.RescaleOn == 0) { return false; @@ -100,14 +94,14 @@ fn LayerParams_PlusPhasePost(ly: ptr, ctx: ptr 0); - var giveUp = (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvGiveUp),u32(di))] > 0); + var hasRew = (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0); + var giveUp = (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvGiveUp), u32(di))] > 0); if (hasRew || giveUp) { LayerParams_DecayState(ly, ctx, di, f32(f32(1)), f32(f32(1)), f32(f32(1))); for (var spi = u32(0); spi < np; spi++) { @@ -131,22 +125,22 @@ fn LayerParams_PlusPhaseActAvg(ly: ptr, ctx: ptr bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronIsOff(ni: u32) -> bool { return NeuronHasFlag(NeuronOff, ni, u32(u32(0))); @@ -312,84 +307,85 @@ struct ActParams { PopCode: PopCodeParams, } fn ActParams_DecayLearnCa(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaLrn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NmdaCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccCaInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaP))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(LearnCaD))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))] += decay * (1.0 - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaIn))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaR))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SKCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaLrn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NmdaCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccCaInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(LearnCaD))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))] += decay * (1.0 - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaIn))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaR))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SKCaM))]; } fn ActParams_DecayAHP(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(MahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gmahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpCa))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SahpN))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsahp))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaMed))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GknaSlow))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(MahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gmahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpCa))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SahpN))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsahp))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaMed))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GknaSlow))]; var kirMrest = (*ac).Kir.Mrest; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))] += decay * (kirMrest - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(KirM))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gkir))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))] += decay * (kirMrest - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(KirM))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gkir))]; } fn ActParams_DecayState(ac: ptr, ctx: ptr, ni: u32,di: u32, decay: f32,glong: f32,ahp: f32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISIAvg))] = -1.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] = (*ac).Init.Act; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spiked))] = 0.0; - if (decay > 0) { // no-op for most, but not all.. - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] - (*ac).Init.Act); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GeBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gi))] - NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ni),u32(GiBase))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gk))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] -= decay * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Vm))] - (*ac).Init.Vm); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiNoise))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))] -= decay * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeIntNorm))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))] = -1.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] = (*ac).Init.Act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], + u32(ni), u32(di), u32(Spiked))] = 0.0; + if (decay > 0) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] - (*ac).Init.Act); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GeBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gi))] - NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ni), u32(GiBase))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] -= decay * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Vm))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiNoise))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))] -= decay * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeIntNorm))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] -= glong * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VmDend))] - (*ac).Init.Vm); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] -= glong * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VmDend))] - (*ac).Init.Vm); if (ahp > 0) { ActParams_DecayAHP(ac, ctx, ni, di, ahp); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GgabaB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABAB))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GABABx))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gnmda))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintSyn))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GnmdaMaint))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gvgcc))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccM))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(VgccH))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gak))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Gsk))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GgabaB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABAB))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GABABx))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gnmda))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintSyn))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GnmdaMaint))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gvgcc))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccM))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(VgccH))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gak))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Gsk))]; if ((*ac).Decay.LearnCa > 0) { // learning-based Ca values -- not usual ActParams_DecayLearnCa(ac, ctx, ni, di, (*ac).Decay.LearnCa); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Inet))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GModSyn))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GMaintRaw))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(SSGiDend))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeExt))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] -= glong * Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))]; -} - -///////////// import: "chans-ak.go" + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Inet))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GModSyn))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GMaintRaw))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(SSGiDend))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeExt))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] -= glong * Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))]; +} + +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -401,7 +397,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -409,7 +405,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -425,7 +421,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -437,7 +433,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -457,7 +453,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -469,7 +465,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -481,7 +477,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -493,7 +489,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -509,7 +505,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -517,7 +513,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -538,7 +534,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -558,9 +554,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -584,10 +580,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -607,7 +603,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -626,7 +622,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -698,7 +694,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -710,7 +706,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -727,20 +723,20 @@ struct InhibParams { Pool: GiParams, } fn PoolInhibDecay(pi: u32,di: u32, decay: f32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]; // capture prior to decay - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] -= decay * Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]; -} - -///////////// import: "init-layer.go" + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]; // capture prior to decay + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] -= decay * Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]; +} + +//////// import: "init-layer.go" fn LayerParams_DecayState(ly: ptr, ctx: ptr, di: u32, decay: f32,glong: f32,ahp: f32) { var nn = (*ly).Indexes.NNeurons; for (var lni = u32(0); lni < nn; lni++) { @@ -752,9 +748,9 @@ fn LayerParams_DecayState(ly: ptr, ctx: ptr, ctx: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -892,7 +888,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -906,13 +902,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -1006,7 +1002,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -1016,9 +1012,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -1032,7 +1028,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -1040,7 +1036,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1056,7 +1052,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1081,7 +1077,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1190,7 +1186,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1237,7 +1233,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1252,7 +1248,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1283,74 +1279,74 @@ fn LayerParams_MatrixGated(ly: ptr, ctx: ptr 0; + var mtxGated = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(lpi), u32(di), u32(PoolGated))] > 0; var thalGated = false; if ((*ly).Matrix.ThalLay1Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay1Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay2Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay2Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay3Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay3Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay4Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay4Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay5Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay5Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } if ((*ly).Matrix.ThalLay6Index >= 0) { var tly = Layers[(*ly).Matrix.ThalLay6Index]; var tlpi = tly.PoolSt; - var gt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(tlpi),u32(di),u32(PoolGated))]; + var gt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(tlpi), u32(di), u32(PoolGated))]; thalGated = thalGated || gt > 0; } mtxGated = mtxGated && thalGated; if (!mtxGated) { // nobody did if thal didn't for (var spi = u32(0); spi < (*ly).Indexes.NPools; spi++) { var pi = LayerParams_PoolIndex(ly, spi); - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] = 0; } } if ((*ctx).PlusPhase == 1 && (*ly).Matrix.IsVS == 1) { - GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixJustGated),u32(di))] = f32(mtxGated); + GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixJustGated), u32(di))] = f32(mtxGated); if (mtxGated) { var poolIndex = i32(-1); for (var spi = u32(1); spi < (*ly).Indexes.NPools; spi++) { var pi = LayerParams_PoolIndex(ly, spi); - if (poolIndex < 0 && PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolGated))] > 0) { + if (poolIndex < 0 && PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolGated))] > 0) { poolIndex = i32(pi); } } if (poolIndex > 0) { - GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvVSMatrixPoolGated),u32(poolIndex),u32(di))] = f32(1.0); + GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvVSMatrixPoolGated), u32(poolIndex), u32(di))] = f32(1.0); } } } } } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1358,7 +1354,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1397,32 +1393,34 @@ fn AvgMaxIntVarIndex(vr: AvgMaxVars, am: AvgMax) -> u32 { return u32(PoolIntAvgMaxStart) + u32(vr)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } fn PoolAvgMaxInit(pi: u32,di: u32) { for (var vr=0; vr, ctx: ptr) { var li = (*ly).Index; for (var di = u32(0); di < (*ctx).NData; di++) { @@ -1497,9 +1495,9 @@ fn LayerParams_PhaseDiffFromActs(ly: ptr, ctx: ptr, ctx: ptr su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1623,7 +1621,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/PlusPhaseStartNeuron.wgsl b/axon/shaders/PlusPhaseStartNeuron.wgsl index 10b04ed2..d68bda44 100644 --- a/axon/shaders/PlusPhaseStartNeuron.wgsl +++ b/axon/shaders/PlusPhaseStartNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,52 +59,44 @@ fn main(@builtin(global_invocation_id) idx: vec3) { PlusPhaseStartNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_PlusPhaseStartNeuron(ly: ptr, ctx: ptr, ni: u32,di: u32) { if (NeuronHasFlag(NeuronHasTarg, ni, di)) { // will be clamped in plus phase - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ext))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Target))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ext))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Target))]; NeuronSetFlag(NeuronHasExt, ni, di); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ISI))] = -1.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], - u32(ni),u32(di),u32(ISIAvg))] = -1.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] = (*ly).Acts.Init.Act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ISI))] = -1.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], + TensorStrides[62], u32(ni), u32(di), u32(ISIAvg))] = -1.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] = (*ly).Acts.Init.Act; } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn PlusPhaseStartNeuron(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_PlusPhaseStartNeuron(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -122,12 +116,13 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" fn NeuronHasFlag(flag: NeuronFlags, ni: u32,di: u32) -> bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronSetFlag(flag: NeuronFlags, ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))] = bitcast(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))]) | u32(flag)); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))] = bitcast(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(NeurFlags))]) | u32(flag)); } struct SpikeParams { Thr: f32, @@ -253,7 +248,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -265,7 +260,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -273,7 +268,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -289,7 +284,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -301,7 +296,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -321,7 +316,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -333,7 +328,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -345,7 +340,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -357,7 +352,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -373,7 +368,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -381,7 +376,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -408,7 +403,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -428,9 +423,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -454,10 +449,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -477,7 +472,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -496,7 +491,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -568,7 +563,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -580,7 +575,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -597,9 +592,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -643,7 +638,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -687,7 +682,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -720,7 +715,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -734,13 +729,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -834,7 +829,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -844,9 +839,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -860,7 +855,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -868,7 +863,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -884,7 +879,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -909,7 +904,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1018,7 +1013,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1065,7 +1060,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1080,7 +1075,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1106,7 +1101,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1114,7 +1109,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1147,14 +1142,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1177,7 +1172,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1185,7 +1180,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1203,7 +1198,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1211,11 +1206,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1231,7 +1226,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1321,7 +1316,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/PoolGi.wgsl b/axon/shaders/PoolGi.wgsl index 5b37810e..98aaa519 100644 --- a/axon/shaders/PoolGi.wgsl +++ b/axon/shaders/PoolGi.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,42 +59,36 @@ fn main(@builtin(global_invocation_id) idx: vec3) { PoolGi(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_SubPoolGiFromSpikes(ly: ptr, ctx: ptr, lpi: u32,pi: u32,di: u32, lyInhib: bool, giMult: f32) { PoolInhibSpikesFromRaw(pi, di); PoolInhib(&(*ly).Inhib.Pool, pi, di, giMult); if (lyInhib) { - PoolInhibLayerMax(pi, di, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(lpi),u32(di),u32(TotalGi))]); // note: this requires lpl inhib to have been computed before! + PoolInhibLayerMax(pi, di, Pools[Index3D(TensorStrides[120], TensorStrides[121], // note: this requires lpl inhib to have been computed before! + TensorStrides[122], u32(lpi), u32(di), u32(TotalGi))]); } else { - PoolInhibPoolMax(pi, di, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))]); // display only - PoolInhibSaveOrig(lpi, di); // effective GiOrig + PoolInhibPoolMax(pi, di, Pools[Index3D(TensorStrides[120], TensorStrides[121], // display only + TensorStrides[122], u32(pi), u32(di), u32(TotalGi))]); + PoolInhibSaveOrig(lpi, di); // effective GiOrig } } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn PoolGi(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); @@ -101,7 +97,7 @@ fn PoolGi(i: u32) { //gosl:kernel Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -121,7 +117,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -246,7 +242,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -258,7 +254,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -266,7 +262,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -282,7 +278,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -294,7 +290,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -314,7 +310,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -326,7 +322,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -338,7 +334,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -350,7 +346,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -366,7 +362,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -374,7 +370,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -401,7 +397,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -421,9 +417,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -447,10 +443,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -485,7 +481,7 @@ fn GiParams_SSFromFBs(fb: ptr, ssf: ptr,ssi: pt *ssf += fbs*(1-*ssf) - (*fb).SSfDt**ssf; } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -504,7 +500,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -576,7 +572,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -588,7 +584,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -608,80 +604,81 @@ fn PoolInhib(fb: ptr, pi: u32,di: u32, gimult: f32) { if ((*fb).On == 0) { PoolInhibZero(pi, di);return; } - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] += (*fb).FFAvgDt * (Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))]); - var fsi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))]; - fsi = GiParams_FSiFromFFs(fb, fsi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))], Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] = fsi; - var clamped = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(Clamped))] > 0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] = (*fb).Gi * GiParams_FS(fb, fsi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))], clamped); - var ssf = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))]; - var ssi = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))]; - GiParams_SSFromFBs(fb, &ssf, &ssi, Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))]); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] = (*fb).Gi * (*fb).SS * ssi; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] = ssf; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] = ssi; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = PoolInhibGiFromFSSS(pi, di) + (*fb).FFPrv*Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] += (*fb).FFAvgDt * (Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] - Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))]); + var fsi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))]; + fsi = GiParams_FSiFromFFs(fb, fsi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))], Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] = fsi; + var clamped = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(Clamped))] > 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] = (*fb).Gi * GiParams_FS(fb, fsi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))], clamped); + var ssf = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))]; + var ssi = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))]; + GiParams_SSFromFBs(fb, &ssf, &ssi, Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))]); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] = (*fb).Gi * (*fb).SS * ssi; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] = ssf; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] = ssi; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = PoolInhibGiFromFSSS(pi, di) + (*fb).FFPrv*Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))]; PoolInhibSaveOrig(pi, di); } fn PoolInhibInitRaw(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))] = 0.0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FFsRawInt))] = 0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FBsRawInt))] = 0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], - u32(pi),u32(di),u32(GeExtRawInt))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))] = 0.0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FFsRawInt))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FBsRawInt))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], + u32(pi), u32(di), u32(GeExtRawInt))] = 0; } fn PoolInhibZero(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSf))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvg))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFAvgPrv))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GiOrig))] = 0.0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(LayGi))] = 0.0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(di),u32(Clamped))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSf))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(SSGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvg))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFAvgPrv))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GiOrig))] = 0.0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(LayGi))] = 0.0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(di), u32(Clamped))] = 0; } fn PoolInhibSpikesFromRaw(pi: u32,di: u32) { var fnn = f32(PoolNNeurons(pi)); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBs))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] / fnn; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFs))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExts))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBs))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] / fnn; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFs))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExts))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))]; PoolInhibInitRaw(pi, di); } fn PoolInhibSaveOrig(pi: u32,di: u32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GiOrig))] = Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GiOrig))] = Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))]; } fn PoolInhibGiFromFSSS(pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FSGi))] + Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(SSGi))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FSGi))] + Pools[Index3D(TensorStrides[120], TensorStrides[121], + TensorStrides[122], u32(pi), u32(di), u32(SSGi))]; } fn PoolInhibLayerMax(pi: u32,di: u32, liGi: f32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(LayGi))] = liGi; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = max(Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))], liGi); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(LayGi))] = liGi; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = max(Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))], liGi); } fn PoolInhibPoolMax(pi: u32,di: u32, piGi: f32) { - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))] = max(Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(TotalGi))], piGi); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))] = max(Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(TotalGi))], piGi); } fn PoolInhibIntToRaw(pi: u32,di: u32) { var floatFromInt = 1.0 / f32(u32(1)<<24); - var fbs = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FBsRawInt))]; - var ffs = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(FFsRawInt))]; - var geExt = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(GeExtRawInt))]; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FBsRaw))] = f32(fbs); - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(FFsRaw))] = f32(ffs) * floatFromInt; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(GeExtRaw))] = f32(geExt) * floatFromInt; + var fbs = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FBsRawInt))]; + var ffs = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(FFsRawInt))]; + var geExt = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(GeExtRawInt))]; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FBsRaw))] = f32(fbs); + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(FFsRaw))] = f32(ffs) * floatFromInt; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(GeExtRaw))] = f32(geExt) * floatFromInt; } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -725,7 +722,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -772,7 +769,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -805,7 +802,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -819,13 +816,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -919,7 +916,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -929,9 +926,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -945,7 +942,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -953,7 +950,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -969,7 +966,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -994,7 +991,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1103,7 +1100,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1150,7 +1147,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1165,7 +1162,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1191,7 +1188,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1199,7 +1196,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1238,25 +1235,25 @@ fn AvgMaxIntVarIndex(vr: AvgMaxVars, am: AvgMax) -> u32 { return u32(PoolIntAvgMaxStart) + u32(vr)*u32(AvgMaxN) + u32(am); } fn PoolNNeurons(pi: u32) -> i32 { - return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(0),u32(PoolNeurSt))]; + return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } fn PoolAvgMaxCalcVar(vr: AvgMaxVars, pi: u32,di: u32) { var floatFromInt = f32(1.0) / f32(u32(1)<<20); var vis = AvgMaxIntVarIndex(vr, Avg); - var sum = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))]; + var sum = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))]; if (sum < 0) { sum = i32(u32(1) << 20); } - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))] = 0; var vim = AvgMaxIntVarIndex(vr, Max); - var mx = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))]; + var mx = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))]; if (mx < 0) { mx = i32(u32(1) << 20); } - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))] = 0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; } fn PoolAvgMaxCalc(pi: u32,di: u32) { for (var vr=0; vr, pi: u32,di: u32) { - if (PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolIsLayer))] > 0) { + if (PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolIsLayer))] > 0) { return; } - var li = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolLayerIdx))]; + var li = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolLayerIdx))]; PoolAvgMaxCalc(pi, di); PoolInhibIntToRaw(pi, di); var ly = Layers[u32(li)]; - var giMult = LayerStates[IndexF323D(LayerStates[0], LayerStates[1], LayerStates[2], u32(li),u32(di),u32(LayerGiMult))]; + var giMult = LayerStates[Index3D(TensorStrides[80], TensorStrides[81], TensorStrides[82], u32(li), u32(di), u32(LayerGiMult))]; var lyIsOn = (ly.Inhib.Layer.On == 1); var lpi = LayerParams_PoolIndex(&ly, u32(0)); LayerParams_SubPoolGiFromSpikes(&ly, ctx, lpi, pi, di, lyIsOn, giMult); } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1307,7 +1304,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1315,7 +1312,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1333,7 +1330,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1341,11 +1338,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1361,7 +1358,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1451,7 +1448,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/SendSpike.wgsl b/axon/shaders/SendSpike.wgsl index bc78a8db..6cf9f03e 100644 --- a/axon/shaders/SendSpike.wgsl +++ b/axon/shaders/SendSpike.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,32 +59,24 @@ fn main(@builtin(global_invocation_id) idx: vec3) { SendSpike(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_SendSpike(ly: ptr, ctx: ptr, ni: u32,di: u32) { - var pi = LayerParams_PoolIndex(ly, NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnSubPool))]); + var pi = LayerParams_PoolIndex(ly, NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnSubPool))]); var lpi = LayerParams_PoolIndex(ly, u32(u32(0))); var lni = ni - (*ly).Indexes.NeurSt; LayerParams_PostSpike(ly, ctx, lpi, pi, ni, di); @@ -92,76 +86,76 @@ fn LayerParams_SendSpike(ly: ptr, ctx: ptr, ctx: ptr, lpi: u32,pi: u32,ni: u32,di: u32) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Burst))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Burst))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))]; var li = (*ly).Index; var pil = pi - (*ly).PoolSt; // 0-n pool index var pnn = u32(PoolNNeurons(pi)); - var pni = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnNeurIndex))] - u32(PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(PoolNeurSt))]); - var hasRew = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvHasRew),u32(di))] > 0; + var pni = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnNeurIndex))] - u32(PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(PoolNeurSt))]); + var hasRew = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvHasRew), u32(di))] > 0; switch ((*ly).Type) { case SuperLayer: { if ((*ctx).PlusPhase == 1) { var actMax = PoolAvgMax(AMCaP, AMCycle, Max, lpi, di); var actAvg = PoolAvgMax(AMCaP, AMCycle, Avg, lpi, di); var thr = BurstParams_ThrFromAvgMax(&(*ly).Bursts, actAvg, actMax); - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CaP))] < thr) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Burst))] = 0.0; + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CaP))] < thr) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Burst))] = 0.0; } } } case PTPredLayer, CTLayer: { if ((*ctx).Cycle == (*ctx).ThetaCycles-1) { if ((*ly).CT.DecayTau == 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeRaw))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeRaw))]; } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))] += Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeRaw))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))] += Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeRaw))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))]; } } case VSGatedLayer: { var dr = f32(0); if (pil == 0) { - dr = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixJustGated),u32(di))]; + dr = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixJustGated), u32(di))]; } else { - dr = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvVSMatrixHasGated),u32(di))]; + dr = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvVSMatrixHasGated), u32(di))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = dr; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = dr; } case BLALayer: { if ((*ctx).Cycle == (*ctx).ThetaCycles-1) { if (hasRew) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))] = 0.0; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] = 0.0; - } else if (GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvACh),u32(di))] > 0.1) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeRaw))]; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGeOrig))] = Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(CtxtGe))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))] = 0.0; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] = 0.0; + } else if (GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvACh), u32(di))] > 0.1) { + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeRaw))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGeOrig))] = Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(CtxtGe))]; } } } case LHbLayer: { if (pni == 0) { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvLHbDip),u32(di))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvLHbDip), u32(di))]; } else { - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvLHbBurst),u32(di))]; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvLHbBurst), u32(di))]; } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeRaw))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeSyn))] = DtParams_GeSynFromRawSteady(&(*ly).Acts.Dt, Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeRaw))]); } case DrivesLayer: { - var dr = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvDrives),u32(pil - 1),u32(di))]; + var dr = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvDrives), u32(pil - 1), u32(di))]; var act = dr; if (dr > 0) { act = PopCodeParams_EncodeValue(&(*ly).Acts.PopCode, pni, pnn, dr); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = act; } case UrgencyLayer: { - var ur = GlobalScalars[IndexF322D(GlobalScalars[0], GlobalScalars[1], u32(GvUrgency),u32(di))]; + var ur = GlobalScalars[Index2D(TensorStrides[90], TensorStrides[91], u32(GvUrgency), u32(di))]; var act = ur; if (ur > 0) { act = PopCodeParams_EncodeValue(&(*ly).Acts.PopCode, pni, pnn, ur); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] = act; + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] = act; } case USLayer: { var us = RubiconUSStimValue(di, pil-1, (*ly).Learn.NeuroMod.Valence); @@ -170,54 +164,55 @@ fn LayerParams_PostSpikeSpecial(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr, lpi: u32,pi: u32,ni: u32,di: u32) { LayerParams_PostSpikeSpecial(ly, ctx, lpi, pi, ni, di); var intdt = (*ly).Acts.Dt.IntDt; - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))] += intdt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Ge))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GeInt))]); - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))] += intdt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiSyn))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(GiInt))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))] += intdt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Ge))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GeInt))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))] += intdt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiSyn))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(GiInt))]); if ((*ctx).PlusPhase == 1) { intdt *= f32(3.0); } - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))] += intdt * (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Act))] - Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(ActInt))]); + Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))] += intdt * (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Act))] - Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(ActInt))]); } -///////////// import: "act-net.go" +//////// import: "act-net.go" fn SendSpike(i: u32) { //gosl:kernel var ctx = Ctx[0]; var di = Context_DataIndex(&ctx, i); var ni = Context_ItemIndex(&ctx, i); - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_SendSpike(&layers, &ctx, ni, di); Ctx[0] = ctx; } -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -281,29 +276,30 @@ fn PathParams_SendSpike(pt: ptr, ctx: ptr if (u32((*ctx).Cycle) != u32((*ctx).ThetaCycles)-1-(*pt).Com.DelLen) { return; } - sendVal *= Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[ // Burst is regular CaP for all non-SuperLayer neurons - 2], u32(ni),u32(di),u32(Burst))]; + sendVal *= Neurons[Index3D(TensorStrides[60], TensorStrides[61], // Burst is regular CaP for all non-SuperLayer neurons + TensorStrides[62], u32(ni), u32(di), u32(Burst))]; } else { - if (Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(Spike))] == 0) { + if (Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], u32(ni), u32(di), u32(Spike))] == 0) { return; } } var recvNeurSt = (*pt).Indexes.RecvNeurSt; var npst = (*pt).Indexes.NPathNeurSt; var cni = (*pt).Indexes.SendConSt + lni; - var synst = (*pt).Indexes.SynapseSt + PathSendCon[IndexU322D(PathSendCon[0], PathSendCon[1], u32(cni),u32(StartOff))]; - var synn = PathSendCon[IndexU322D(PathSendCon[0], PathSendCon[1], u32(cni),u32(Nitems))]; + var synst = (*pt).Indexes.SynapseSt + PathSendCon[Index2D(TensorStrides[20], TensorStrides[21], u32(cni), u32(StartOff))]; + var synn = PathSendCon[Index2D(TensorStrides[20], TensorStrides[21], u32(cni), u32(Nitems))]; for (var ci = u32(0); ci < synn; ci++) { var syni = synst + ci; - var ri = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynRecvIndex))]; + var ri = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynRecvIndex))]; var npti = npst + (ri - recvNeurSt); var deli = SynComParams_WriteOff(&(*pt).Com, (*ctx).CyclesTotal); - var sv = i32(sendVal * Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))]); - atomicAdd(&PathGBuf[IndexI323D(PathGBuf[0], PathGBuf[1], PathGBuf[2], u32(npti),u32(di),u32(deli))], sv); + var sv = i32(sendVal * Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))]); + atomicAdd(&PathGBuf[Index3D(TensorStrides[140], TensorStrides[141], TensorStrides[142], + u32(npti), u32(di), u32(deli))], sv); } } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -463,7 +459,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -475,7 +471,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -483,7 +479,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -499,7 +495,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -511,7 +507,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -531,7 +527,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -543,7 +539,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -555,7 +551,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -567,7 +563,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -583,7 +579,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -591,7 +587,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -618,7 +614,7 @@ fn Context_DataIndex(ctx: ptr, idx: u32) -> u32 { return idx % (*ctx).NData; } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -642,9 +638,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -668,10 +664,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -691,7 +687,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -710,7 +706,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -782,7 +778,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -794,7 +790,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -811,9 +807,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -857,7 +853,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -904,7 +900,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -937,7 +933,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -951,13 +947,13 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -1051,7 +1047,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -1061,7 +1057,7 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" fn FastExp(x: f32) -> f32 { if (x <= -88.02969) { // this doesn't add anything and -exp is main use-case anyway return f32(0.0); @@ -1071,7 +1067,7 @@ fn FastExp(x: f32) -> f32 { i += (((((((((((3537 * m) >> 16) + 13668) * m) >> 18) + 15817) * m) >> 14) - 80470) * m) >> 11);return bitcast(u32(i)); } -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -1085,7 +1081,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -1101,7 +1097,7 @@ fn F32_ClipValue(mr: ptr, val: f32) -> f32 { }return val; } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1117,7 +1113,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1142,7 +1138,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1251,7 +1247,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1298,7 +1294,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1313,7 +1309,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1339,7 +1335,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1347,7 +1343,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1383,21 +1379,22 @@ fn AvgMaxVarIndex(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax) -> u32 { return u32(poolFloatAvgMaxStart) + u32(vr)*u32(AvgMaxN)*u32(AvgMaxPhasesN) + u32(phase)*u32(AvgMaxN) + u32(am); } fn PoolAvgMax(vr: AvgMaxVars, phase: AvgMaxPhases, am: AvgMax, pi: u32,di: u32) -> f32 { - return Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, phase, am)))]; + return Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], + u32(pi), u32(di), u32(AvgMaxVarIndex(vr, phase, am)))]; } fn PoolNNeurons(pi: u32) -> i32 { - return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(0),u32(PoolNeurSt))]; + return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1420,7 +1417,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1428,7 +1425,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1446,7 +1443,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1454,24 +1451,24 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" fn RubiconUSStimValue(di: u32, usIndex: u32, valence: ValenceTypes) -> f32 { var nix = NetworkIxs[0]; var us = f32(0); switch (valence) { case Positive: { if (usIndex < nix.RubiconNPosUSs) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvUSpos),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvUSpos), u32(usIndex), u32(di))]; } } case Negative: { if (usIndex < nix.RubiconNNegUSs) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvUSneg),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvUSneg), u32(usIndex), u32(di))]; } } case Cost: { if (usIndex < nix.RubiconNCosts) { - us = GlobalVectors[IndexF323D(GlobalVectors[0], GlobalVectors[1], GlobalVectors[2], u32(GvCost),u32(usIndex),u32(di))]; + us = GlobalVectors[Index3D(TensorStrides[100], TensorStrides[101], TensorStrides[102], u32(GvCost), u32(usIndex), u32(di))]; } } default: { @@ -1479,9 +1476,9 @@ fn RubiconUSStimValue(di: u32, usIndex: u32, valence: ValenceTypes) -> f32 { }return us; } -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1497,7 +1494,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1587,7 +1584,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/SlowAdaptLayer.wgsl b/axon/shaders/SlowAdaptLayer.wgsl index 1067ab3d..f8ee868d 100644 --- a/axon/shaders/SlowAdaptLayer.wgsl +++ b/axon/shaders/SlowAdaptLayer.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { SlowAdaptLayer(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_IsInput(ly: ptr) -> bool { switch ((*ly).Type) { case InputLayer: { @@ -92,9 +86,9 @@ fn LayerParams_IsInput(ly: ptr) -> bool { } } -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -114,9 +108,10 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" fn NeuronHasFlag(flag: NeuronFlags, ni: u32,di: u32) -> bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronIsOff(ni: u32) -> bool { return NeuronHasFlag(NeuronOff, ni, u32(u32(0))); @@ -245,7 +240,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -257,7 +252,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -265,7 +260,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -281,7 +276,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -293,7 +288,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -313,7 +308,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -325,7 +320,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -337,7 +332,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -349,7 +344,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -365,7 +360,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -373,7 +368,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -394,7 +389,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -414,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -440,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -463,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -482,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -554,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -566,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -590,9 +585,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -636,7 +631,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -683,7 +678,7 @@ fn LayerParams_PoolIndex(ly: ptr, pi: u32) -> u32 { return (*ly).PoolSt + pi; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -716,7 +711,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -730,7 +725,7 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" fn LayerParams_SlowAdaptLayer(ly: ptr, ctx: ptr) { LayerParams_AdaptInhib(ly, ctx); LayerParams_AvgDifFromTrgAvg(ly, ctx); @@ -740,10 +735,11 @@ fn LayerParams_AdaptInhib(ly: ptr, ctx: ptr, ctx: ptr) { @@ -754,8 +750,8 @@ fn LayerParams_AvgDifFromTrgAvg(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr u32 { return u32(PoolIntAvgMaxStart) + u32(vr)*u32(AvgMaxN) + u32(am); } fn PoolNNeurons(pi: u32) -> i32 { - return PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(0),u32(PoolNeurEd))] - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[ - 2], u32(pi),u32(0),u32(PoolNeurSt))]; + return PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(0), u32(PoolNeurEd))] - PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], + TensorStrides[132], u32(pi), u32(0), u32(PoolNeurSt))]; } fn PoolAvgMaxUpdateVar(vr: AvgMaxVars, pi: u32,di: u32, val: f32) { var n = f32(PoolNNeurons(pi)); @@ -1242,29 +1238,30 @@ fn PoolAvgMaxUpdateVar(vr: AvgMaxVars, pi: u32,di: u32, val: f32) { var floatToSum = floatToInt / n; var vis = AvgMaxIntVarIndex(vr, Avg); var vim = AvgMaxIntVarIndex(vr, Max); - atomicAdd(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))], i32(val*floatToSum)); - atomicMax(&PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))], i32(val*floatToInt)); + atomicAdd(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))], i32(val*floatToSum)); + atomicMax(&PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], + u32(pi), u32(di), u32(vim))], i32(val*floatToInt)); } fn PoolAvgMaxCalcVar(vr: AvgMaxVars, pi: u32,di: u32) { var floatFromInt = f32(1.0) / f32(u32(1)<<20); var vis = AvgMaxIntVarIndex(vr, Avg); - var sum = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))]; + var sum = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))]; if (sum < 0) { sum = i32(u32(1) << 20); } - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vis))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Avg)))] = f32(sum) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vis))] = 0; var vim = AvgMaxIntVarIndex(vr, Max); - var mx = PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))]; + var mx = PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))]; if (mx < 0) { mx = i32(u32(1) << 20); } - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(vim))] = 0; - Pools[IndexF323D(Pools[0], Pools[1], Pools[2], u32(pi),u32(di),u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(vim))] = 0; + Pools[Index3D(TensorStrides[120], TensorStrides[121], TensorStrides[122], u32(pi), u32(di), u32(AvgMaxVarIndex(vr, AMCycle, Max)))] = f32(mx) * floatFromInt; } fn PoolAvgDifInit(pi: u32,di: u32) { - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(AvgMaxIntVarIndex(AMAvgDif, Avg)))] = 0; - PoolsInt[IndexI323D(PoolsInt[0], PoolsInt[1], PoolsInt[2], u32(pi),u32(di),u32(AvgMaxIntVarIndex(AMAvgDif, Max)))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(AvgMaxIntVarIndex(AMAvgDif, Avg)))] = 0; + PoolsInt[Index3D(TensorStrides[130], TensorStrides[131], TensorStrides[132], u32(pi), u32(di), u32(AvgMaxIntVarIndex(AMAvgDif, Max)))] = 0; } fn PoolAvgDifUpdate(pi: u32,di: u32, avdif: f32) { PoolAvgMaxUpdateVar(AMAvgDif, pi, di, avdif); @@ -1273,14 +1270,14 @@ fn PoolAvgDifCalc(pi: u32,di: u32) { PoolAvgMaxCalcVar(AMAvgDif, pi, di); } -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1303,7 +1300,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1311,7 +1308,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1329,7 +1326,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1337,11 +1334,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1357,7 +1354,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1447,7 +1444,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/SlowAdaptNeuron.wgsl b/axon/shaders/SlowAdaptNeuron.wgsl index 8c65cd48..a5f17d55 100644 --- a/axon/shaders/SlowAdaptNeuron.wgsl +++ b/axon/shaders/SlowAdaptNeuron.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { SlowAdaptNeuron(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_IsTarget(ly: ptr) -> bool { switch ((*ly).Type) { case TargetLayer: { @@ -100,9 +94,9 @@ fn LayerParams_IsLearnTrgAvg(ly: ptr) -> bool { }return true; } -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -122,7 +116,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -247,7 +241,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -259,7 +253,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -267,7 +261,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -283,7 +277,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -295,7 +289,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -315,7 +309,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -327,7 +321,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -339,7 +333,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -351,7 +345,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -367,7 +361,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -375,7 +369,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -396,7 +390,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -416,9 +410,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -442,10 +436,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -465,7 +459,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -484,7 +478,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -556,7 +550,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -568,7 +562,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -585,9 +579,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -631,7 +625,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -675,7 +669,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -708,7 +702,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -722,25 +716,25 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" fn LayerParams_SlowAdaptNeuron(ly: ptr, ctx: ptr, ri: u32) { var lni = ri - (*ly).Indexes.NeurSt; var rn = (*ly).Indexes.RecvN; for (var pi = u32(0); pi < rn; pi++) { - var pti = RecvPathIxs[IndexU321D(RecvPathIxs[0], u32((*ly).Indexes.RecvSt + pi))]; + var pti = RecvPathIxs[Index1D(TensorStrides[30], u32((*ly).Indexes.RecvSt + pi))]; var paths=Paths[pti]; PathParams_SlowAdapt(&paths, ctx, ly, pti, ri, lni); } } -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn SlowAdaptNeuron(ni: u32) { //gosl:kernel var ctx = Ctx[0]; - var li = NeuronIxs[IndexU322D(NeuronIxs[0], NeuronIxs[1], u32(ni),u32(NrnLayIndex))]; + var li = NeuronIxs[Index2D(TensorStrides[0], TensorStrides[1], u32(ni), u32(NrnLayIndex))]; var layers=Layers[li]; LayerParams_SlowAdaptNeuron(&layers, &ctx, ni); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" fn PathParams_SlowAdapt(pt: ptr, ctx: ptr, rlay: ptr, pti: u32,ri: u32,lni: u32) { PathParams_SWtFromWt(pt, ctx, rlay, pti, ri, lni); PathParams_SynScale(pt, ctx, rlay, pti, ri, lni); @@ -756,29 +750,29 @@ fn PathParams_SWtFromWt(pt: ptr, ctx: ptr var mn = (*pt).SWts.Limit.Min; var lr = (*pt).SWts.Adapt.LRate; var cni = (*pt).Indexes.RecvConSt + lni; - var synn = PathRecvCon[IndexU322D(PathRecvCon[0], PathRecvCon[1], u32(cni),u32(Nitems))]; - var synst = (*pt).Indexes.RecvSynSt + PathRecvCon[IndexU322D(PathRecvCon[0], PathRecvCon[1], u32(cni),u32(StartOff))]; + var synn = PathRecvCon[Index2D(TensorStrides[40], TensorStrides[41], u32(cni), u32(Nitems))]; + var synst = (*pt).Indexes.RecvSynSt + PathRecvCon[Index2D(TensorStrides[40], TensorStrides[41], u32(cni), u32(StartOff))]; var avgDWt = f32(0); for (var ci = u32(0); ci < synn; ci++) { - var syni = RecvSynIxs[IndexU321D(RecvSynIxs[0], u32(synst + ci))]; - var swt = Synapses[IndexF322D(Synapses[0], Synapses[ - 1], u32(syni),u32(SWt))]; - if (Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] >= 0) { - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] *= (mx - swt); + var syni = RecvSynIxs[Index1D(TensorStrides[50], u32(synst + ci))]; + var swt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], + u32(syni), u32(SWt))]; + if (Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] >= 0) { + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] *= (mx - swt); } else { - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] *= (swt - mn); + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] *= (swt - mn); } - avgDWt += Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))]; + avgDWt += Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))]; } avgDWt /= f32(synn); avgDWt *= (*pt).SWts.Adapt.SubMean; for (var ci = u32(0); ci < synn; ci++) { - var syni = RecvSynIxs[IndexU321D(RecvSynIxs[0], u32(synst + ci))]; - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(SWt))] += lr * (Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] - avgDWt); - var swt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(SWt))]; - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] = 0.0; - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))] = SWtParams_LWtFromWts(&(*pt).SWts, Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))], swt); - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] = SWtParams_WtValue(&(*pt).SWts, swt, Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))]); + var syni = RecvSynIxs[Index1D(TensorStrides[50], u32(synst + ci))]; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(SWt))] += lr * (Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] - avgDWt); + var swt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(SWt))]; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] = 0.0; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))] = SWtParams_LWtFromWts(&(*pt).SWts, Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))], swt); + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] = SWtParams_WtValue(&(*pt).SWts, swt, Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))]); } } fn PathParams_SynScale(pt: ptr, ctx: ptr, rlay: ptr, pti: u32,ri: u32,lni: u32) { @@ -790,23 +784,24 @@ fn PathParams_SynScale(pt: ptr, ctx: ptr, } var lr = (*rlay).Learn.TrgAvgAct.SynScaleRate; var cni = (*pt).Indexes.RecvConSt + lni; - var synn = PathRecvCon[IndexU322D(PathRecvCon[0], PathRecvCon[1], u32(cni),u32(Nitems))]; - var synst = (*pt).Indexes.RecvSynSt + PathRecvCon[IndexU322D(PathRecvCon[0], PathRecvCon[1], u32(cni),u32(StartOff))]; - var adif = -lr * NeuronAvgs[IndexF322D(NeuronAvgs[0], NeuronAvgs[1], u32(ri),u32(AvgDif))]; + var synn = PathRecvCon[Index2D(TensorStrides[40], TensorStrides[41], u32(cni), u32(Nitems))]; + var synst = (*pt).Indexes.RecvSynSt + PathRecvCon[Index2D(TensorStrides[40], TensorStrides[41], u32(cni), u32(StartOff))]; + var adif = -lr * NeuronAvgs[Index2D(TensorStrides[70], TensorStrides[71], u32(ri), u32(AvgDif))]; for (var ci = u32(0); ci < synn; ci++) { - var syni = RecvSynIxs[IndexU321D(RecvSynIxs[0], u32(synst + ci))]; - var lwt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))]; - var swt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(SWt))]; - if (adif >= 0) { // key to have soft bounding on lwt here! - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))] += (1 - lwt) * adif * swt; + var syni = RecvSynIxs[Index1D(TensorStrides[50], u32(synst + ci))]; + var lwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))]; + var swt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], + u32(syni), u32(SWt))]; + if (adif >= 0) { + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))] += (1 - lwt) * adif * swt; } else { - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))] += lwt * adif * swt; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))] += lwt * adif * swt; } - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] = SWtParams_WtValue(&(*pt).SWts, swt, Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))]); + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] = SWtParams_WtValue(&(*pt).SWts, swt, Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))]); } } -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -964,7 +959,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -974,9 +969,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -990,7 +985,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -998,7 +993,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -1014,7 +1009,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -1039,7 +1034,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1148,7 +1143,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1198,7 +1193,7 @@ fn PathParams_IsInhib(pt: ptr) -> bool { return (*pt).Com.GType == InhibitoryG; } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1213,7 +1208,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1239,7 +1234,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1247,7 +1242,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1280,14 +1275,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1310,7 +1305,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1318,7 +1313,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1336,7 +1331,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1344,11 +1339,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1364,7 +1359,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1454,7 +1449,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/WtFromDWtLayer.wgsl b/axon/shaders/WtFromDWtLayer.wgsl index ee255a6b..26db1ad7 100644 --- a/axon/shaders/WtFromDWtLayer.wgsl +++ b/axon/shaders/WtFromDWtLayer.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,30 +59,22 @@ fn main(@builtin(global_invocation_id) idx: vec3) { WtFromDWtLayer(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" fn LayerParams_IsLearnTrgAvg(ly: ptr) -> bool { if ((*ly).Acts.Clamp.IsInput == 1 || (*ly).Acts.Clamp.IsTarget == 1 || (*ly).Learn.TrgAvgAct.RescaleOn == 0) { return false; @@ -92,9 +86,9 @@ fn LayerParams_LearnTrgAvgErrLRate(ly: ptr) -> f32 { }return (*ly).Learn.TrgAvgAct.ErrLRate; } -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -114,9 +108,10 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" fn NeuronHasFlag(flag: NeuronFlags, ni: u32,di: u32) -> bool { - return (NeuronFlags(bitcast(Neurons[IndexF323D(Neurons[0], Neurons[1], Neurons[2], u32(ni),u32(di),u32(NeurFlags))])) & flag) > 0; // weird: != 0 does NOT work on GPU + return (NeuronFlags(bitcast(Neurons[Index3D(TensorStrides[60], TensorStrides[61], TensorStrides[62], // weird: != 0 does NOT work on GPU + u32(ni), u32(di), u32(NeurFlags))])) & flag) > 0; } fn NeuronIsOff(ni: u32) -> bool { return NeuronHasFlag(NeuronOff, ni, u32(u32(0))); @@ -245,7 +240,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -257,7 +252,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -265,7 +260,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -281,7 +276,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -293,7 +288,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -313,7 +308,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -325,7 +320,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -337,7 +332,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -349,7 +344,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -365,7 +360,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -373,7 +368,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -394,7 +389,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -414,9 +409,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -440,10 +435,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -463,7 +458,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -482,7 +477,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -554,7 +549,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -566,7 +561,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -583,9 +578,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -629,7 +624,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -679,7 +674,7 @@ fn LayerParams_HasPoolInhib(ly: ptr) -> bool { return (*ly).Inhib.Pool.On == 1; } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -712,7 +707,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -726,7 +721,7 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" fn LayerParams_DTrgSubMean(ly: ptr, ctx: ptr) { var submean = (*ly).Learn.TrgAvgAct.SubMean; if (submean == 0) { @@ -736,8 +731,8 @@ fn LayerParams_DTrgSubMean(ly: ptr, ctx: ptr, ctx: ptr, ctx: ptr, ctx: ptr, ctx: ptr, ctx: ptr, ctx: ptr) { LayerParams_TrgAvgFromD(ly, ctx); } -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn WtFromDWtLayer(li: u32) { //gosl:kernel var ctx = Ctx[0]; var layers=Layers[li]; LayerParams_WtFromDWtLayer(&layers, &ctx); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -913,7 +908,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -923,9 +918,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -939,7 +934,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -955,7 +950,7 @@ fn F32_ClipValue(mr: ptr, val: f32) -> f32 { }return val; } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -971,7 +966,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -996,7 +991,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1105,7 +1100,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1152,7 +1147,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1167,7 +1162,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1193,7 +1188,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1201,7 +1196,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1234,14 +1229,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1264,7 +1259,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1272,7 +1267,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1290,7 +1285,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1298,11 +1293,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1318,7 +1313,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1408,7 +1403,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/axon/shaders/WtFromDWtSyn.wgsl b/axon/shaders/WtFromDWtSyn.wgsl index 33ecace1..1e630c0e 100644 --- a/axon/shaders/WtFromDWtSyn.wgsl +++ b/axon/shaders/WtFromDWtSyn.wgsl @@ -3,24 +3,26 @@ // // Layers are all the layer parameters. @group(0) @binding(0) -var Layers: array; +var TensorStrides: array; @group(0) @binding(1) -var Paths: array; +var Layers: array; +@group(0) @binding(2) +var Paths: array; // // NetworkIxs have indexes and sizes for entire network (one only). @group(1) @binding(0) -var NetworkIxs: array; +var NetworkIxs: array; @group(1) @binding(1) -var NeuronIxs: array; +var NeuronIxs: array; @group(1) @binding(2) -var SynapseIxs: array; +var SynapseIxs: array; @group(1) @binding(3) -var PathSendCon: array; +var PathSendCon: array; @group(1) @binding(4) -var RecvPathIxs: array; +var RecvPathIxs: array; @group(1) @binding(5) -var PathRecvCon: array; +var PathRecvCon: array; @group(1) @binding(6) -var RecvSynIxs: array; +var RecvSynIxs: array; // // Ctx is the current context state (one only). @group(2) @binding(0) var Ctx: array; @@ -57,34 +59,26 @@ fn main(@builtin(global_invocation_id) idx: vec3) { WtFromDWtSyn(idx.x); } -fn IndexU322D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { - return u32(2) + s0 * i0 + s1 * i1; +fn Index2D(s0: u32, s1: u32, i0: u32, i1: u32) -> u32 { + return s0 * i0 + s1 * i1; } -fn IndexU321D(s0: u32, i0: u32) -> u32 { - return u32(1) + s0 * i0; +fn Index1D(s0: u32, i0: u32) -> u32 { + return s0 * i0; } -fn IndexF323D(s0: f32, s1: f32, s2: f32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + bitcast(s0) * i0 + bitcast(s1) * i1 + bitcast(s2) * i2; -} - -fn IndexF322D(s0: f32, s1: f32, i0: u32, i1: u32) -> u32 { - return u32(2) + bitcast(s0) * i0 + bitcast(s1) * i1; -} - -fn IndexI323D(s0: i32, s1: i32, s2: i32, i0: u32, i1: u32, i2: u32) -> u32 { - return u32(3) + u32(s0) * i0 + u32(s1) * i1 + u32(s2) * i2; +fn Index3D(s0: u32, s1: u32, s2: u32, i0: u32, i1: u32, i2: u32) -> u32 { + return s0 * i0 + s1 * i1 + s2 * i2; } -///////////// import: "vars.go" +//////// import: "vars.go" -///////////// import: "act-layer.go" +//////// import: "act-layer.go" -///////////// import: "act-net.go" +//////// import: "act-net.go" -///////////// import: "act-path.go" +//////// import: "act-path.go" alias PathGTypes = i32; //enums:enum const ExcitatoryG: PathGTypes = 0; const InhibitoryG: PathGTypes = 1; @@ -104,7 +98,7 @@ struct PathScaleParams { pad1: f32, } -///////////// import: "act.go" +//////// import: "act.go" struct SpikeParams { Thr: f32, VmR: f32, @@ -229,7 +223,7 @@ struct ActParams { PopCode: PopCodeParams, } -///////////// import: "chans-ak.go" +//////// import: "chans-ak.go" struct AKsParams { Gbar: f32, Hf: f32, @@ -241,7 +235,7 @@ struct AKsParams { pad2: i32, } -///////////// import: "chans-chans.go" +//////// import: "chans-chans.go" struct Chans { E: f32, L: f32, @@ -249,7 +243,7 @@ struct Chans { K: f32, } -///////////// import: "chans-gabab.go" +//////// import: "chans-gabab.go" struct GABABParams { Gbar: f32, RiseTau: f32, @@ -265,7 +259,7 @@ struct GABABParams { pad2: f32, } -///////////// import: "chans-kir.go" +//////// import: "chans-kir.go" struct KirParams { Gbar: f32, MinfOff: f32, @@ -277,7 +271,7 @@ struct KirParams { Mrest: f32, } -///////////// import: "chans-kna.go" +//////// import: "chans-kna.go" struct KNaParams { On: i32, Rise: f32, @@ -297,7 +291,7 @@ struct KNaMedSlow { Slow: KNaParams, } -///////////// import: "chans-mahp.go" +//////// import: "chans-mahp.go" struct MahpParams { Gbar: f32, Voff: f32, @@ -309,7 +303,7 @@ struct MahpParams { pad2: i32, } -///////////// import: "chans-nmda.go" +//////// import: "chans-nmda.go" struct NMDAParams { Gbar: f32, Tau: f32, @@ -321,7 +315,7 @@ struct NMDAParams { MgFact: f32, } -///////////// import: "chans-sahp.go" +//////// import: "chans-sahp.go" struct SahpParams { Gbar: f32, CaTau: f32, @@ -333,7 +327,7 @@ struct SahpParams { pad: i32, } -///////////// import: "chans-skca.go" +//////// import: "chans-skca.go" struct SKCaParams { Gbar: f32, C50: f32, @@ -349,7 +343,7 @@ struct SKCaParams { CaInDt: f32, } -///////////// import: "chans-vgcc.go" +//////// import: "chans-vgcc.go" struct VGCCParams { Gbar: f32, Ca: f32, @@ -357,7 +351,7 @@ struct VGCCParams { pad1: i32, } -///////////// import: "context.go" +//////// import: "context.go" struct Context { NData: u32, Mode: i32, @@ -378,7 +372,7 @@ struct Context { RandCounter: RandCounter, } -///////////// import: "deep-layer.go" +//////// import: "deep-layer.go" struct BurstParams { ThrRel: f32, ThrAbs: f32, @@ -398,9 +392,9 @@ struct PulvParams { pad: f32, } -///////////// import: "deep-path.go" +//////// import: "deep-path.go" -///////////// import: "enumgen.go" +//////// import: "enumgen.go" const PathGTypesN: PathGTypes = 5; const GlobalScalarVarsN: GlobalScalarVars = 57; const GlobalVectorVarsN: GlobalVectorVars = 10; @@ -424,10 +418,10 @@ const SynapseVarsN: SynapseVars = 5; const SynapseTraceVarsN: SynapseTraceVars = 3; const SynapseIndexVarsN: SynapseIndexVars = 3; -///////////// import: "fsfffb-enumgen.go" +//////// import: "fsfffb-enumgen.go" const InhibVarsN: InhibVars = 16; -///////////// import: "fsfffb-fsfffb.go" +//////// import: "fsfffb-fsfffb.go" struct GiParams { On: i32, Gi: f32, @@ -447,7 +441,7 @@ struct GiParams { pad: f32, } -///////////// import: "fsfffb-inhib.go" +//////// import: "fsfffb-inhib.go" alias InhibVars = i32; //enums:enum const FFsRaw: InhibVars = 0; const FBsRaw: InhibVars = 1; @@ -466,7 +460,7 @@ const LayGi: InhibVars = 13; const FFAvg: InhibVars = 14; const FFAvgPrv: InhibVars = 15; -///////////// import: "globals.go" +//////// import: "globals.go" alias GlobalScalarVars = i32; //enums:enum const GvRew: GlobalScalarVars = 0; const GvHasRew: GlobalScalarVars = 1; @@ -538,7 +532,7 @@ const GvVSPatchD2: GlobalVectorVars = 7; const GvOFCposPTMaint: GlobalVectorVars = 8; const GvVSMatrixPoolGated: GlobalVectorVars = 9; -///////////// import: "hip_paths.go" +//////// import: "hip_paths.go" struct HipPathParams { Hebb: f32, Err: f32, @@ -550,7 +544,7 @@ struct HipPathParams { pad2: f32, } -///////////// import: "inhib.go" +//////// import: "inhib.go" struct ActAvgParams { Nominal: f32, AdaptGi: i32, @@ -567,9 +561,9 @@ struct InhibParams { Pool: GiParams, } -///////////// import: "init-layer.go" +//////// import: "init-layer.go" -///////////// import: "kinase-params.go" +//////// import: "kinase-params.go" struct CaDtParams { //types:add MTau: f32, PTau: f32, @@ -613,7 +607,7 @@ struct SynCaLinear { //types:add pad2: f32, } -///////////// import: "layerparams.go" +//////// import: "layerparams.go" struct LayerIndexes { NPools: u32, NeurSt: u32, @@ -657,7 +651,7 @@ struct LayerParams { Indexes: LayerIndexes, } -///////////// import: "layertypes.go" +//////// import: "layertypes.go" alias LayerTypes = i32; //enums:enum const SuperLayer: LayerTypes = 0; const InputLayer: LayerTypes = 1; @@ -690,7 +684,7 @@ const TDPredLayer: LayerTypes = 27; const TDIntegLayer: LayerTypes = 28; const TDDaLayer: LayerTypes = 29; -///////////// import: "layervars.go" +//////// import: "layervars.go" alias LayerVars = i32; //enums:enum const LayerActMAvg: LayerVars = 0; const LayerActPAvg: LayerVars = 1; @@ -704,17 +698,17 @@ const LayerRT: LayerVars = 8; const LayerRewPredPos: LayerVars = 9; const LayerRewPredNeg: LayerVars = 10; -///////////// import: "learn-layer.go" +//////// import: "learn-layer.go" -///////////// import: "learn-net.go" +//////// import: "learn-net.go" fn WtFromDWtSyn(syni: u32) { //gosl:kernel var ctx = Ctx[0]; - var pti = SynapseIxs[IndexU322D(SynapseIxs[0], SynapseIxs[1], u32(syni),u32(SynPathIndex))]; + var pti = SynapseIxs[Index2D(TensorStrides[10], TensorStrides[11], u32(syni), u32(SynPathIndex))]; var paths=Paths[pti]; PathParams_WtFromDWtSyn(&paths, &ctx, syni); Ctx[0] = ctx; } -///////////// import: "learn-path.go" +//////// import: "learn-path.go" fn PathParams_WtFromDWtSyn(pt: ptr, ctx: ptr, syni: u32) { switch ((*pt).Type) { case RWPath: { @@ -735,31 +729,31 @@ fn PathParams_WtFromDWtSyn(pt: ptr, ctx: ptr, ctx: ptr, syni: u32) { - var dwt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DWt))]; - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DSWt))] += dwt; - var wt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))]; - var lwt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))]; - SWtParams_WtFromDWt(&(*pt).SWts, &wt, &lwt, dwt, Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(SWt))]); - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DWt))] = 0.0; - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] = wt; - Synapses[IndexF322D(Synapses[0], Synapses[ - 1], u32(syni),u32(LWt))] = lwt; + var dwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DWt))]; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DSWt))] += dwt; + var wt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))]; + var lwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))]; + SWtParams_WtFromDWt(&(*pt).SWts, &wt, &lwt, dwt, Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(SWt))]); + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DWt))] = 0.0; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] = wt; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], + u32(syni), u32(LWt))] = lwt; } fn PathParams_WtFromDWtSynNoLimits(pt: ptr, ctx: ptr, syni: u32) { - var dwt = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(DWt))]; + var dwt = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(DWt))]; if (dwt == 0) { return; } - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] += dwt; - if (Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] < 0) { - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))] = 0.0; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] += dwt; + if (Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] < 0) { + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))] = 0.0; } - Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(LWt))] = Synapses[IndexF322D(Synapses[0], Synapses[1], u32(syni),u32(Wt))]; - Synapses[IndexF322D(Synapses[0], Synapses[1], - u32(syni),u32(DWt))] = 0.0; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(LWt))] = Synapses[Index2D(TensorStrides[160], TensorStrides[161], u32(syni), u32(Wt))]; + Synapses[Index2D(TensorStrides[160], TensorStrides[161], + u32(syni), u32(DWt))] = 0.0; } -///////////// import: "learn.go" +//////// import: "learn.go" struct LearnCaParams { Norm: f32, SpkVGCC: i32, @@ -897,7 +891,7 @@ struct LearnSynParams { Hebb: HebbParams, } -///////////// import: "looper.go" +//////// import: "looper.go" alias ViewTimes = i32; //enums:enum const Cycle: ViewTimes = 0; const FastSpike: ViewTimes = 1; @@ -907,9 +901,9 @@ const Alpha: ViewTimes = 4; const Phase: ViewTimes = 5; const Theta: ViewTimes = 6; -///////////// import: "math32-fastexp.go" +//////// import: "math32-fastexp.go" -///////////// import: "minmax-avgmax.go" +//////// import: "minmax-avgmax.go" const MaxFloat32: f32 = 3.402823466e+38; const MinFloat32: f32 = 1.175494351e-38; struct AvgMax32 { @@ -923,7 +917,7 @@ struct AvgMax32 { pad2: i32, } -///////////// import: "minmax-minmax32.go" +//////// import: "minmax-minmax32.go" struct F32 { Min: f32, Max: f32, @@ -931,7 +925,7 @@ struct F32 { pad1: i32, // for gpu use } -///////////// import: "network.go" +//////// import: "network.go" struct NetworkIndexes { MaxData: u32, MaxDelay: u32, @@ -947,7 +941,7 @@ struct NetworkIndexes { GPUSynCaBanks: u32, } -///////////// import: "neuromod.go" +//////// import: "neuromod.go" alias DAModTypes = i32; //enums:enum const NoDAMod: DAModTypes = 0; const D1Mod: DAModTypes = 1; @@ -972,7 +966,7 @@ struct NeuroModParams { pad2: f32, } -///////////// import: "neuron.go" +//////// import: "neuron.go" alias NeuronFlags = i32; //enums:enum const NeuronOff: NeuronFlags = 1; const NeuronHasExt: NeuronFlags = 2; @@ -1081,7 +1075,7 @@ const NrnNeurIndex: NeuronIndexVars = 0; const NrnLayIndex: NeuronIndexVars = 1; const NrnSubPool: NeuronIndexVars = 2; -///////////// import: "pathparams.go" +//////// import: "pathparams.go" const StartOff: i32 = 0; const Nitems: i32 = 1; const StartNN: i32 = 2; @@ -1128,7 +1122,7 @@ struct PathParams { Hip: HipPathParams, } -///////////// import: "pathtypes.go" +//////// import: "pathtypes.go" alias PathTypes = i32; //enums:enum const ForwardPath: PathTypes = 0; const BackPath: PathTypes = 1; @@ -1143,7 +1137,7 @@ const VSPatchPath: PathTypes = 9; const VSMatrixPath: PathTypes = 10; const DSMatrixPath: PathTypes = 11; -///////////// import: "pcore-layer.go" +//////// import: "pcore-layer.go" struct MatrixParams { GateThr: f32, IsVS: i32, @@ -1169,7 +1163,7 @@ struct GPParams { pad2: u32, } -///////////// import: "pcore-path.go" +//////// import: "pcore-path.go" struct MatrixPathParams { Credit: f32, BasePF: f32, @@ -1177,7 +1171,7 @@ struct MatrixPathParams { VSRewLearn: i32, } -///////////// import: "pool.go" +//////// import: "pool.go" alias PoolIntVars = i32; //enums:enum const PoolNeurSt: PoolIntVars = 0; const PoolNeurEd: PoolIntVars = 1; @@ -1210,14 +1204,14 @@ const PoolVarsN = poolFloatAvgMaxStart + InhibVars(i32(AvgMaxVarsN)*i32(AvgMaxN const PoolIntVarsTot = PoolIntAvgMaxStart + PoolIntVars(i32(AvgMaxVarsN)*i32(AvgMaxN)); const avgMaxToNeuron = array(CaP, CaD, CaPMax, Act, GeInt, GiInt); -///////////// import: "rand.go" +//////// import: "rand.go" alias RandFunIndex = u32; const RandFunActPGe: RandFunIndex = 0; const RandFunActPGi: RandFunIndex = 1; const RandFunActSMaintP: RandFunIndex = 2; const RandFunIndexN: RandFunIndex = 3; -///////////// import: "rl-layer.go" +//////// import: "rl-layer.go" struct RWPredParams { PredRange: F32, } @@ -1240,7 +1234,7 @@ struct TDDaParams { pad1: u32, } -///////////// import: "rl-path.go" +//////// import: "rl-path.go" struct RLPredPathParams { OppSignLRate: f32, DaTol: f32, @@ -1248,7 +1242,7 @@ struct RLPredPathParams { pad1: f32, } -///////////// import: "rubicon-layer.go" +//////// import: "rubicon-layer.go" struct LDTParams { SrcThr: f32, Rew: i32, @@ -1266,7 +1260,7 @@ struct VTAParams { pad: f32, } -///////////// import: "rubicon-path.go" +//////// import: "rubicon-path.go" struct BLAPathParams { NegDeltaLRate: f32, AChThr: f32, @@ -1274,11 +1268,11 @@ struct BLAPathParams { pad: f32, } -///////////// import: "rubicon.go" +//////// import: "rubicon.go" -///////////// import: "stats.go" +//////// import: "stats.go" -///////////// import: "synapse.go" +//////// import: "synapse.go" alias SynapseVars = i32; //enums:enum const Wt: SynapseVars = 0; const LWt: SynapseVars = 1; @@ -1294,7 +1288,7 @@ const SynRecvIndex: SynapseIndexVars = 0; const SynSendIndex: SynapseIndexVars = 1; const SynPathIndex: SynapseIndexVars = 2; -///////////// import: "slrand.wgsl" +//////// import: "slrand.wgsl" fn Philox2x32round(counter: su64, key: u32) -> su64 { let mul = Uint32Mul64(u32(0xD256D193), counter.x); var ctr: su64; @@ -1384,7 +1378,7 @@ fn RandCounter_Add(ct: ptr, inc: u32) { (*ct).Counter = Uint64Add32((*ct).Counter, inc); } -///////////// import: "sltype.wgsl" +//////// import: "sltype.wgsl" alias su64 = vec2; fn Uint32Mul64(a: u32, b: u32) -> su64 { let LOMASK = (((u32(1))<<16)-1); diff --git a/examples/ra25/ra25.go b/examples/ra25/ra25.go index 2e80b383..eeb2dc52 100644 --- a/examples/ra25/ra25.go +++ b/examples/ra25/ra25.go @@ -114,7 +114,7 @@ type RunConfig struct { // GPU uses the GPU for computation, generally faster than CPU even for // small models if NData ~16. - GPU bool `default:"true"` + GPU bool `default:"false"` // NData is the number of data-parallel items to process in parallel per trial. // Is significantly faster for both CPU and GPU. Results in an effective