コード例 #1
0
 public void SetInputs(ExecutionSequence executionSequence, double[] inputs)
 {
     if (inputs.Length != NodeCount)
     {
         throw new ArgumentException($"input array length ({inputs.Length}) does not match input layer size ({NodeCount})", nameof(inputs));
     }
     _inputs.Update(inputs, executionSequence);
 }
コード例 #2
0
 public void SetWeights(ExecutionSequence executionSequence, double[] weights)
 {
     if (weights.Length != _weightLength)
     {
         throw new ArgumentException($"weight array length ({weights.Length}) does not match required ({_weightLength})", nameof(weights));
     }
     _weights.Update(weights, executionSequence);
 }
コード例 #3
0
ファイル: GpuMatrixTest.cs プロジェクト: sami016/Nerotiq
        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
                );
        }
コード例 #4
0
ファイル: GpuMatrixTest.cs プロジェクト: sami016/Nerotiq
        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);
                }
            }
        }
コード例 #5
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);
 }
コード例 #6
0
 public void SetOutputs(ExecutionSequence executionSequence, double[] outputs)
 {
     _layerOutputs.Update(outputs, executionSequence);
 }
コード例 #7
0
 public void SetBiases(ExecutionSequence executionSequence, double[] biases)
 {
     _biases.Update(biases, executionSequence);
 }
コード例 #8
0
ファイル: GpuMatrixTest.cs プロジェクト: sami016/Nerotiq
        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);
            }
        }