Q.ANT Native Computing Toolkit 2.3.1
All you need for photonic computing
Loading...
Searching...
No Matches
qant_native_computing_toolkit_ai.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <dlpack/dlpack.h>
Include dependency graph for qant_native_computing_toolkit_ai.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

DLManagedTensorVersioned * add_bias_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *bias)
 Element-wise addition. Supports batched input.
DLManagedTensorVersioned * add_bias_for_conv2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *bias)
 Element-wise addition. Specifically used for conv2d.
DLManagedTensorVersioned * relu_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features)
 Performs a forward pass through a ReLU layer.
DLManagedTensorVersioned * sigmoid_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features)
 Performs a forward pass through a Sigmoid layer.
DLManagedTensorVersioned * softmax_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features)
 Performs a forward pass through a Softmax layer.
DLManagedTensorVersioned * conv_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *kernels, size_t const padding, size_t const stride, size_t const dilation)
 Performs a forward pass through a convolution layer.
DLManagedTensorVersioned * conv_transpose_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *kernels, size_t const padding, size_t const stride, size_t const dilation, size_t const output_padding)
 Performs a forward pass through a transposed convolution layer.
DLManagedTensorVersioned * batchnorm2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *means, DLManagedTensorVersioned const *variances, DLManagedTensorVersioned const *weights, DLManagedTensorVersioned const *bias, float const eps)
 Performs a forward pass through a batchnorm2d layer.
DLManagedTensorVersioned * maxpool2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, size_t const kernel_height, size_t const kernel_width, size_t const padding, size_t const stride)
 Performs a forward pass through a maxpooling2d layer.
DLManagedTensorVersioned * avgpool2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, size_t const kernel_height, size_t const kernel_width, size_t const padding, size_t const stride, bool const count_include_pad)
 Performs a forward pass through a avgpooling2d layer.
DLManagedTensorVersioned * adaptive_maxpool2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, size_t const output_height, size_t const output_width)
 Performs a forward pass through an adaptive maxpooling2d layer.
DLManagedTensorVersioned * adaptive_avgpool2d_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, size_t const output_height, size_t const output_width)
 Performs a forward pass through an adaptive avgpooling2d layer.
DLManagedTensorVersioned * calc_kan_layer_fprop (const uint32_t npu_id, DLManagedTensorVersioned const *features, DLManagedTensorVersioned const *phis, DLManagedTensorVersioned const *ampls, DLManagedTensorVersioned const *ks)
 Calculates a Q.ANT version of a KAN layer (https://arxiv.org/abs/2404.19756) based on scaled_periodic_nl.

Function Documentation

◆ adaptive_avgpool2d_fprop()

DLManagedTensorVersioned * adaptive_avgpool2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
size_t const output_height,
size_t const output_width )

Performs a forward pass through an adaptive avgpooling2d layer.

Only works for symmetric input and output sizes. Input size has to be integer multiple of output size.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
output_heightHeight of the output.
output_widthWidth of the output.
Returns
A 4D tensor with shape (n_batches, n_channels, output_height, output_width)

◆ adaptive_maxpool2d_fprop()

DLManagedTensorVersioned * adaptive_maxpool2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
size_t const output_height,
size_t const output_width )

Performs a forward pass through an adaptive maxpooling2d layer.

Only works for symmetric input and output sizes. Input size has to be integer multiple of output size.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
output_heightHeight of the output.
output_widthWidth of the output.
Returns
A 4D tensor with shape (n_batches, n_channels, output_height, output_width)

◆ add_bias_for_conv2d_fprop()

DLManagedTensorVersioned * add_bias_for_conv2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * bias )

Element-wise addition. Specifically used for conv2d.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
biasA 1D tensor with data type bfloat16 and shape (n_channels)
Returns
A 4D tensor containing the result of the addition, same shape as the input features.

◆ add_bias_fprop()

DLManagedTensorVersioned * add_bias_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * bias )

Element-wise addition. Supports batched input.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 2D tensor with data type bfloat16 and shape (n_batches, n_channels).
biasA 1D tensor with data type bfloat16 and shape (n_channels)
Returns
A 2D tensor, same shape as inputs.

◆ avgpool2d_fprop()

DLManagedTensorVersioned * avgpool2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
size_t const kernel_height,
size_t const kernel_width,
size_t const padding,
size_t const stride,
bool const count_include_pad )

Performs a forward pass through a avgpooling2d layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Pooling_layer

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
kernel_heightHeight of the pooling kernel.
kernel_widthWidth of the pooling kernel.
paddingAmount of padding added to the input features.
strideStep size for moving the filter window over the input features.
count_include_padWhen True, will include the zero-padding in the averaging calculation.
Returns
A 4D tensor with shape (n_batches, n_channels, height, width)

◆ batchnorm2d_fprop()

DLManagedTensorVersioned * batchnorm2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * means,
DLManagedTensorVersioned const * variances,
DLManagedTensorVersioned const * weights,
DLManagedTensorVersioned const * bias,
float const eps )

Performs a forward pass through a batchnorm2d layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Batch_normalization

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
meansA 1D tensor containing the mean values for each feature, with data type bfloat16 and length n_channels
variancesA 1D tensor containing the variance values for each feature, with data type bfloat16 and length n_channels
weightsA 1D tensor containing the parameter for each feature, with data type bfloat16 and length n_channels
biasA 1D tensor containing the bias value for each feature, with data type bfloat16 and length n_channels
epsA small value added to the variance for numerical stability.
Returns
A 4D tensor containing the result of the batchnorm operation with shape (n_batches, n_channels, height, width)

◆ calc_kan_layer_fprop()

DLManagedTensorVersioned * calc_kan_layer_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * phis,
DLManagedTensorVersioned const * ampls,
DLManagedTensorVersioned const * ks )

Calculates a Q.ANT version of a KAN layer (https://arxiv.org/abs/2404.19756) based on scaled_periodic_nl.

The mathematical function is

\‍[    y_j = \sum_{i,l} \mathrm{tcos}\!\left(ks_l x_i + \phi_{jil}\right) ampls_{jil},
\‍]

where $x_i$ is the input (vector), $ks_l$ is the frequency components, $\phi_{jil}$ the phase offsets (tensor) and $ampls_{jil}$ the amplitude (tensor) and $y_j$ output (vector). $\mathrm{tcos}$ denotes the cosine-related shape of the periodic optical nonlinearity.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 2D input tensor with shape (n_batches, n_channels_in), with data type bfloat16.
phisA 3D tensor of phase offsets, shape (n_channels_out, n_channels_in, n_ks), with data type bfloat16.
amplsA 3D array of amplitudes, same shape as phis, with data type bfloat16.
ksA 1D tensor of frequency components, shape (n_ks), with data type bfloat16.
Returns
The result of the KAN layer with shape (n_batches, n_channels_out), with data type bfloat16.

◆ conv_fprop()

DLManagedTensorVersioned * conv_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * kernels,
size_t const padding,
size_t const stride,
size_t const dilation )

Performs a forward pass through a convolution layer.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels_in, height, width)
kernelsA 4D tensor with data type bfloat16 and shape (n_channels_out, n_channels_in, height, width)
paddingAmount of padding added to the input features.
strideStep size for moving the filter window over the input features.
dilationDilation ("zoom out") of the filter window.
Returns
A 4D tensor containing the result of the convolution with shape (n_batches, n_channels_out, height, width)

◆ conv_transpose_fprop()

DLManagedTensorVersioned * conv_transpose_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
DLManagedTensorVersioned const * kernels,
size_t const padding,
size_t const stride,
size_t const dilation,
size_t const output_padding )

Performs a forward pass through a transposed convolution layer.

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels_in, height, width)
kernelsA 4D tensor with data type bfloat16 and shape (n_channels_in, n_channels_out, height, width)
paddingAmount of padding added to the input features.
strideStep size for moving the filter window over the input features.
dilationDilation ("zoom out") of the filter window.
output_paddingPadding for the returned features.
Returns
A 4D tensor containing the result of the transpose convolution with shape (n_batches, n_channels_out, height, width)

◆ maxpool2d_fprop()

DLManagedTensorVersioned * maxpool2d_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features,
size_t const kernel_height,
size_t const kernel_width,
size_t const padding,
size_t const stride )

Performs a forward pass through a maxpooling2d layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Pooling_layer

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 4D tensor with data type bfloat16 and shape (n_batches, n_channels, height, width)
kernel_heightHeight of the pooling kernel.
kernel_widthWidth of the pooling kernel.
paddingAmount of padding added to the input features.
strideStep size for moving the filter window over the input features.
Returns
A 4D tensor containing the result of the maxpool operation with shape ([batches], n_channels, output_height, output_width).

◆ relu_fprop()

DLManagedTensorVersioned * relu_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features )

Performs a forward pass through a ReLU layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Rectifier_(neural_networks)

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 1D tensor with data type bfloat16.
Returns
A 1D array containing the result of the ReLU operation.

◆ sigmoid_fprop()

DLManagedTensorVersioned * sigmoid_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features )

Performs a forward pass through a Sigmoid layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Sigmoid_function

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 1D tensor with data type bfloat16.
Returns
A 1D array containing the result of the Sigmoid operation with the same shape as the input.

◆ softmax_fprop()

DLManagedTensorVersioned * softmax_fprop ( const uint32_t npu_id,
DLManagedTensorVersioned const * features )

Performs a forward pass through a Softmax layer.

For a mathematical definition, see https://en.wikipedia.org/wiki/Softmax_function

Parameters
npu_idThe identifier of the NPU on which to perform the operation.
featuresA 2D tensor with data type bfloat16 and shape (1, N).
Returns
A 2D tensor, containing the result of the Softmax operation with the same shape as the input.