From 36179b6cedc612c4b830a198d3c6ac975dff37cf Mon Sep 17 00:00:00 2001 From: tangxifan Date: Fri, 14 Feb 2020 10:00:24 -0700 Subject: [PATCH] start moving top-module builder. Now adapt the utils --- .../src/fabric/build_top_module_utils.cpp | 90 +++++++++++++++++++ openfpga/src/fabric/build_top_module_utils.h | 31 +++++++ 2 files changed, 121 insertions(+) create mode 100644 openfpga/src/fabric/build_top_module_utils.cpp create mode 100644 openfpga/src/fabric/build_top_module_utils.h diff --git a/openfpga/src/fabric/build_top_module_utils.cpp b/openfpga/src/fabric/build_top_module_utils.cpp new file mode 100644 index 000000000..141d2dd54 --- /dev/null +++ b/openfpga/src/fabric/build_top_module_utils.cpp @@ -0,0 +1,90 @@ +/******************************************************************** + * This file include most utilized functions for building the module + * graph for FPGA fabric + *******************************************************************/ +/* Headers from vtrutil library */ +#include "vtr_assert.h" + +/* Headers from vpr library */ +#include "vpr_utils.h" + +#include "openfpga_naming.h" + +/* Module builder headers */ +#include "build_top_module_utils.h" + +/* begin namespace openfpga */ +namespace openfpga { + +/******************************************************************** + * Generate the name for a grid block, by considering + * 1. if it locates on the border with given device size + * 2. its type + * + * This function is mainly used in the top-level module generation + *******************************************************************/ +std::string generate_grid_block_module_name_in_top_module(const std::string& prefix, + const DeviceGrid& grids, + const vtr::Point& grid_coord) { + /* Determine if the grid locates at the border */ + vtr::Point device_size(grids.width(), grids.height()); + e_side border_side = find_grid_border_side(device_size, grid_coord); + + return generate_grid_block_module_name(prefix, + std::string(grids[grid_coord.x()][grid_coord.y()].type->name), + is_io_type(grids[grid_coord.x()][grid_coord.y()].type), + border_side); +} + +/******************************************************************** + * Find the cb_type of a GSB in the top-level module + * depending on the side of SB + * TOP/BOTTOM side: CHANY + * RIGHT/LEFT side: CHANX + *******************************************************************/ +t_rr_type find_top_module_cb_type_by_sb_side(const e_side& sb_side) { + VTR_ASSERT(NUM_SIDES != sb_side); + + if ((TOP == sb_side) || (BOTTOM == sb_side)) { + return CHANY; + } + + VTR_ASSERT((RIGHT == sb_side) || (LEFT == sb_side)); + return CHANX; +} + +/******************************************************************** + * Find the GSB coordinate for a CB in the top-level module + * depending on the side of a SB + * TODO: use vtr::Point to replace DeviceCoordinator + *******************************************************************/ +vtr::Point find_top_module_gsb_coordinate_by_sb_side(const RRGSB& rr_gsb, + const e_side& sb_side) { + VTR_ASSERT(NUM_SIDES != sb_side); + + vtr::Point gsb_coordinate; + + if ((TOP == sb_side) || (LEFT == sb_side)) { + gsb_coordinate.set_x(rr_gsb.get_x()); + gsb_coordinate.set_y(rr_gsb.get_y()); + return gsb_coordinate; + } + + VTR_ASSERT((RIGHT == sb_side) || (BOTTOM == sb_side)); + + /* RIGHT side: x + 1 */ + if (RIGHT == sb_side) { + gsb_coordinate.set_x(rr_gsb.get_x() + 1); + gsb_coordinate.set_y(rr_gsb.get_y()); + } + + /* BOTTOM side: y - 1 */ + if (BOTTOM == sb_side) { + gsb_coordinate.set_x(rr_gsb.get_x()); + gsb_coordinate.set_y(rr_gsb.get_y() - 1); + } + + return gsb_coordinate; +} + +} /* end namespace openfpga */ diff --git a/openfpga/src/fabric/build_top_module_utils.h b/openfpga/src/fabric/build_top_module_utils.h new file mode 100644 index 000000000..c0bcbcee5 --- /dev/null +++ b/openfpga/src/fabric/build_top_module_utils.h @@ -0,0 +1,31 @@ +#ifndef BUILD_TOP_MODULE_UTILS_H +#define BUILD_TOP_MODULE_UTILS_H + +/******************************************************************** + * Include header files that are required by function declaration + *******************************************************************/ +#include +#include +#include "vtr_geometry.h" +#include "device_grid.h" +#include "rr_gsb.h" + +/******************************************************************** + * Function declaration + *******************************************************************/ + +/* begin namespace openfpga */ +namespace openfpga { + +std::string generate_grid_block_module_name_in_top_module(const std::string& prefix, + const DeviceGrid& grids, + const vtr::Point& grid_coord); + +t_rr_type find_top_module_cb_type_by_sb_side(const e_side& sb_side); + +vtr::Point find_top_module_gsb_coordinate_by_sb_side(const RRGSB& rr_gsb, + const e_side& sb_side); + +} /* end namespace openfpga */ + +#endif