Shared utility routines for ONNX JSON export
Contains base64 encoding, node emission helpers, col→row transpose, and activation/attribute-building utilities used by both the main write_onnx procedure and layer-specific emit_onnx_nodes overrides.
Convert an ONNX activation op_type string to the Athena activation name
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | optype |
Core base64 encoder (allocatable output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int8), | intent(in) | :: | bytes(:) | |||
| integer, | intent(in) | :: | nbytes | |||
| character(len=:), | intent(out), | allocatable | :: | output |
Core base64 encoder (fixed-length output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=int8), | intent(in) | :: | bytes(:) | |||
| integer, | intent(in) | :: | nbytes | |||
| character(len=256), | intent(out) | :: | output |
Build JSON string for layer attributes
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | layer |
Layer supplying ONNX attribute metadata |
||
| character(len=*), | intent(in) | :: | op_type |
ONNX operation type used to handle special cases |
||
| character(len=4096), | intent(out) | :: | attr_json |
Serialized JSON fragment containing the emitted attributes |
Convert flat column-major [m,n] to flat row-major [m,n] Fortran stores arrays column-major; ONNX rawData expects row-major.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | data_in(m*n) | |||
| real(kind=real32), | intent(out) | :: | data_out(m*n) | |||
| integer, | intent(in) | :: | m | |||
| integer, | intent(in) | :: | n |
Decode base64 string to float32 array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | input | |||
| real(kind=real32), | intent(out), | allocatable | :: | values(:) | ||
| integer, | intent(out) | :: | n |
Decode base64 string to integer array (from 8-byte int64 encoding)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | input | |||
| integer, | intent(out), | allocatable | :: | values(:) | ||
| integer, | intent(out) | :: | n |
Emit an activation function node
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Activation name, node prefix, and optional override for the input name |
||
| character(len=*), | intent(in) | :: | prefix |
Activation name, node prefix, and optional override for the input name |
||
| character(len=*), | intent(in) | :: | input_override |
Activation name, node prefix, and optional override for the input name |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
||
| integer, | intent(in) | :: | max_nodes |
Maximum number of nodes available in the accumulator |
Emit a Constant node producing a float32 tensor
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Constant node and output tensor name |
||
| real(kind=real32), | intent(in) | :: | values(:) |
Float32 constant values to embed in the node |
||
| integer, | intent(in) | :: | dims(:) |
Tensor dimensions for the constant value |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
||
| type(onnx_initialiser_type), | intent(inout), | dimension(:) | :: | inits |
Initialiser accumulator array (unused, kept for interface symmetry) |
|
| integer, | intent(inout) | :: | num_inits |
Current number of populated initialisers (unused) |
Emit a Constant node producing an int64 tensor
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Constant node and output tensor name |
||
| integer, | intent(in) | :: | values(:) |
Constant values and tensor dimensions |
||
| integer, | intent(in) | :: | dims(:) |
Constant values and tensor dimensions |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
||
| type(onnx_initialiser_type), | intent(inout), | dimension(:) | :: | inits |
Initialiser accumulator array (unused, kept for interface symmetry) |
|
| integer, | intent(inout) | :: | num_inits |
Current number of populated initialisers (unused) |
Emit a ConstantOfShape node
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Node name, shape tensor input, and output tensor name |
||
| character(len=*), | intent(in) | :: | shape_input |
Node name, shape tensor input, and output tensor name |
||
| real(kind=real32), | intent(in) | :: | value |
Fill value to use for the generated tensor |
||
| character(len=*), | intent(in) | :: | output |
Node name, shape tensor input, and output tensor name |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
||
| type(onnx_initialiser_type), | intent(inout), | dimension(:) | :: | inits |
Initialiser accumulator array (unused, kept for interface symmetry) |
|
| integer, | intent(inout) | :: | num_inits |
Current number of populated initialisers (unused) |
Emit initialisers for a learnable layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(in) | :: | layer |
Learnable layer containing parameter tensors and shape metadata |
||
| character(len=*), | intent(in) | :: | prefix |
Name prefix used to generate exported initialiser names |
||
| type(onnx_initialiser_type), | intent(inout), | dimension(:) | :: | inits |
Initialiser accumulator array |
|
| integer, | intent(inout) | :: | num_inits |
Current number of populated initialisers |
||
| integer, | intent(in) | :: | max_inits |
Maximum number of initialisers available in the accumulator |
Emit a simple ONNX node (individual string interface) Avoids gfortran array constructor issues
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | op_type |
ONNX operation type, node name, output name, and attribute JSON |
||
| character(len=*), | intent(in) | :: | name |
ONNX operation type, node name, output name, and attribute JSON |
||
| character(len=*), | intent(in) | :: | out1 |
ONNX operation type, node name, output name, and attribute JSON |
||
| character(len=*), | intent(in) | :: | attr_json |
ONNX operation type, node name, output name, and attribute JSON |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
||
| character(len=*), | intent(in), | optional | :: | in1 |
Optional input tensor names |
|
| character(len=*), | intent(in), | optional | :: | in2 |
Optional input tensor names |
|
| character(len=*), | intent(in), | optional | :: | in3 |
Optional input tensor names |
Emit a Squeeze node (ONNX opset 13+: axes as input)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | name |
Node name, data input, axes input, and output tensor name |
||
| character(len=*), | intent(in) | :: | input |
Node name, data input, axes input, and output tensor name |
||
| character(len=*), | intent(in) | :: | axes_input |
Node name, data input, axes input, and output tensor name |
||
| character(len=*), | intent(in) | :: | output |
Node name, data input, axes input, and output tensor name |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
Node accumulator array |
|
| integer, | intent(inout) | :: | num_nodes |
Current number of populated nodes |
Encode float32 array as base64 string (fixed-length output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | values(:) | |||
| integer, | intent(in) | :: | n | |||
| character(len=256), | intent(out) | :: | output |
Encode float32 array as base64 string (allocatable output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | values(:) | |||
| integer, | intent(in) | :: | n | |||
| character(len=:), | intent(out), | allocatable | :: | output |
Encode integer array as base64 int64 string (fixed-length output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | values(:) | |||
| character(len=256), | intent(out) | :: | output |
Encode integer array as base64 int64 string (allocatable output)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | values(:) | |||
| integer, | intent(in) | :: | n | |||
| character(len=:), | intent(out), | allocatable | :: | output |
Encode a string as base64
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| character(len=256), | intent(out) | :: | output |
Parse space-separated integers from a string into an allocatable array
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| integer, | intent(out), | allocatable | :: | values(:) |
Convert flat row-major [m,n] to flat column-major [m,n] Inverse of col_to_row_major_2d.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real32), | intent(in) | :: | data_in(m*n) | |||
| real(kind=real32), | intent(out) | :: | data_out(m*n) | |||
| integer, | intent(in) | :: | m | |||
| integer, | intent(in) | :: | n |
Write initialisers array to JSON with base64-encoded rawData
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit |
Output unit receiving the JSON text |
||
| type(onnx_initialiser_type), | intent(in), | dimension(:) | :: | inits |
Initialiser collection to serialise |
|
| integer, | intent(in) | :: | num_inits |
Number of populated initialisers in the collection |
Write nodes array to JSON
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit |
Output unit receiving the JSON text |
||
| type(onnx_node_type), | intent(in), | dimension(:) | :: | nodes |
Node collection to serialise |
|
| integer, | intent(in) | :: | num_nodes |
Number of populated nodes in the collection |
Write input/output tensor specifications to JSON
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit |
Output unit receiving the JSON text |
||
| character(len=*), | intent(in) | :: | section_name |
JSON section name, e.g. input or output |
||
| type(onnx_tensor_type), | intent(in), | dimension(:) | :: | tensors |
Tensor collection to serialise |
|
| integer, | intent(in) | :: | num_tensors |
Number of populated tensors in the collection |
Core base64 decoder
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | input | |||
| integer(kind=int8), | intent(out), | allocatable | :: | bytes(:) | ||
| integer, | intent(out) | :: | nbytes |