private void SetBackwardPassArgs() { // Arg 1: layerNodeCount (uint) ClHelpers.SetKernelArg( _backwardKernel, 1, (uint)NodeCount ); // Arg 2: nextLayerNodeCount (uint) ClHelpers.SetKernelArg( _backwardKernel, 2, (uint)0 ); // Arg 3: layerSums (float*) _layerSums.SetKernelArg(_backwardKernel, 3); // Arg 4: layerOutputs (float*) _layerOutputs.SetKernelArg(_backwardKernel, 4); // Arg 5: layerOutputs (float*) _layerDeltas.SetKernelArg(_backwardKernel, 5); // Arg 6: layerWeights (float*) _weights.SetKernelArg(_backwardKernel, 6); // Arg 7: layerBiases (float*) _biases.SetKernelArg(_backwardKernel, 7); // Arg 8: previousLayerOutputs (float*) GpuMatrix.SetNullKernelArg(_backwardKernel, 8); // Arg 9: nextLayerDeltas (float*) GpuMatrix.SetNullKernelArg(_backwardKernel, 9); // // Arg 10: nextLayerWeights (float*) GpuMatrix.SetNullKernelArg(_backwardKernel, 10); // Arg 11: targets (float*) GpuMatrix.SetNullKernelArg(_backwardKernel, 11); }
public InputLayer(ExecutionContext executionContext, InputLayerOptions options) { _executionContext = executionContext; Dimensionality = options.Dimensionality; NodeCount = 1; foreach (var i in options.Dimensionality) { NodeCount *= i; } _inputs = new GpuMatrix((ushort)NodeCount, 1, executionContext); }
public void Read_Works() { var matrix = new GpuMatrix(3, 3, _testScaffold.Context); using (matrix.Read(_testScaffold.ExecutionSequence)) { matrix.InMemoryData.Length.Should().Be(9); for (var i = 0; i < 9; i++) { matrix.InMemoryData[i].Should().Be(0); } } }
public void Update_DoesntThrow() { var matrix = new GpuMatrix(3, 3, _testScaffold.Context); matrix.Update( new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }, _testScaffold.ExecutionSequence ); }
public void UpdateRead_Works() { var matrix = new GpuMatrix(3, 3, _testScaffold.Context); matrix.Update( new double[] { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }, _testScaffold.ExecutionSequence ); using (matrix.Read(_testScaffold.ExecutionSequence)) { for (var i = 0; i < 9; i++) { matrix.InMemoryData[i].Should().Be(i); } } }
public void SetTargets(ExecutionSequence executionSequence, double[] targets) { if (targets.Length != NodeCount) { throw new NerotiqException($"target value array length ({targets.Length}) does not match layer size ({NodeCount})"); } if (_layerTargets == null) { try { _layerTargets = new GpuMatrix((ushort)NodeCount, 1, executionSequence.Context); } catch (Exception ex) { throw new NerotiqException($"Error allocating delta buffer", ex); } _layerTargets.SetKernelArg( _backwardKernel, 11 ); } _layerTargets.Update(targets, executionSequence); }
private void AllocateBuffers(ExecutionContext executionContext, FeedForwardLayerOptions options) { try { _layerSums = new GpuMatrix((ushort)NodeCount, 1, executionContext); } catch (Exception ex) { throw new NerotiqException($"Error allocating sum buffer", ex); } try { _layerOutputs = new GpuMatrix((ushort)NodeCount, 1, executionContext); } catch (Exception ex) { throw new NerotiqException($"Error allocating output buffer", ex); } try { _layerDeltas = new GpuMatrix((ushort)NodeCount, 1, executionContext); } catch (Exception ex) { throw new NerotiqException($"Error allocating delta buffer", ex); } // Parameters try { _weights = new GpuMatrix((ushort)NodeCount, (ushort)_previousLayerNodeCount, executionContext); } catch (Exception ex) { throw new NerotiqException($"Error allocating weight buffer", ex); } try { _biases = new GpuMatrix((ushort)NodeCount, 1, executionContext); } catch (Exception ex) { throw new NerotiqException($"Error allocating bias buffer", ex); } }
public void SetKernelArgs_Works() { var src = @" __kernel void a( __global double *data // 0 ) { int global_id = get_global_id(0); data[global_id] *= data[global_id]; } "; var srcs = SourceLoader.CreateProgramCollection(src); var program = Cl.CreateProgramWithSource( _testScaffold.Context.OpenClContext, (uint)srcs.Length, srcs, null, out var error ); error.Should().Be(ErrorCode.Success); error = Cl.BuildProgram( program, 1, new[] { _testScaffold.Context.Device }, string.Empty, null, IntPtr.Zero ); error.Should().Be(ErrorCode.Success); var kernel = Cl.CreateKernel(program, "a", out error); error.Should().Be(ErrorCode.Success); var matrix = new GpuMatrix(3, 3, _testScaffold.Context); matrix.Update( new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }, _testScaffold.ExecutionSequence ); matrix.SetKernelArg(kernel, 0); _testScaffold.ExecutionSequence.EnqueueNDRangeKernel( kernel, 1, null, new IntPtr [] { new IntPtr(9) }, null ); using (matrix.Read(_testScaffold.ExecutionSequence)) { matrix.GetValue(0, 0).Should().Be(1.0); matrix.GetValue(0, 1).Should().Be(4.0); matrix.GetValue(0, 2).Should().Be(9.0); matrix.GetValue(1, 0).Should().Be(16.0); matrix.GetValue(1, 1).Should().Be(25.0); matrix.GetValue(1, 2).Should().Be(36.0); matrix.GetValue(2, 0).Should().Be(49.0); matrix.GetValue(2, 1).Should().Be(64.0); matrix.GetValue(2, 2).Should().Be(81.0); } }
public void Instanciate_DoesntThrow() { var matrix = new GpuMatrix(3, 3, _testScaffold.Context); }