Beispiel #1
0
 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);
 }
Beispiel #2
0
 private void SetForwardPassArgs()
 {
     // Arg 0: previousLayerNodeCount (uint)
     ClHelpers.SetKernelArg(
         _forwardKernel,
         0,
         (uint)_previousLayerNodeCount
         );
     // Arg 1: layerNodeCount (uint)
     ClHelpers.SetKernelArg(
         _forwardKernel,
         1,
         (uint)NodeCount
         );
     // Arg 3: layerWeights (float*)
     _weights.SetKernelArg(_forwardKernel, 3);
     // Arg 4: layerBiases (float*)
     _biases.SetKernelArg(_forwardKernel, 4);
     // Arg 5: layerSums (float*)
     _layerSums.SetKernelArg(_forwardKernel, 5);
     // Arg 6: layerOutputs (float*)
     _layerOutputs.SetKernelArg(_forwardKernel, 6);
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
        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);
            }
        }