emit_nop_output_tail Subroutine

public subroutine emit_nop_output_tail(prefix, activation_name, is_last_layer, input_name, nodes, num_nodes, final_output)

Uses

    • coreutils

Emit the common transpose and optional activation at the end of a NOP.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: prefix
character(len=*), intent(in) :: activation_name
logical, intent(in) :: is_last_layer
character(len=*), intent(in) :: input_name
type(onnx_node_type), intent(inout) :: nodes(:)
integer, intent(inout) :: num_nodes
character(len=128), intent(out) :: final_output

Source Code

  subroutine emit_nop_output_tail(prefix, activation_name, is_last_layer, &
       input_name, nodes, num_nodes, final_output)
    !! Emit the common transpose and optional activation at the end of a NOP.
    use coreutils, only: to_camel_case
    implicit none

    character(*), intent(in) :: prefix, activation_name, input_name
    logical, intent(in) :: is_last_layer
    type(onnx_node_type), intent(inout) :: nodes(:)
    integer, intent(inout) :: num_nodes
    character(128), intent(out) :: final_output

    character(4096) :: perm_attr
    character(128) :: transpose_output
    character(128) :: activation_op, activation_node
    character(4096) :: activation_attr

    perm_attr = '        "attribute": [{"name": "perm", "ints": ' // &
         '["1", "0"], "type": "INTS"}]'

    if(is_last_layer .and. trim(activation_name) .eq. 'none')then
       transpose_output = 'output'
    else
       write(transpose_output, '("/",A,"/Transpose_1_output_0")') &
            trim(prefix)
    end if

    call emit_node('Transpose', '/' // trim(prefix) // '/Transpose_1', &
         trim(transpose_output), trim(perm_attr), nodes, num_nodes, &
         in1=trim(input_name))

    if(trim(activation_name) .ne. 'none')then
       activation_op = to_camel_case( &
            trim(adjustl(activation_name)), &
            capitalise_first_letter = .true.)
       activation_attr = ''
       if(trim(activation_name) .eq. 'leaky_relu')then
          activation_op = 'LeakyRelu'
          activation_attr = '        "attribute": [{"name": "alpha", ' // &
               '"f": 0.01, "type": "FLOAT"}]'
       end if
       if(is_last_layer)then
          final_output = 'output'
       else
          write(final_output, '("/",A,"/",A,"_output_0")') &
               trim(prefix), trim(activation_op)
       end if
       activation_node = '/' // trim(prefix) // '/' // trim(activation_op)
       call emit_node(trim(activation_op), trim(activation_node), &
            trim(final_output), trim(activation_attr), nodes, num_nodes, &
            in1=trim(transpose_output))
    else
       final_output = transpose_output
    end if

  end subroutine emit_nop_output_tail