openfpga/src/annotation/check_pb_type_annotation.cpp
/********************************************************************
 * This function will recursively traverse all the primitive pb_types 
 * in the graph to ensure
 *  - If a primitive pb_type has mode bits, it must have been linked to a physical pb_type
 *    and the circuit model must have a port for mode selection. 
 *    And the port size must match the length of mode bits
 *******************************************************************/
This function will recursively traverse all the primitive pb_types
in the graph to ensure
- If a primitive pb_type has mode bits, it must have been linked to a physical pb_type
and the circuit model must have a port for mode selection.
And the port size must match the length of mode bits
This function will recursively traverse all the primitive pb_types in the graph to ensure - If a primitive pb_type has mode bits it must have been linked to a physical pb_type and the circuit model must have a port for mode selection . And the port size must match the length of mode bits
static 
void rec_check_vpr_pb_type_mode_bits_annotation(t_pb_type* cur_pb_type,
                                                const CircuitLibrary& circuit_lib,
                                                const VprDeviceAnnotation& vpr_device_annotation,
                                                size_t& num_err) {
  if (true == is_primitive_pb_type(cur_pb_type)) {
    t_pb_type* physical_pb_type = vpr_device_annotation.physical_pb_type(cur_pb_type);
    if (nullptr == physical_pb_type) {
      VTR_LOG_ERROR("Find a pb_type '%s' which has not been mapped to any physical pb_type!\n",
                    cur_pb_type->name);
      VTR_LOG_ERROR("Please specify in the OpenFPGA architecture\n");
      num_err++;
      return;
    }
    if (vpr_device_annotation.pb_type_mode_bits(cur_pb_type).size() != vpr_device_annotation.pb_type_mode_bits(physical_pb_type).size()) {
      VTR_LOG_ERROR("Found different sizes of mode_bits for pb_type '%s' and its physical pb_type '%s'\n",
                    cur_pb_type->name,
                    physical_pb_type->name);
      num_err++;
      return;
    }
    CircuitModelId circuit_model = vpr_device_annotation.pb_type_circuit_model(physical_pb_type);
    if (CircuitModelId::INVALID() == vpr_device_annotation.pb_type_circuit_model(physical_pb_type)) {
      VTR_LOG_ERROR("Found a physical pb_type '%s' missing circuit model binding!\n",
                    physical_pb_type->name);
      num_err++;
      return; 
    }
    if (0 == vpr_device_annotation.pb_type_mode_bits(cur_pb_type).size()) {
      return;
    }
    std::vector<CircuitPortId> mode_select_ports = find_circuit_mode_select_sram_ports(circuit_lib, circuit_model);
    size_t port_num_mode_bits = 0;
    for (const CircuitPortId& mode_select_port : mode_select_ports) {
      port_num_mode_bits += circuit_lib.port_size(mode_select_port);
    }
    if (port_num_mode_bits != vpr_device_annotation.pb_type_mode_bits(cur_pb_type).size()) {
      VTR_LOG_ERROR("Length of mode bits of pb_type '%s' does not match the size(%ld) of mode selection ports of circuit model '%s'!\n",
                    cur_pb_type->name,
                    port_num_mode_bits,
                    circuit_lib.model_name(circuit_model).c_str());
      num_err++;
    }
    return;
  }
  for (int imode = 0; imode < cur_pb_type->num_modes; ++imode) {
    for (int ichild = 0; ichild < cur_pb_type->modes[imode].num_pb_type_children; ++ichild) { 
      rec_check_vpr_pb_type_mode_bits_annotation(&(cur_pb_type->modes[imode].pb_type_children[ichild]),
                                                 circuit_lib, vpr_device_annotation,
                                                 num_err);
    }
  }
}
static void rec_check_vpr_pb_type_mode_bits_annotation ( t_pb_type * cur_pb_type , const CircuitLibrary & circuit_lib , const VprDeviceAnnotation & vpr_device_annotation , size_t & num_err ) { if ( true == is_primitive_pb_type ( cur_pb_type ) ) { t_pb_type * physical_pb_type = vpr_device_annotation . physical_pb_type ( cur_pb_type ) ; if ( nullptr == physical_pb_type ) { VTR_LOG_ERROR ( " \n " , cur_pb_type -> name ) ; VTR_LOG_ERROR ( " \n " ) ; num_err ++ ; return ; } if ( vpr_device_annotation . pb_type_mode_bits ( cur_pb_type ) . size ( ) != vpr_device_annotation . pb_type_mode_bits ( physical_pb_type ) . size ( ) ) { VTR_LOG_ERROR ( " \n " , cur_pb_type -> name , physical_pb_type -> name ) ; num_err ++ ; return ; } CircuitModelId circuit_model = vpr_device_annotation . pb_type_circuit_model ( physical_pb_type ) ; if ( CircuitModelId :: INVALID ( ) == vpr_device_annotation . pb_type_circuit_model ( physical_pb_type ) ) { VTR_LOG_ERROR ( " \n " , physical_pb_type -> name ) ; num_err ++ ; return ; } if ( 0 == vpr_device_annotation . pb_type_mode_bits ( cur_pb_type ) . size ( ) ) { return ; } std :: vector < CircuitPortId > mode_select_ports = find_circuit_mode_select_sram_ports ( circuit_lib , circuit_model ) ; size_t port_num_mode_bits = 0 ; for ( const CircuitPortId & mode_select_port : mode_select_ports ) { port_num_mode_bits += circuit_lib . port_size ( mode_select_port ) ; } if ( port_num_mode_bits != vpr_device_annotation . pb_type_mode_bits ( cur_pb_type ) . size ( ) ) { VTR_LOG_ERROR ( " \n " , cur_pb_type -> name , port_num_mode_bits , circuit_lib . model_name ( circuit_model ) . c_str ( ) ) ; num_err ++ ; } return ; } for ( int imode = 0 ; imode < cur_pb_type -> num_modes ; ++ imode ) { for ( int ichild = 0 ; ichild < cur_pb_type -> modes [ imode ] . num_pb_type_children ; ++ ichild ) { rec_check_vpr_pb_type_mode_bits_annotation ( & ( cur_pb_type -> modes [ imode ] . pb_type_children [ ichild ] ) , circuit_lib , vpr_device_annotation , num_err ) ; } } }
This function will recursively traverse all the primitive pb_types
 in the graph to ensure
  - If a primitive pb_type has mode bits, it must have been linked to a physical pb_type
    and the circuit model must have a port for mode selection.
This function will recursively traverse all the primitive pb_types in the graph to ensure - If a primitive pb_type has mode bits it must have been linked to a physical pb_type and the circuit model must have a port for mode selection .
/* Primitive pb_type should always been binded to a physical pb_type */ /* Find the physical pb_type
     * If the physical pb_type has mode selection bits, this pb_type must have as well!
     */ /* Try to find a mode selection port for the circuit model linked to the circuit model */ /* Invalid id already, further check is not applicable */ /* No mode bits to be checked! */ /* Search the ports of this circuit model and we must have a mode selection port */ /* Traverse all the modes */