public FeedForwardLayer(ExecutionContext executionContext, FeedForwardLayerOptions options, ushort[] previousLayerDimensionality) { _options = options; Dimensionality = options.Dimensionality; _weightLength = MatrixHelpers.GetWeightCardinality(previousLayerDimensionality, options.Dimensionality); NodeCount = MatrixHelpers.GetCardinality(options.Dimensionality); _previousLayerNodeCount = MatrixHelpers.GetCardinality(previousLayerDimensionality); _activation = (options.ActivationOptions ?? new ReluActivationOptions()) .Create(); _update = (options.UpdateOptions ?? new FeedForwardUpdateOptions()) .Create(executionContext); CompileKernels(executionContext); AllocateBuffers(executionContext, options); SetForwardPassArgs(); SetBackwardPassArgs(); }
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); } }