---
title: "init(device:convolutionDescriptor:kernelWeights:biasTerms:flags:)"
framework: metalperformanceshaders
role: symbol
role_heading: Initializer
path: "metalperformanceshaders/mpscnnfullyconnected/init(device:convolutiondescriptor:kernelweights:biasterms:flags:)"
---

# init(device:convolutionDescriptor:kernelWeights:biasTerms:flags:)

Initializes a fully connected convolution layer.

## Declaration

```swift
init(device: any MTLDevice, convolutionDescriptor: MPSCNNConvolutionDescriptor, kernelWeights: UnsafePointer<Float>, biasTerms: UnsafePointer<Float>?, flags: MPSCNNConvolutionFlags)
```

## Parameters

- `device`: The device on which this kernel will run.
- `convolutionDescriptor`: A valid convolution descriptor. The values of the```MPSCNNConvolutionDescriptor/strideInPixelsX``, ``MPSCNNConvolutionDescriptor/strideInPixelsY``, and ``MPSCNNConvolutionDescriptor/groups`` properties of the descriptor must be set to1` (i.e. their default values).
- `kernelWeights`: A pointer to a weights array. Each entry is a float value. The number of entries is equal to doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor/inputFeatureChannels * doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor/outputFeatureChannels * doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor/kernelHeight * doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolutionDescriptor/kernelWidth. The layout of the filter weights is arranged so that it can be reinterpreted as a 4D tensor (array) weight[outputFeatureChannels][kernelHeight][kernelWidth][inputChannels/groups]. Weights are converted to half float precision (fp16) internally for best performance.
- `biasTerms`: A pointer to bias terms to be applied to the convolution output. Each entry is a float value. The number of entries is the number of output feature maps.
- `flags`: Currently unused. This value must be doc://com.apple.metalperformanceshaders/documentation/MetalPerformanceShaders/MPSCNNConvolutionFlags/none.

## Return Value

Return Value A valid MPSCNNFullyConnected object or nil, if failure.

## Discussion

Discussion note: The encode methods in the MPSCNNKernel class can be used to encode an MPSCNNFullyConnected object to a MTLCommandBuffer object.

## See Also

### Initializers

- [init(coder:device:)](metalperformanceshaders/mpscnnfullyconnected/init(coder:device:).md)
- [init(device:weights:)](metalperformanceshaders/mpscnnfullyconnected/init(device:weights:).md)
- [MPSCNNConvolutionDataSource](metalperformanceshaders/mpscnnconvolutiondatasource.md)
- [MPSCNNConvolutionDescriptor](metalperformanceshaders/mpscnnconvolutiondescriptor.md)
- [MPSCNNConvolutionFlags](metalperformanceshaders/mpscnnconvolutionflags.md)
