openfpga/src/fabric/build_top_module_memory.cpp
/********************************************************************
 * Split memory modules into different configurable regions
 * This function will create regions based on the definition
 * in the configuration protocols, to accommodate each configurable
 * child under the top-level module
 *
 * For example:
 *  FPGA Top-level module
 *  +----------------------+
 *  |           |          |
 *  |  Region 0 | Region 1 |
 *  |           |          |
 *  +----------------------+
 *  |           |          |
 *  |  Region 2 | Region 3 |
 *  |           |          |
 *  +----------------------+
 *
 *  A typical organization of a Region X
 *  +-----------------------+
 *  |                       |
 *  | +------+ +------+     |
 *  | |      | |      |     |
 *  | | Tile | | Tile | ... |
 *  | |      | |      |     |
 *  | +------+ +------+     |
 *  |  ...      ...         |
 *  |                       |
 *  | +------+ +------+     |
 *  | |      | |      |     |
 *  | | Tile | | Tile | ... |
 *  | |      | |      |     |
 *  | +------+ +------+     |
 *  +-----------------------+
 *
 * Note:
 *   - This function should NOT modify configurable children
 *
 *******************************************************************/
Split memory modules into different configurable regions
This function will create regions based on the definition
in the configuration protocols, to accommodate each configurable
child under the top-level module





- This function should NOT modify configurable children
Split memory modules into different configurable regions This function will create regions based on the definition in the configuration protocols to accommodate each configurable child under the top - level module - This function should NOT modify configurable children
static  
void build_top_module_configurable_regions(ModuleManager& module_manager,
                                           const ModuleId& top_module,
                                           const ConfigProtocol& config_protocol) {
  vtr::ScopedStartFinishTimer timer("Build configurable regions for the top module");
  VTR_ASSERT(false == module_manager.configurable_children(top_module).empty());
  VTR_ASSERT(1 <= config_protocol.num_regions());
  size_t num_configurable_children = module_manager.configurable_children(top_module).size();
  if (CONFIG_MEM_MEMORY_BANK == config_protocol.type()) {
    num_configurable_children -= 2;
  } else if (CONFIG_MEM_FRAME_BASED == config_protocol.type()) {
    num_configurable_children -= 1;
  }
  size_t num_children_per_region = num_configurable_children / config_protocol.num_regions(); 
  size_t region_child_counter = 0;
  bool create_region = true;
  ConfigRegionId curr_region = ConfigRegionId::INVALID();
  for (size_t ichild = 0; ichild < module_manager.configurable_children(top_module).size(); ++ichild) {
    if (true == create_region) {
      curr_region = module_manager.add_config_region(top_module);
    }
    module_manager.add_configurable_child_to_region(top_module,
                                                    curr_region,
                                                    module_manager.configurable_children(top_module)[ichild],
                                                    module_manager.configurable_child_instances(top_module)[ichild],
                                                    ichild);
    region_child_counter++;
    if (region_child_counter < num_children_per_region) {
      create_region = false;
    } else if (size_t(curr_region) < (size_t)config_protocol.num_regions() - 1) {
      create_region = true;
      region_child_counter = 0;
    }
  }
  VTR_ASSERT((size_t)config_protocol.num_regions() == module_manager.regions(top_module).size());
}
static void build_top_module_configurable_regions ( ModuleManager & module_manager , const ModuleId & top_module , const ConfigProtocol & config_protocol ) { vtr :: ScopedStartFinishTimer timer ( " " ) ; VTR_ASSERT ( false == module_manager . configurable_children ( top_module ) . empty ( ) ) ; VTR_ASSERT ( 1 <= config_protocol . num_regions ( ) ) ; size_t num_configurable_children = module_manager . configurable_children ( top_module ) . size ( ) ; if ( CONFIG_MEM_MEMORY_BANK == config_protocol . type ( ) ) { num_configurable_children -= 2 ; } else if ( CONFIG_MEM_FRAME_BASED == config_protocol . type ( ) ) { num_configurable_children -= 1 ; } size_t num_children_per_region = num_configurable_children / config_protocol . num_regions ( ) ; size_t region_child_counter = 0 ; bool create_region = true ; ConfigRegionId curr_region = ConfigRegionId :: INVALID ( ) ; for ( size_t ichild = 0 ; ichild < module_manager . configurable_children ( top_module ) . size ( ) ; ++ ichild ) { if ( true == create_region ) { curr_region = module_manager . add_config_region ( top_module ) ; } module_manager . add_configurable_child_to_region ( top_module , curr_region , module_manager . configurable_children ( top_module ) [ ichild ] , module_manager . configurable_child_instances ( top_module ) [ ichild ] , ichild ) ; region_child_counter ++ ; if ( region_child_counter < num_children_per_region ) { create_region = false ; } else if ( size_t ( curr_region ) < ( size_t ) config_protocol . num_regions ( ) - 1 ) { create_region = true ; region_child_counter = 0 ; } } VTR_ASSERT ( ( size_t ) config_protocol . num_regions ( ) == module_manager . regions ( top_module ) . size ( ) ) ; }
Split memory modules into different configurable regions
 This function will create regions based on the definition
 in the configuration protocols, to accommodate each configurable
 child under the top-level module
Split memory modules into different configurable regions This function will create regions based on the definition in the configuration protocols to accommodate each configurable child under the top - level module
/* Ensure we have valid configurable children */ /* Ensure that our region definition is valid */ /* Exclude decoders from the list */ /* Evenly place each configurable child to each region */ /* Add the child to a region */ /* See if the current region is full or not:
     * For the last region, we will keep adding until we finish all the children 
     */ /* Ensure that the number of configurable regions created matches the definition */