Submodule containing the ONNX import procedures.
This submodule contains the routines that parse the JSON ONNX representation and rebuild ATHENA networks from it.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | private, | parameter | :: | MAX_GNN_METADATA | = | 100 | |
| integer, | private, | parameter | :: | MAX_ITEMS | = | 500 |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | data_type | = | 1 |
ONNX dataType enum value |
|
| integer, | public, | allocatable | :: | dims(:) |
Parsed tensor dimensions |
||
| logical, | public | :: | in_dims_array | = | .false. |
Whether parser is currently inside a multiline dims array |
|
| logical, | public | :: | in_object | = | .false. |
Whether parser is currently inside an initialiser object |
|
| character(len=128), | public | :: | name | = | '' |
Initialiser tensor name |
|
| character(len=:), | public, | allocatable | :: | raw_data |
Base64 payload from rawData field |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=16), | public | :: | active_string_array | = | '' |
Currently active multiline string array: input or output |
|
| integer, | public | :: | attribute_bracket_depth | = | 0 |
Current square-bracket nesting depth inside a multiline attribute block |
|
| type(onnx_attribute_type), | public, | allocatable | :: | attrs(:) |
Temporary parsed node attributes |
||
| logical, | public | :: | in_attribute | = | .false. |
Whether parser is currently inside an attribute array |
|
| logical, | public | :: | in_object | = | .false. |
Whether parser is currently inside a node object |
|
| character(len=128), | public, | allocatable | :: | inputs(:) |
Temporary node input names |
||
| character(len=256), | public | :: | name | = | '' |
Node name parsed from JSON |
|
| integer, | public | :: | num_attrs | = | 0 |
Number of valid attribute entries |
|
| integer, | public | :: | num_inputs | = | 0 |
Number of valid input names |
|
| integer, | public | :: | num_outputs | = | 0 |
Number of valid output names |
|
| character(len=256), | public | :: | op_type | = | '' |
Node opType parsed from JSON |
|
| character(len=128), | public, | allocatable | :: | outputs(:) |
Temporary node output names |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(onnx_initialiser_type), | public | :: | inits(MAX_ITEMS) |
Parsed ONNX initialisers |
|||
| type(onnx_tensor_type), | public | :: | inputs(MAX_ITEMS) |
Parsed graph input tensors |
|||
| character(len=256), | public | :: | meta_keys(MAX_GNN_METADATA) |
Metadata keys read from metadataProps |
|||
| character(len=256), | public | :: | meta_values(MAX_GNN_METADATA) |
Metadata values read from metadataProps |
|||
| type(onnx_node_type), | public | :: | nodes(MAX_ITEMS) |
Parsed ONNX nodes |
|||
| integer, | public | :: | num_inits | = | 0 |
Number of valid entries in inits |
|
| integer, | public | :: | num_inputs | = | 0 |
Number of valid entries in inputs |
|
| integer, | public | :: | num_meta | = | 0 |
Number of valid metadata key/value pairs |
|
| integer, | public | :: | num_nodes | = | 0 |
Number of valid entries in nodes |
|
| integer, | public | :: | num_outputs | = | 0 |
Number of valid entries in outputs |
|
| type(onnx_tensor_type), | public | :: | outputs(MAX_ITEMS) |
Parsed graph output tensors |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(json_initialiser_state_type), | public | :: | initialiser |
Reusable initialiser parser state |
|||
| type(json_tensor_state_type), | public | :: | input_tensor |
Reusable input tensor parser state |
|||
| type(json_node_state_type), | public | :: | node |
Reusable node parser state |
|||
| type(json_tensor_state_type), | public | :: | output_tensor |
Reusable output tensor parser state |
|||
| character(len=32), | public | :: | section | = | '' |
Active top-level section name |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public, | allocatable | :: | dim_values(:) |
Parsed tensor dimensions (-1 for dimParam) |
||
| integer, | public | :: | elem_type | = | 1 |
ONNX element type enum value |
|
| logical, | public | :: | in_object | = | .false. |
Whether parser is currently inside a tensor object |
|
| character(len=128), | public | :: | name | = | '' |
Tensor name |
|
| integer, | public | :: | object_depth | = | 0 |
Nested JSON object depth within this tensor block |
Extract the layerN prefix from an expanded-ONNX node name.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | node_name |
Node name such as /layer1/MatMul |
Extracted layer prefix without leading slash
Return node index for activation attached to node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid nodes and target layer id |
||
| integer, | intent(in) | :: | layer_id |
Number of valid nodes and target layer id |
Index of the found activation node
Return metadata index for a given layer id, or 0 if absent.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=256), | intent(in) | :: | meta_keys(:) |
Metadata keys list |
||
| integer, | intent(in) | :: | num_meta |
Number of metadata entries and target layer id |
||
| integer, | intent(in) | :: | layer_id |
Number of metadata entries and target layer id |
Index of the found metadata entry, or 0 if not found
Return node index for primary node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid nodes and target layer id |
||
| integer, | intent(in) | :: | layer_id |
Number of valid nodes and target layer id |
Index of the found primary node, or 0 if not found
Return true for ONNX activation nodes emitted by ATHENA export.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | op_type |
ONNX operation type string |
Whether op_type matches an activation emitted by ATHENA export
Return true for section object lines like {.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line to classify |
Whether this line is the start of a JSON object
Return true when the parsed ONNX graph contains expanded-ONNX GNN patterns that ATHENA can collapse back into native message passing layers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid node entries |
Whether the graph contains recognizable expanded-ONNX GNN patterns
Return true when the parsed ONNX graph is a supported expanded-ONNX NOP decomposition that ATHENA can collapse back into native NOP layers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid node entries |
Whether the graph matches expanded-ONNX NOP patterns
Create one GNN or NOP layer from metadata and append it to the network.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network receiving the created layer |
||
| character(len=*), | intent(in) | :: | meta_key |
Metadata key/value pair describing one layer |
||
| character(len=*), | intent(in) | :: | meta_value |
Metadata key/value pair describing one layer |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Number of initialisers and effective verbosity level |
||
| integer, | intent(in) | :: | verbose_ |
Number of initialisers and effective verbosity level |
Create standard (non-GNN) layers for a given layer_id using the registered ONNX creator framework (list_of_onnx_layer_creators).
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network receiving the created layer(s) |
||
| integer, | intent(in) | :: | layer_id |
Layer id, primary node index, node count and initialiser count |
||
| integer, | intent(in) | :: | node_index |
Layer id, primary node index, node count and initialiser count |
||
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Layer id, primary node index, node count and initialiser count |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Layer id, primary node index, node count and initialiser count |
||
| integer, | intent(in) | :: | verbose_ |
Effective verbosity level |
Append one integer value stored as a quoted JSON string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line inside a multiline integer array |
||
| integer, | intent(inout), | allocatable | :: | values(:) |
Mutable integer array buffer updated in-place |
Append one string element from a multiline JSON string array.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line inside a multiline string array |
||
| character(len=*), | intent(in) | :: | active_array |
Array currently being accumulated: input or output |
||
| character(len=128), | intent(inout) | :: | inputs(:) |
Mutable node input/output buffers |
||
| integer, | intent(inout) | :: | num_inputs |
Counts of valid input/output entries |
||
| character(len=128), | intent(inout) | :: | outputs(:) |
Mutable node input/output buffers |
||
| integer, | intent(inout) | :: | num_outputs |
Counts of valid input/output entries |
Append a layer id parsed from athena_gnn_node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | meta_key |
Metadata key potentially containing a layer id |
||
| integer, | intent(inout), | allocatable | :: | ids(:) |
Unique set of discovered layer ids |
Append a /layerN prefix to a list if it is not already present.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | prefix |
Prefix to append |
||
| character(len=32), | intent(inout), | allocatable | :: | prefixes(:) |
Prefix list updated in-place |
Append a layer id parsed from a primary node name node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | node_name |
Node name potentially containing a primary layer id |
||
| integer, | intent(inout), | allocatable | :: | ids(:) |
Unique set of discovered layer ids |
Build a network containing GNN layers from parsed JSON data.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network to populate from parsed ONNX content |
||
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid entries in nodes |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Number of valid entries in inits |
||
| type(onnx_tensor_type), | intent(in) | :: | inputs(:) |
Parsed graph input tensors |
||
| integer, | intent(in) | :: | num_inputs |
Number of valid entries in inputs |
||
| type(onnx_tensor_type), | intent(in) | :: | outputs(:) |
Parsed graph output tensors |
||
| integer, | intent(in) | :: | num_outputs |
Number of valid entries in outputs |
||
| character(len=256), | intent(in) | :: | meta_keys(:) |
Metadata keys and values from metadataProps |
||
| character(len=256), | intent(in) | :: | meta_values(:) |
Metadata keys and values from metadataProps |
||
| integer, | intent(in) | :: | num_meta |
Number of valid metadata entries |
||
| integer, | intent(in) | :: | verbose_ |
Effective verbosity level |
Reconstruct ATHENA GNN layers from an expanded-ONNX graph when metadata is absent.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network receiving the reconstructed layers |
||
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid node entries |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Number of valid initialiser entries |
||
| type(onnx_tensor_type), | intent(in) | :: | inputs(:) |
Parsed ONNX graph input tensors |
||
| integer, | intent(in) | :: | num_inputs |
Number of valid graph input entries |
||
| integer, | intent(in) | :: | verbose_ |
Effective verbosity level |
Reconstruct ATHENA NOP layers from an expanded-ONNX decomposed graph.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network receiving the reconstructed layers |
||
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid node entries |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Number of valid initialiser entries |
||
| integer, | intent(in) | :: | verbose_ |
Effective verbosity level |
Build a standard, non-GNN network from parsed JSON data.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(network_type), | intent(inout) | :: | network |
Network to populate from parsed ONNX content |
||
| type(onnx_node_type), | intent(in) | :: | nodes(:) |
Parsed ONNX nodes |
||
| integer, | intent(in) | :: | num_nodes |
Number of valid entries in nodes |
||
| type(onnx_initialiser_type), | intent(in) | :: | inits(:) |
Parsed ONNX initialisers |
||
| integer, | intent(in) | :: | num_inits |
Number of valid entries in inits |
||
| type(onnx_tensor_type), | intent(in) | :: | inputs(:) |
Parsed graph input tensors |
||
| integer, | intent(in) | :: | num_inputs |
Number of valid entries in inputs |
||
| integer, | intent(in) | :: | verbose_ |
Effective verbosity level |
Detect the active top-level graph section.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current trimmed JSON line |
||
| type(json_parser_state_type), | intent(inout) | :: | parser |
Parser state with mutable active section |
Extract the subtype=... token from one metadata value string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | meta_value |
Metadata payload string |
||
| character(len=*), | intent(out) | :: | gnn_subtype |
Extracted subtype token |
Extract an integer value from a JSON key-value pair.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line and key token to find |
||
| character(len=*), | intent(in) | :: | key |
Source line and key token to find |
||
| integer, | intent(out) | :: | value |
Extracted integer value |
Extract a string value from a JSON key-value pair.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line and key token to find |
||
| character(len=*), | intent(in) | :: | key |
Source line and key token to find |
||
| character(len=*), | intent(out) | :: | value |
Extracted string value |
Initialise the reusable parser state objects.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_parser_state_type), | intent(out) | :: | parser |
Parser state container to initialise |
Parse layer id from node_X or node_X_* names.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | node_name |
Candidate ONNX node name |
||
| integer, | intent(out) | :: | layer_id |
Parsed layer id when present |
||
| integer, | intent(out) | :: | found |
Positive when parsing succeeded, zero otherwise |
Parse one line from the initialiser section.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line to parse |
||
| type(json_initialiser_state_type), | intent(inout) | :: | state |
Mutable parser state for the active initialiser object |
||
| type(json_parse_result_type), | intent(inout) | :: | parsed |
Parsed ONNX content accumulated so far |
||
| character(len=32), | intent(inout) | :: | section |
Current top-level JSON section name |
Parse one or more JSON attribute objects from a line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line containing one or more JSON attribute objects |
||
| type(onnx_attribute_type), | intent(inout), | allocatable | :: | attrs(:) |
Destination list of parsed attributes |
|
| integer, | intent(inout) | :: | n_attrs |
Number of valid attributes in attrs |
Parse a JSON array of string-encoded integers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line containing a JSON array |
||
| integer, | intent(inout), | allocatable | :: | values(:) |
Parsed integer values |
Parse a JSON string array from one line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line and array key token |
||
| character(len=*), | intent(in) | :: | key |
Source line and array key token |
||
| character(len=128), | intent(inout) | :: | values(:) |
Destination array for parsed values |
||
| integer, | intent(inout) | :: | n |
Number of valid parsed values |
Parse athena_gnn_node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | meta_key |
Metadata key potentially containing a layer id |
||
| integer, | intent(out) | :: | layer_id |
Parsed layer id value |
||
| logical, | intent(out) | :: | found |
Whether parsing succeeded |
Parse one metadataProps line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current metadata JSON line |
||
| type(json_parse_result_type), | intent(inout) | :: | parsed |
Parsed ONNX content accumulated so far |
||
| character(len=32), | intent(inout) | :: | section |
Current top-level JSON section name |
Parse one line from the node section.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line to parse |
||
| type(json_node_state_type), | intent(inout) | :: | state |
Mutable node parser state |
||
| type(json_parse_result_type), | intent(inout) | :: | parsed |
Parsed ONNX content accumulated so far |
||
| character(len=32), | intent(inout) | :: | section |
Current top-level JSON section name |
Parse node_
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | node_name |
Candidate ONNX node name |
||
| integer, | intent(out) | :: | layer_id |
Parsed layer id when present |
||
| logical, | intent(out) | :: | is_primary |
Whether node_name matches primary pattern node_ |
Parse a single JSON attribute object.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line for one JSON attribute object |
||
| type(onnx_attribute_type), | intent(inout), | allocatable | :: | attrs(:) |
Destination list of parsed attributes |
|
| integer, | intent(inout) | :: | n_attrs |
Number of valid attributes in attrs |
Parse one line from the input or output tensor section.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line to parse |
||
| type(json_tensor_state_type), | intent(inout) | :: | state |
Mutable tensor parser state |
||
| type(onnx_tensor_type), | intent(inout) | :: | tensors(:) |
Parsed tensor destination array |
||
| integer, | intent(inout) | :: | num_tensors |
Number of valid tensor entries in tensors |
||
| character(len=32), | intent(inout) | :: | section |
Current top-level JSON section name |
Reset the reusable initialiser parser state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_initialiser_state_type), | intent(inout) | :: | state |
Initialiser parser state to reset |
Reset the reusable node parser state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_node_state_type), | intent(inout) | :: | state |
Node parser state to reset |
Reset the reusable tensor parser state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_tensor_state_type), | intent(inout) | :: | state |
Tensor parser state to reset |
Sort an integer array in ascending order.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(inout), | allocatable | :: | values(:) |
Integer array sorted in ascending order in-place |
Copy the current initialiser state into the parsed result collection.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_initialiser_state_type), | intent(in) | :: | state |
Completed initialiser parse state to copy into the result object |
||
| type(json_parse_result_type), | intent(inout) | :: | parsed |
Parsed ONNX content accumulated so far |
Copy the current node state into the parsed result collection.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_node_state_type), | intent(in) | :: | state |
Completed node parser state |
||
| type(json_parse_result_type), | intent(inout) | :: | parsed |
Parsed ONNX content accumulated so far |
Copy the current tensor state into the parsed result collection.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(json_tensor_state_type), | intent(in) | :: | state |
Completed tensor parser state |
||
| type(onnx_tensor_type), | intent(inout) | :: | tensors(:) |
Parsed tensor destination array |
||
| integer, | intent(inout) | :: | num_tensors |
Number of valid tensor entries in tensors |
Update square-bracket nesting depth for multiline JSON arrays.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line inside a multiline array |
||
| integer, | intent(inout) | :: | depth |
Mutable array nesting depth |
Update a nested object depth counter from one JSON line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Current JSON line |
||
| integer, | intent(inout) | :: | object_depth |
Mutable object depth counter |
Import a network from ONNX JSON format.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | file |
File to import the network from |
||
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Resulting network instance