is_onnx_expanded_nop_graph Function

function is_onnx_expanded_nop_graph(nodes, num_nodes) result(output)

Return true when the parsed ONNX graph is a supported expanded-ONNX NOP decomposition that ATHENA can collapse back into native NOP layers.

Arguments

Type IntentOptional Attributes Name
type(onnx_node_type), intent(in) :: nodes(:)

Parsed ONNX nodes

integer, intent(in) :: num_nodes

Number of valid node entries

Return Value logical

Whether the graph matches expanded-ONNX NOP patterns


Source Code

  function is_onnx_expanded_nop_graph(nodes, num_nodes) result(output)
    !! Return true when the parsed ONNX graph is a supported expanded-ONNX NOP
    !! decomposition that ATHENA can collapse back into native NOP layers.
    use athena__container_layer, only: &
         list_of_onnx_expanded_nop_layer_creators, &
         allocate_list_of_onnx_expanded_nop_layer_creators
    implicit none

    ! Arguments
    type(onnx_node_type), intent(in) :: nodes(:)
    !! Parsed ONNX nodes
    integer, intent(in) :: num_nodes
    !! Number of valid node entries

    logical :: output
    !! Whether the graph matches expanded-ONNX NOP patterns

    ! Local variables
    character(32), allocatable :: layer_prefixes(:)
    !! Unique /layerN prefixes discovered in encounter order
    character(32) :: prefix
    !! Prefix extracted from the current node name
    integer :: i, j
    !! Loop indices
    logical :: recognised
    !! Whether at least one registered creator recognises the prefix

    if(.not.allocated(list_of_onnx_expanded_nop_layer_creators))then
       call allocate_list_of_onnx_expanded_nop_layer_creators()
    end if

    allocate(layer_prefixes(0))

    do i = 1, num_nodes
       prefix = extract_onnx_expanded_layer_prefix(nodes(i)%name)
       if(len_trim(prefix) .eq. 0)then
          output = .false.
          return
       end if
       call append_unique_onnx_expanded_prefix(prefix, layer_prefixes)
    end do

    if(size(layer_prefixes) .eq. 0)then
       output = .false.
       return
    end if

    do i = 1, size(layer_prefixes)
       recognised = .false.
       do j = 1, size(list_of_onnx_expanded_nop_layer_creators)
          if(list_of_onnx_expanded_nop_layer_creators(j)%classify_ptr( &
               layer_prefixes(i), nodes, num_nodes))then
             recognised = .true.
             exit
          end if
       end do
       if(.not.recognised)then
          output = .false.
          return
       end if
    end do

    output = .true.

  end function is_onnx_expanded_nop_graph