From 500ed28a7f3862cf61b1e931678c5f80727a3a06 Mon Sep 17 00:00:00 2001 From: liulixinkerry Date: Sat, 23 Nov 2024 13:09:12 +0800 Subject: [PATCH] refine code structure to accelerate compilation time --- CMakeLists.txt | 57 +++--- README.md | 2 +- cpp_to_py/common/db/BsRouteInfo.h | 4 + cpp_to_py/common/db/Cell.cpp | 11 +- cpp_to_py/common/db/Cell.h | 18 ++ cpp_to_py/common/db/Database.cpp | 234 +++++++++++++++-------- cpp_to_py/common/db/Database.h | 85 ++------ cpp_to_py/common/db/DatabaseClass.h | 45 +++++ cpp_to_py/common/db/DesignRule.cpp | 5 +- cpp_to_py/common/db/DesignRule.h | 9 + cpp_to_py/common/db/GCellGrid.h | 1 + cpp_to_py/common/db/Geometry.cpp | 5 +- cpp_to_py/common/db/Geometry.h | 11 +- cpp_to_py/common/db/Layer.cpp | 5 +- cpp_to_py/common/db/Layer.h | 13 +- cpp_to_py/common/db/Net.cpp | 29 ++- cpp_to_py/common/db/Net.h | 27 ++- cpp_to_py/common/db/Pin.cpp | 20 +- cpp_to_py/common/db/Pin.h | 37 +++- cpp_to_py/common/db/Region.cpp | 2 +- cpp_to_py/common/db/Region.h | 14 +- cpp_to_py/common/db/Row.h | 16 +- cpp_to_py/common/db/SNet.h | 12 +- cpp_to_py/common/db/Setting.h | 3 +- cpp_to_py/common/db/Site.h | 5 + cpp_to_py/common/db/SiteMap.cpp | 19 +- cpp_to_py/common/db/SiteMap.h | 15 +- cpp_to_py/common/db/Via.h | 10 + cpp_to_py/common/io/file_bkshf_db.cpp | 84 +++++--- cpp_to_py/common/io/file_constraints.cpp | 4 + cpp_to_py/common/io/file_lefdef_db.cpp | 110 +++++++---- cpp_to_py/common/io/file_verilog.cpp | 6 +- cpp_to_py/draw_placement/CMakeLists.txt | 4 +- cpp_to_py/gpudp/CMakeLists.txt | 37 ++-- cpp_to_py/gpudp/db/dp_torch.h | 5 +- cpp_to_py/gpudp/dp/detailed_place_db.cuh | 1 - cpp_to_py/gpudp/lg/legalization_db.h | 1 - cpp_to_py/gpugr/CMakeLists.txt | 74 ++----- cpp_to_py/gpugr/PyBindCppMain.cpp | 1 + cpp_to_py/gpugr/db/GRDatabase.cpp | 49 +++-- cpp_to_py/gpugr/db/GRDatabase.h | 12 +- cpp_to_py/gpugr/gr/RouteForce.cpp | 3 + cpp_to_py/gpugr/gr/RouteForce.h | 6 +- cpp_to_py/io_parser/BindHelper.cpp | 2 + cpp_to_py/io_parser/BindHelper.h | 3 - cpp_to_py/io_parser/PyBindCppMain.cpp | 2 + cpp_to_py/io_parser/gp/GPDatabase.cpp | 13 +- cpp_to_py/io_parser/gp/GPDatabase.h | 9 +- cpp_to_py/routedp/PyBindCppMain.cpp | 5 +- thirdparty/flute/CMakeLists.txt | 2 +- thirdparty/pybind11 | 2 +- 51 files changed, 729 insertions(+), 420 deletions(-) create mode 100644 cpp_to_py/common/db/DatabaseClass.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 01cf612..627b811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.18) -project(xplace C CXX) +project(xplace LANGUAGES C CXX CUDA) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) @@ -48,7 +48,25 @@ find_package(Cairo) message(STATUS "CAIRO_INCLUDE_DIRS: ${CAIRO_INCLUDE_DIRS}") message(STATUS "CAIRO_LIBRARIES: ${CAIRO_LIBRARIES}") -# Get Torch info +# CUDA +# set cuda arch and nvcc flags +if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + set(CMAKE_CUDA_ARCHITECTURES 80 86 CACHE STRING "CUDA architectures" FORCE) +endif() +message(STATUS "CMAKE_CUDA_ARCHITECTURES: ${CMAKE_CUDA_ARCHITECTURES}") +find_package(CUDAToolkit) + +# set nvcc flags +set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) +set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") +list(APPEND BASIC_CUDA_FLAGS --compiler-options;-fPIC;-std=c++17) +list(APPEND BASIC_CUDA_FLAGS --expt-relaxed-constexpr) # suppress warning from pytorch +message(STATUS "BASIC_CUDA_FLAGS: ${BASIC_CUDA_FLAGS}") +add_compile_options( + "$<$:${BASIC_CUDA_FLAGS}>" +) + +# Torch execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0]); print(int(torch.cuda.is_available())); print(torch.__version__);" OUTPUT_VARIABLE TORCH_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE) @@ -61,35 +79,10 @@ list(GET TORCH_VERSION_LIST 0 TORCH_VERSION_MAJOR) list(GET TORCH_VERSION_LIST 1 TORCH_VERSION_MINOR) message(STATUS TORCH_INSTALL_PREFIX=${TORCH_INSTALL_PREFIX}) message(STATUS TORCH_VERSION=${TORCH_VERSION_MAJOR}.${TORCH_VERSION_MINOR}) - -# find CUDA -if (TORCH_ENABLE_CUDA) - find_package(CUDA 11.4) - find_package(CUDAToolkit) - if (NOT CUDA_FOUND) - set(TORCH_ENABLE_CUDA 0 CACHE BOOL "Whether enable CUDA" FORCE) - message(FATAL_ERROR "Xplace only supports CUDA mode, CMake will exit." ) - endif(NOT CUDA_FOUND) -endif() message(STATUS TORCH_ENABLE_CUDA=${TORCH_ENABLE_CUDA}) - -# set cuda arch and nvcc flags -if (CUDA_FOUND) - if (NOT CUDA_ARCH_LIST) - set(CUDA_ARCH_LIST 6.0 6.1 7.0 7.5 8.0 8.6) - endif(NOT CUDA_ARCH_LIST) - # for cuda_add_library - cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS ${CUDA_ARCH_LIST}) - message(STATUS "CUDA_ARCH_FLAGS: ${CUDA_ARCH_FLAGS}") - # set nvcc flags - set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) - set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") - list(APPEND CUDA_NVCC_FLAGS ${CUDA_ARCH_FLAGS} --compiler-options;-fPIC;-std=c++17) - list(APPEND CUDA_NVCC_FLAGS ${CUDA_ARCH_FLAGS} --extended-lambda) - list(APPEND TORCH_NVCC_FLAGS --expt-relaxed-constexpr) - list(APPEND CUDA_NVCC_FLAGS ${TORCH_NVCC_FLAGS}) - message(STATUS "CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS}") -endif(CUDA_FOUND) +if (NOT TORCH_ENABLE_CUDA) + message(FATAL_ERROR "Xplace only supports Torch-CUDA mode, exit CMAKE." ) +endif() # set torch lib add_library(torch STATIC IMPORTED) @@ -131,7 +124,7 @@ function(add_pytorch_extension target_name) set(CUDA_SRCS "${ARG_UNPARSED_ARGUMENTS}") list(FILTER CUDA_SRCS INCLUDE REGEX ".*cu$") if (CUDA_SRCS) - cuda_add_library(${target_name}_cuda_tmp STATIC ${CUDA_SRCS}) + add_library(${target_name}_cuda_tmp STATIC ${CUDA_SRCS}) target_include_directories(${target_name}_cuda_tmp PRIVATE ${ARG_EXTRA_INCLUDE_DIRS} ${TORCH_INCLUDE_DIRS}) target_link_libraries(${target_name}_cuda_tmp ${ARG_EXTRA_LINK_LIBRARIES} ${TORCH_LIBRARY}) target_compile_definitions(${target_name}_cuda_tmp PRIVATE diff --git a/README.md b/README.md index ee654d6..5c3a465 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ make -j40 && make install ``` ### 1.1. Dependencies -- [CMake](https://cmake.org/) >= 3.17 +- [CMake](https://cmake.org/) >= 3.18 - [GCC](https://gcc.gnu.org/) >= 7.5.0 - [Boost](https://www.boost.org/) >= 1.56.0 - [CUDA](https://developer.nvidia.com/cuda-toolkit) >= 11.3 diff --git a/cpp_to_py/common/db/BsRouteInfo.h b/cpp_to_py/common/db/BsRouteInfo.h index 401caaa..e4bd126 100644 --- a/cpp_to_py/common/db/BsRouteInfo.h +++ b/cpp_to_py/common/db/BsRouteInfo.h @@ -1,6 +1,10 @@ #pragma once +#include namespace db { + +using std::vector; + class BsRouteInfo { // specially restore ICCAD2012/DAC2012 bookshelf routing info public: diff --git a/cpp_to_py/common/db/Cell.cpp b/cpp_to_py/common/db/Cell.cpp index 360cc9a..449603f 100644 --- a/cpp_to_py/common/db/Cell.cpp +++ b/cpp_to_py/common/db/Cell.cpp @@ -1,4 +1,9 @@ -#include "Database.h" +#include "Cell.h" + +#include "DatabaseClass.h" +#include "Geometry.h" +#include "Pin.h" + using namespace db; /***** Cell *****/ @@ -37,9 +42,7 @@ void Cell::ctype(CellType* t) { int Cell::lx() const { return _lx; } int Cell::ly() const { return _ly; } -int Cell::orient() const { - return _orient; -} +int Cell::orient() const { return _orient; } bool Cell::placed() const { return (lx() != INT_MIN) && (ly() != INT_MIN); } // int Cell::siteWidth() const { return width() / database.siteW; } diff --git a/cpp_to_py/common/db/Cell.h b/cpp_to_py/common/db/Cell.h index 4f93e21..16443e0 100644 --- a/cpp_to_py/common/db/Cell.h +++ b/cpp_to_py/common/db/Cell.h @@ -1,6 +1,24 @@ #pragma once +#include +#include +#include +#include "Geometry.h" namespace db { + +using std::string; +using std::vector; + +class CellType; +class Cell; +class Database; +class Rectangle; +class Geometry; +class Pin; +class Region; +class Net; +class PinType; + class CellType { friend class Database; diff --git a/cpp_to_py/common/db/Database.cpp b/cpp_to_py/common/db/Database.cpp index 1310c42..15dff85 100644 --- a/cpp_to_py/common/db/Database.cpp +++ b/cpp_to_py/common/db/Database.cpp @@ -1,11 +1,32 @@ #include "Database.h" +#include "BsRouteInfo.h" +#include "Cell.h" +#include "DatabaseClass.h" +#include "DesignRule.h" +#include "GCellGrid.h" +#include "Geometry.h" +#include "Layer.h" +#include "Net.h" +#include "Pin.h" +#include "Region.h" +#include "Row.h" +#include "SNet.h" +#include "Site.h" +#include "SiteMap.h" +#include "Via.h" + using namespace db; /***** Database *****/ Database::Database() { clear(); _buffer = new char[_bufferCapacity]; + powerNet = new PowerNet(); + siteMap = new SiteMap(); + gcellgrid = new GCellGrid(); + bsRouteInfo = new BsRouteInfo(); + edgetypes = new EdgeTypes(); } Database::~Database() { @@ -72,16 +93,15 @@ void Database::reset() { name_viatypes.clear(); layers.clear(); - sites.clear(); routeBlockages.clear(); placeBlockages.clear(); - powerNet = PowerNet(); - - siteMap = SiteMap(); - gcellgrid = GCellGrid(); - edgetypes = EdgeTypes(); + powerNet = new PowerNet(); + siteMap = new SiteMap(); + gcellgrid = new GCellGrid(); + bsRouteInfo = new BsRouteInfo(); + edgetypes = new EdgeTypes(); dbIssues.clear(); dieLX = 0; @@ -114,6 +134,11 @@ void Database::clearTechnology() { CLEAR_POINTER_MAP(ndrs); } +void Database::clearLibrary() { + CLEAR_POINTER_LIST(lefsites); + CLEAR_POINTER_LIST(celltypes); +} + void Database::clearDesign() { CLEAR_POINTER_LIST(cells); CLEAR_POINTER_LIST(iopins); @@ -126,6 +151,22 @@ void Database::clearDesign() { DBU_Micron = -1.0; designName = ""; regions.push_back(new Region("default")); + + if (!powerNet) { + delete powerNet; + } + if (!siteMap) { + delete siteMap; + } + if (!gcellgrid) { + delete gcellgrid; + } + if (!bsRouteInfo) { + delete bsRouteInfo; + } + if (!edgetypes) { + delete edgetypes; + } } void Database::save(const std::string& given_prefix) { @@ -246,17 +287,17 @@ void Database::SetupFloorplan() { coreHY = std::max(row->y() + siteH, coreHY); } - for (Site& site : sites) { - if (site.siteClassName() == "CORE") { - if (siteW != (unsigned)site.width()) { + for (Site* lefsite : lefsites) { + if (lefsite->siteClassName() == "CORE") { + if (siteW != (unsigned)lefsite->width()) { logger.warning("siteW %d in DEF is inconsistent with siteW %d in LEF.", static_cast(siteW), - static_cast(site.width())); + static_cast(lefsite->width())); } - if (siteH != site.height()) { + if (siteH != lefsite->height()) { logger.warning("siteH %d in DEF is inconsistent with siteH %d in LEF.", static_cast(siteH), - static_cast(site.height())); + static_cast(lefsite->height())); } break; } @@ -319,15 +360,15 @@ void Database::SetupRegions() { void Database::SetupSiteMap() { // set up site map - siteMap.siteL = coreLX; - siteMap.siteR = coreHX; - siteMap.siteB = coreLY; - siteMap.siteT = coreHY; - siteMap.siteStepX = siteW; - siteMap.siteStepY = siteH; - siteMap.siteNX = nSitesX; - siteMap.siteNY = nSitesY; - siteMap.initSiteMap(nSitesX, nSitesY); + siteMap->siteL = coreLX; + siteMap->siteR = coreHX; + siteMap->siteB = coreLY; + siteMap->siteT = coreHY; + siteMap->siteStepX = siteW; + siteMap->siteStepY = siteH; + siteMap->siteNX = nSitesX; + siteMap->siteNY = nSitesY; + siteMap->initSiteMap(nSitesX, nSitesY); // mark site partially overlapped by fence int nRegions = regions.size(); @@ -342,20 +383,20 @@ void Database::SetupSiteMap() { for (int j = 0; j < (int)hSlices.size(); j++) { int lx = hSlices[j].lx; int hx = hSlices[j].hx; - int olx = binOverlappedL(lx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); - int ohx = binOverlappedR(hx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); - int clx = binContainedL(lx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); - int chx = binContainedR(hx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); - int sly = binOverlappedL(hSlices[j].ly, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); - int shy = binOverlappedR(hSlices[j].hy, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); + int olx = binOverlappedL(lx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); + int ohx = binOverlappedR(hx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); + int clx = binContainedL(lx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); + int chx = binContainedR(hx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); + int sly = binOverlappedL(hSlices[j].ly, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); + int shy = binOverlappedR(hSlices[j].hy, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); if (olx != clx) { for (int y = sly; y <= shy; y++) { - siteMap.blockRegion(olx, y); + siteMap->blockRegion(olx, y); } } if (ohx != chx) { for (int y = sly; y <= shy; y++) { - siteMap.blockRegion(ohx, y); + siteMap->blockRegion(ohx, y); } } } @@ -365,34 +406,34 @@ void Database::SetupSiteMap() { for (const Rectangle& vSlice : vSlices) { int ly = vSlice.ly; int hy = vSlice.hy; - const unsigned oly = binOverlappedL(ly, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); - const unsigned ohy = binOverlappedR(hy, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); - const int cly = binContainedL(ly, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); - const int chy = binContainedR(hy, siteMap.siteB, siteMap.siteT, siteMap.siteStepY); - const unsigned slx = binOverlappedL(vSlice.lx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); - const unsigned shx = binOverlappedR(vSlice.hx, siteMap.siteL, siteMap.siteR, siteMap.siteStepX); + const unsigned oly = binOverlappedL(ly, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); + const unsigned ohy = binOverlappedR(hy, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); + const int cly = binContainedL(ly, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); + const int chy = binContainedR(hy, siteMap->siteB, siteMap->siteT, siteMap->siteStepY); + const unsigned slx = binOverlappedL(vSlice.lx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); + const unsigned shx = binOverlappedR(vSlice.hx, siteMap->siteL, siteMap->siteR, siteMap->siteStepX); if ((int)oly != cly) { for (unsigned x = slx; x <= shx; ++x) { - siteMap.blockRegion(x, oly); + siteMap->blockRegion(x, oly); } } if ((int)ohy != chy) { for (unsigned x = slx; x <= shx; ++x) { - siteMap.blockRegion(x, ohy); + siteMap->blockRegion(x, ohy); } } } for (const Rectangle& rect : hSlices) { - siteMap.setRegion(rect.lx, rect.ly, rect.hx, rect.hy, region->id); + siteMap->setRegion(rect.lx, rect.ly, rect.hx, rect.hy, region->id); } for (const Rectangle& rect : vSlices) { - siteMap.setRegion(rect.lx, rect.ly, rect.hx, rect.hy, region->id); + siteMap->setRegion(rect.lx, rect.ly, rect.hx, rect.hy, region->id); } } // mark all sites blocked - siteMap.setSites(coreLX, coreLY, coreHX, coreHY, SiteMap::SiteBlocked); + siteMap->setSites(coreLX, coreLY, coreHX, coreHY, SiteMap::SiteBlocked); // mark rows as non-blocked for (const Row* row : rows) { @@ -400,7 +441,7 @@ void Database::SetupSiteMap() { int ly = row->y(); int hx = row->x() + row->width(); int hy = row->y() + siteH; - siteMap.unsetSites(lx, ly, hx, hy, SiteMap::SiteBlocked); + siteMap->unsetSites(lx, ly, hx, hy, SiteMap::SiteBlocked); } // mark blocked sites @@ -413,8 +454,8 @@ void Database::SetupSiteMap() { int hx = cell->hx(); int hy = cell->hy(); - siteMap.setSites(lx, ly, hx, hy, SiteMap::SiteBlocked); - siteMap.blockRegion(lx, ly, hx, hy); + siteMap->setSites(lx, ly, hx, hy, SiteMap::SiteBlocked); + siteMap->blockRegion(lx, ly, hx, hy); } for (const Rectangle& placeBlockage : placeBlockages) { @@ -422,8 +463,8 @@ void Database::SetupSiteMap() { int ly = placeBlockage.ly; int hx = placeBlockage.hx; int hy = placeBlockage.hy; - siteMap.setSites(lx, ly, hx, hy, SiteMap::SiteBlocked); - siteMap.blockRegion(lx, ly, hx, hy); + siteMap->setSites(lx, ly, hx, hy, SiteMap::SiteBlocked); + siteMap->blockRegion(lx, ly, hx, hy); } for (const SNet* snet : snets) { @@ -431,11 +472,11 @@ void Database::SetupSiteMap() { switch (geo.layer.rIndex) { case 1: if (geo.layer.direction == 'v') { - siteMap.setSites(geo.lx, geo.ly, geo.hx, geo.hy, SiteMap::SiteM2Blocked); + siteMap->setSites(geo.lx, geo.ly, geo.hx, geo.hy, SiteMap::SiteM2Blocked); } break; case 2: - siteMap.setSites(geo.lx, geo.ly, geo.hx, geo.hy, SiteMap::SiteM3Blocked); + siteMap->setSites(geo.lx, geo.ly, geo.hx, geo.hy, SiteMap::SiteM3Blocked); break; default: break; @@ -449,11 +490,11 @@ void Database::SetupSiteMap() { case 0: break; case 1: - siteMap.setSites(shape.lx + iopin->x, - shape.ly + iopin->y, - shape.hx + iopin->x, - shape.hy + iopin->y, - SiteMap::SiteM2BlockedIOPin); + siteMap->setSites(shape.lx + iopin->x, + shape.ly + iopin->y, + shape.hx + iopin->x, + shape.hy + iopin->y, + SiteMap::SiteM2BlockedIOPin); break; case 2: break; @@ -463,31 +504,31 @@ void Database::SetupSiteMap() { } } - siteMap.nSites = siteMap.siteNX * siteMap.siteNY; - siteMap.nPlaceable = 0; - siteMap.nRegionSites.resize(regions.size(), 0); - for (int y = 0; y < siteMap.siteNY; y++) { - for (int x = 0; x < siteMap.siteNX; x++) { - if (siteMap.getSiteMap(x, y, SiteMap::SiteBlocked) || siteMap.getSiteMap(x, y, SiteMap::SiteM2Blocked) || - siteMap.getSiteMap(x, y, SiteMap::SiteM2BlockedIOPin)) { + siteMap->nSites = siteMap->siteNX * siteMap->siteNY; + siteMap->nPlaceable = 0; + siteMap->nRegionSites.resize(regions.size(), 0); + for (int y = 0; y < siteMap->siteNY; y++) { + for (int x = 0; x < siteMap->siteNX; x++) { + if (siteMap->getSiteMap(x, y, SiteMap::SiteBlocked) || siteMap->getSiteMap(x, y, SiteMap::SiteM2Blocked) || + siteMap->getSiteMap(x, y, SiteMap::SiteM2BlockedIOPin)) { continue; } - siteMap.nPlaceable++; - unsigned char region = siteMap.getRegion(x, y); + siteMap->nPlaceable++; + unsigned char region = siteMap->getRegion(x, y); if (region != Region::InvalidRegion) { - siteMap.nRegionSites[region]++; + siteMap->nRegionSites[region]++; } } } - logger.verbose("core area: %ld", siteMap.nSites); + logger.verbose("core area: %ld", siteMap->nSites); logger.verbose( - "placeable: %ld (%lf%%)", siteMap.nPlaceable, (double)siteMap.nPlaceable / (double)siteMap.nSites * 100.0); + "placeable: %ld (%lf%%)", siteMap->nPlaceable, (double)siteMap->nPlaceable / (double)siteMap->nSites * 100.0); for (int i = 0; i < (int)regions.size(); i++) { logger.verbose("region %d : %ld (%lf%%)", i, - siteMap.nRegionSites[i], - (double)siteMap.nRegionSites[i] / (double)siteMap.nPlaceable); + siteMap->nRegionSites[i], + (double)siteMap->nRegionSites[i] / (double)siteMap->nPlaceable); } } @@ -499,7 +540,8 @@ void Database::SetupRows() { for (Row* row : rows) { char isFlip = (row->flip() ? 1 : 2); int y = (row->y() - coreLY) / siteH; - orients[y] = row->orient(); // TODO: how to handle multiple ROW definitions on same y? + orients[y] = row->orient(); // TODO: how to handle multiple ROW + // definitions on same y? if (flip[y] == 0) { flip[y] = isFlip; } else if (flip[y] != isFlip) { @@ -543,27 +585,42 @@ void Database::SetupRows() { Row* row = rows[y]; int ly = row->y(); int hy = row->y() + siteH; - if (!powerNet.getRowPower(ly, hy, row->_topPower, row->_botPower)) { + if (!powerNet->getRowPower(ly, hy, row->_topPower, row->_botPower)) { if (topNormal && row->topPower() == 'x') { if (y + 1 == nSitesY) { - logger.warning("Top power rail of the row at y=%d is not connected to power rail", row->y()); + logger.warning( + "Top power rail of the row at y=%d is not connected to " + "power rail", + row->y()); } else { - logger.error("Top power rail of the row at y=%d is not connected to power rail", row->y()); + logger.error( + "Top power rail of the row at y=%d is not connected to " + "power rail", + row->y()); topNormal = false; } } if (botNormal && row->botPower() == 'x') { if (y) { - logger.error("Bottom power rail of the row at y=%d is not connected to power rail", row->y()); + logger.error( + "Bottom power rail of the row at y=%d is not connected " + "to power rail", + row->y()); botNormal = false; } else { - logger.warning("Bottom power rail of the row at y=%d is not connected to power rail", row->y()); + logger.warning( + "Bottom power rail of the row at y=%d is not connected " + "to power rail", + row->y()); } } } if (shrNormal && row->topPower() == row->botPower()) { logger.error( - "Top and Bottom power rail of the row at y=%d share the same power %c", row->y(), row->topPower()); + "Top and Bottom power rail of the row at y=%d share the same " + "power %c", + row->y(), + row->topPower()); shrNormal = false; } } @@ -584,15 +641,15 @@ void Database::SetupRowSegments() { b2 = true; r2 = NULL; } else { - b2 = siteMap.getSiteMap(x, y, SiteMap::SiteBlocked); + b2 = siteMap->getSiteMap(x, y, SiteMap::SiteBlocked); if (setting.EnablePG) { - b2 = b2 || siteMap.getSiteMap(x, y, SiteMap::SiteM2Blocked); + b2 = b2 || siteMap->getSiteMap(x, y, SiteMap::SiteM2Blocked); } if (setting.EnableIOPin) { - b2 = b2 || siteMap.getSiteMap(x, y, SiteMap::SiteM2BlockedIOPin); + b2 = b2 || siteMap->getSiteMap(x, y, SiteMap::SiteM2BlockedIOPin); } if (setting.EnableFence) { - r2 = getRegion(siteMap.getRegion(x, y)); + r2 = getRegion(siteMap->getRegion(x, y)); } else { r2 = regions[0]; } @@ -650,15 +707,16 @@ Layer& Database::addLayer(const string& name, const char type) { return newlayer; } -Site& Database::addSite(const string& name, const string& siteClassName, const int w, const int h) { - for (unsigned i = 0; i < sites.size(); i++) { - if (name == sites[i].name()) { +Site* Database::addSite(const string& name, const string& siteClassName, const int w, const int h) { + for (unsigned i = 0; i < lefsites.size(); i++) { + if (name == lefsites[i]->name()) { logger.warning("site re-defined: %s", name.c_str()); - return sites[i]; + return lefsites[i]; } } - sites.emplace_back(name, siteClassName, w, h); - return sites.back(); + Site* site = new Site(name, siteClassName, w, h); + lefsites.push_back(site); + return site; } ViaType* Database::addViaType(const string& name, bool isDef) { @@ -793,7 +851,7 @@ long long Database::getFreeArea(Region* region) const { if (region && region != regions[i]) { continue; } - freeArea += siteMap.nRegionSites[i]; + freeArea += siteMap->nRegionSites[i]; } return freeArea; } @@ -919,6 +977,12 @@ ViaType* Database::getViaType(const string& name) const { return mi->second; } +int Database::getCellTypeSpace(const CellType* L, const CellType* R) const { + return edgetypes->getEdgeSpace(L->edgetypeR, R->edgetypeL); +} + +int Database::getCellTypeSpace(const Cell* L, const Cell* R) const { return getCellTypeSpace(L->ctype(), R->ctype()); } + int Database::getContainedSites( const int lx, const int ly, const int hx, const int hy, int& slx, int& sly, int& shx, int& shy) const { slx = binContainedL(lx, coreLX, coreHX, siteW); @@ -963,6 +1027,8 @@ unsigned Database::getNumCLayers() const { return numCLayers; } +unsigned Database::getNumLayers() const { return layers.size(); } + void Database::errorCheck(bool autoFix) { vector::iterator ri = rows.begin(); vector::iterator re = rows.end(); diff --git a/cpp_to_py/common/db/Database.h b/cpp_to_py/common/db/Database.h index fa88672..36e2eaf 100644 --- a/cpp_to_py/common/db/Database.h +++ b/cpp_to_py/common/db/Database.h @@ -1,54 +1,7 @@ #pragma once +#include "DatabaseClass.h" #include "Setting.h" -#include "common/common.h" - -namespace db { - -using std::string; -using std::vector; - -class Rectangle; -class Geometry; -class GeoMap; -class Cell; -class CellType; -class Pin; -class PinType; -class IOPin; -class CellPin; -class Net; -class Row; -class RowSegment; -class Track; -class Layer; -class Via; -class ViaRule; -class ViaType; -class Region; -class NDR; -class SNet; -class Site; -class PowerNet; -class EdgeTypes; -class GCellGrid; -class BsRouteInfo; -} // namespace db - -#include "BsRouteInfo.h" -#include "Cell.h" -#include "DesignRule.h" -#include "GCellGrid.h" -#include "Geometry.h" -#include "Layer.h" -#include "Net.h" -#include "Pin.h" -#include "Region.h" -#include "Row.h" -#include "SNet.h" -#include "Site.h" -#include "SiteMap.h" -#include "Via.h" namespace db { @@ -86,7 +39,7 @@ public: robin_hood::unordered_map name_viatypes; vector layers; - vector sites; + vector lefsites; vector viatypes; vector celltypes; @@ -102,7 +55,7 @@ public: vector routeBlockages; vector placeBlockages; - PowerNet powerNet; + PowerNet* powerNet = nullptr; private: static const size_t _bufferCapacity = 128 * 1024; @@ -115,11 +68,11 @@ public: unsigned nSitesX = 0; unsigned nSitesY = 0; - SiteMap siteMap; - GCellGrid gcellgrid; + SiteMap* siteMap = nullptr; + GCellGrid* gcellgrid = nullptr; - BsRouteInfo bsRouteInfo; - EdgeTypes edgetypes; + BsRouteInfo* bsRouteInfo = nullptr; + EdgeTypes* edgetypes = nullptr; int dieLX, dieLY, dieHX, dieHY; int coreLX, coreLY, coreHX, coreHY; @@ -139,13 +92,13 @@ public: ~Database(); void clear(); void clearTechnology(); - inline void clearLibrary() { CLEAR_POINTER_LIST(celltypes); } + void clearLibrary(); void clearDesign(); Layer& addLayer(const string& name, const char type = 'x'); - Site& addSite(const string& name, const string& siteClassName, const int w, const int h); + Site* addSite(const string& name, const string& siteClassName, const int w, const int h); ViaType* addViaType(const string& name, bool isDef); - inline ViaType* addViaType(const string& name) { return addViaType(name, false); } + ViaType* addViaType(const string& name) { return addViaType(name, false); } CellType* addCellType(const string& name, unsigned libcell); void reserveCells(const size_t n) { cells.reserve(n); } Cell* addCell(const string& name, CellType* type = nullptr); @@ -183,17 +136,15 @@ public: unsigned getNumRLayers() const; unsigned getNumCLayers() const; - inline unsigned getNumLayers() const { return layers.size(); } - inline unsigned getNumCells() const { return cells.size(); } - inline unsigned getNumNets() const { return nets.size(); } - inline unsigned getNumRegions() const { return regions.size(); } - inline unsigned getNumIOPins() const { return iopins.size(); } - inline unsigned getNumCellTypes() const { return celltypes.size(); } + unsigned getNumLayers() const; + unsigned getNumCells() const { return cells.size(); } + unsigned getNumNets() const { return nets.size(); } + unsigned getNumRegions() const { return regions.size(); } + unsigned getNumIOPins() const { return iopins.size(); } + unsigned getNumCellTypes() const { return celltypes.size(); } - inline int getCellTypeSpace(const CellType* L, const CellType* R) const { - return edgetypes.getEdgeSpace(L->edgetypeR, R->edgetypeL); - } - inline int getCellTypeSpace(const Cell* L, const Cell* R) const { return getCellTypeSpace(L->ctype(), R->ctype()); } + int getCellTypeSpace(const CellType* L, const CellType* R) const; + int getCellTypeSpace(const Cell* L, const Cell* R) const; int getContainedSites( const int lx, const int ly, const int hx, const int hy, int& slx, int& sly, int& shx, int& shy) const; int getOverlappedSites( diff --git a/cpp_to_py/common/db/DatabaseClass.h b/cpp_to_py/common/db/DatabaseClass.h new file mode 100644 index 0000000..9af8b05 --- /dev/null +++ b/cpp_to_py/common/db/DatabaseClass.h @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +#include "common/utils/utils.h" + +using utils::assert_msg; +using utils::logger; + +namespace db { + +using std::string; +using std::vector; + +class Database; +class Rectangle; +class Geometry; +class GeoMap; +class Cell; +class CellType; +class Pin; +class PinType; +class IOPin; +class CellPin; +class Net; +class Row; +class RowSegment; +class Track; +class Layer; +class Via; +class ViaRule; +class ViaType; +class Region; +class NDR; +class SNet; +class Site; +class SiteMap; +class PowerNet; +class EdgeTypes; +class GCellGrid; +class BsRouteInfo; +} // namespace db diff --git a/cpp_to_py/common/db/DesignRule.cpp b/cpp_to_py/common/db/DesignRule.cpp index 6360a2f..d3d7d92 100644 --- a/cpp_to_py/common/db/DesignRule.cpp +++ b/cpp_to_py/common/db/DesignRule.cpp @@ -1,4 +1,7 @@ -#include "Database.h" +#include "DesignRule.h" + +#include "DatabaseClass.h" + using namespace db; /***** EdgeTypes *****/ diff --git a/cpp_to_py/common/db/DesignRule.h b/cpp_to_py/common/db/DesignRule.h index b86e9a0..ea66367 100644 --- a/cpp_to_py/common/db/DesignRule.h +++ b/cpp_to_py/common/db/DesignRule.h @@ -1,6 +1,15 @@ #pragma once +#include +#include namespace db { + +class Layer; +class ViaType; + +using std::string; +using std::vector; + class WireRule { private: const Layer* _layer; diff --git a/cpp_to_py/common/db/GCellGrid.h b/cpp_to_py/common/db/GCellGrid.h index 7eb8980..3df0844 100644 --- a/cpp_to_py/common/db/GCellGrid.h +++ b/cpp_to_py/common/db/GCellGrid.h @@ -1,4 +1,5 @@ #pragma once +#include namespace db { diff --git a/cpp_to_py/common/db/Geometry.cpp b/cpp_to_py/common/db/Geometry.cpp index 3e5386b..915d4c4 100644 --- a/cpp_to_py/common/db/Geometry.cpp +++ b/cpp_to_py/common/db/Geometry.cpp @@ -1,4 +1,7 @@ -#include "Database.h" +#include "DatabaseClass.h" +#include "Geometry.h" +#include "Layer.h" + using namespace db; /***** Rectangle *****/ diff --git a/cpp_to_py/common/db/Geometry.h b/cpp_to_py/common/db/Geometry.h index c7660b1..f5df8f6 100644 --- a/cpp_to_py/common/db/Geometry.h +++ b/cpp_to_py/common/db/Geometry.h @@ -1,6 +1,15 @@ #pragma once +#include +#include +#include +#include namespace db { + +using std::vector; + +class Layer; + class Rectangle { public: int lx = INT_MAX; @@ -47,7 +56,7 @@ public: : Rectangle(lx, ly, hx, hy), layer(layer) {} Geometry(const Geometry& geom) : Rectangle(geom), layer(geom.layer) {} - inline bool operator==(const Geometry& rhs) const; + bool operator==(const Geometry& rhs) const; }; class GeoMap : public Rectangle { diff --git a/cpp_to_py/common/db/Layer.cpp b/cpp_to_py/common/db/Layer.cpp index 03322fb..cf18b65 100644 --- a/cpp_to_py/common/db/Layer.cpp +++ b/cpp_to_py/common/db/Layer.cpp @@ -1,4 +1,7 @@ -#include "Database.h" +#include "Layer.h" + +#include "DatabaseClass.h" + using namespace db; /***** Track *****/ diff --git a/cpp_to_py/common/db/Layer.h b/cpp_to_py/common/db/Layer.h index 564a78c..b84a746 100644 --- a/cpp_to_py/common/db/Layer.h +++ b/cpp_to_py/common/db/Layer.h @@ -1,6 +1,17 @@ #pragma once +#include +#include +#include +#include namespace db { + +using std::string; +using std::vector; + +class Layer; +class Track; + class Track { // contain DEF track info // support multi layer track DEF definition @@ -68,7 +79,7 @@ public: // ParallelRunLength Spacing vector parLength; vector parWidth; - vector> parWidthSpace; // 2D table: (parWidth, parLength) -> widthSpacing + vector> parWidthSpace; // 2D table: (parWidth, parLength) -> widthSpacing vector tracks; vector nonPreferDirTracks; diff --git a/cpp_to_py/common/db/Net.cpp b/cpp_to_py/common/db/Net.cpp index b5994f3..eda2228 100644 --- a/cpp_to_py/common/db/Net.cpp +++ b/cpp_to_py/common/db/Net.cpp @@ -1,4 +1,12 @@ -#include "Database.h" +#include "Net.h" + +#include "DatabaseClass.h" +#include "DesignRule.h" +#include "Layer.h" +#include "SNet.h" +#include "Via.h" +#include "Geometry.h" + using namespace db; /***** NetRouteNode *****/ @@ -6,6 +14,10 @@ using namespace db; NetRouteNode::NetRouteNode(const Layer* layer, const int x, const int y, const int z) : _layer(layer), x(x), y(y), z(z) {} +bool NetRouteNode::operator==(const NetRouteNode& r) const { + return _layer == r._layer && x == r.x && y == r.y && z == r.z; +} + /***** NetRouteSegment *****/ NetRouteSegment::NetRouteSegment(const unsigned fromi, const unsigned toi, const char dir, const unsigned len) @@ -94,6 +106,9 @@ long long NetRouting::length() const { /***** Net *****/ +Net::Net(const string& name, const NDR* ndr) : name(name), ndr(ndr) {} +Net::Net(const Net& net) : _routing(net._routing), name(net.name), pins(net.pins), ndr(net.ndr) {} + void Net::addPin(Pin* pin) { // if (pin->type->direction() == 'o' && pins.size()) { // Pin* firstPin = pins[0]; @@ -111,12 +126,13 @@ void Net::addPin(Pin* pin) { void PowerNet::addRail(SNet* snet, int lx, int hx, int y) { std::map::iterator rail = rails.find(y); if (rail != rails.end() && rail->second != snet) { - logger.error("rail %s already exists at y=%d , new rail %s is from %d to %d", rail->second->name.c_str(), - y, snet->name.c_str(), - lx, - hx); + logger.error("rail %s already exists at y=%d , new rail %s is from %d to %d", + rail->second->name.c_str(), + y, + snet->name.c_str(), + lx, + hx); return; - } rails.emplace(y, snet); } @@ -139,4 +155,3 @@ bool PowerNet::getRowPower(int ly, int hy, char& topPower, char& botPower) { } return valid; } - diff --git a/cpp_to_py/common/db/Net.h b/cpp_to_py/common/db/Net.h index d88499a..ede4595 100644 --- a/cpp_to_py/common/db/Net.h +++ b/cpp_to_py/common/db/Net.h @@ -1,7 +1,24 @@ #pragma once +#include +#include +#include +#include namespace db { +using std::string; +using std::vector; + +class Layer; +class Pin; +class Cell; +class NDR; +class NetRouteNode; +class NetRouteSegment; +class NetRouting; +class Net; +class SNet; + class NetRouteNode { private: const Layer* _layer = nullptr; @@ -11,12 +28,9 @@ public: int y = 0; int z = 0; Pin* pin; - NetRouteNode(const Layer* layer = nullptr, const int x = 0, const int y = 0, const int z = 0); - inline bool operator==(const NetRouteNode& r) const { - return _layer == r._layer && x == r.x && y == r.y && z == r.z; - } + bool operator==(const NetRouteNode& r) const; }; class NetRouteSegment { @@ -62,8 +76,8 @@ public: const NDR* ndr = nullptr; int gpdb_id = -1; - Net(const string& name, const NDR* ndr = nullptr) : name(name), ndr(ndr) {} - Net(const Net& net) : _routing(net._routing), name(net.name), pins(net.pins), ndr(net.ndr) {} + Net(const string& name, const NDR* ndr = nullptr); + Net(const Net& net); bool globalRouted() const { return gRouted; } bool detailedRouted() const { return dRouted; } @@ -100,6 +114,7 @@ private: std::map rails; public: + ~PowerNet() { rails.clear(); } void addRail(SNet* snet, int lx, int hx, int y); bool getRowPower(int ly, int hy, char& topPower, char& botPower); }; diff --git a/cpp_to_py/common/db/Pin.cpp b/cpp_to_py/common/db/Pin.cpp index c90bbf0..75eb052 100644 --- a/cpp_to_py/common/db/Pin.cpp +++ b/cpp_to_py/common/db/Pin.cpp @@ -1,4 +1,12 @@ -#include "Database.h" +#include "Pin.h" + +#include "Cell.h" +#include "DatabaseClass.h" +#include "Geometry.h" +#include "Layer.h" +#include "Net.h" +#include "common/utils/utils.h" + using namespace db; /***** PinSTA *****/ @@ -38,6 +46,11 @@ void IOPin::getBounds(int& lx, int& ly, int& hx, int& hy, int& rIndex) const { /***** Pin *****/ +Pin::Pin(const PinType* type) : type(type) {} +Pin::Pin(Cell* cell, int i) : cell(cell), type(cell->ctype()->pins[i]), parentCellPinId(i) {} +Pin::Pin(IOPin* iopin) : iopin(iopin), type(iopin->type) {} +Pin::Pin(const Pin& pin) : cell(pin.cell), net(pin.net), type(pin.type) {} + void Pin::getPinCenter(int& x, int& y) { int lx, ly, hx, hy; type->getBounds(lx, ly, hx, hy); @@ -160,3 +173,8 @@ bool PinType::comparePin(vector pins1, vector pins2) { } return true; } + +bool PinType::operator==(const PinType& r) const { + return _type == r._type && boundLX == r.boundLX && boundLY == r.boundLY && boundHX == r.boundHX && + boundHY == r.boundHY && shapes[0].layer.rIndex == r.shapes[0].layer.rIndex; +} \ No newline at end of file diff --git a/cpp_to_py/common/db/Pin.h b/cpp_to_py/common/db/Pin.h index dfc4643..177f963 100644 --- a/cpp_to_py/common/db/Pin.h +++ b/cpp_to_py/common/db/Pin.h @@ -1,6 +1,30 @@ #pragma once +#include +#include +#include + +namespace utils { +template +class BoxT; +template +class PointT; +} // namespace utils + namespace db { + +using std::string; +using std::vector; + +class Geometry; +class Layer; +class PinType; +class IOPin; +class Pin; +class PinSTA; +class Cell; +class Net; + class PinType { private: string _name = ""; @@ -30,10 +54,7 @@ public: unsigned getW() const { return boundHX - boundLX; } unsigned getH() const { return boundHY - boundLY; } void getBounds(int& lx, int& ly, int& hx, int& hy) const; - bool operator==(const PinType& r) const { - return _type == r._type && boundLX == r.boundLX && boundLY == r.boundLY && boundHX == r.boundHX && - boundHY == r.boundHY && shapes[0].layer.rIndex == r.shapes[0].layer.rIndex; - } + bool operator==(const PinType& r) const; bool operator!=(const PinType& r) const { return !(*this == r); } bool operator<(const PinType& r) const; bool operator>(const PinType& r) const { return r < *this; } @@ -95,10 +116,10 @@ public: PinSTA* staInfo = nullptr; - Pin(const PinType* type = nullptr) : type(type) {} - Pin(Cell* cell, int i) : cell(cell), type(cell->ctype()->pins[i]), parentCellPinId(i) {} - Pin(IOPin* iopin) : iopin(iopin), type(iopin->type) {} - Pin(const Pin& pin) : cell(pin.cell), net(pin.net), type(pin.type) {} + Pin(const PinType* type = nullptr); + Pin(Cell* cell, int i); + Pin(IOPin* iopin); + Pin(const Pin& pin); void getPinCenter(int& x, int& y); void getPinBounds(int& lx, int& ly, int& hx, int& hy, int& rIndex); diff --git a/cpp_to_py/common/db/Region.cpp b/cpp_to_py/common/db/Region.cpp index 70f7083..a78142b 100644 --- a/cpp_to_py/common/db/Region.cpp +++ b/cpp_to_py/common/db/Region.cpp @@ -1,4 +1,4 @@ -#include "Database.h" +#include "Region.h" using namespace db; /***** Region *****/ diff --git a/cpp_to_py/common/db/Region.h b/cpp_to_py/common/db/Region.h index 7fe0296..edb7931 100644 --- a/cpp_to_py/common/db/Region.h +++ b/cpp_to_py/common/db/Region.h @@ -1,6 +1,14 @@ #pragma once +#include +#include + +#include "Geometry.h" namespace db { + +using std::string; +using std::vector; + class Region : public Rectangle { private: string _name = ""; @@ -19,12 +27,10 @@ public: Region(const string& name = "", const char type = 'x') : Rectangle(INT_MAX, INT_MAX, INT_MIN, INT_MIN), _name(name), _type(type) {} - inline const string& name() const { return _name; } - inline char type() const { return _type; } + const string& name() const { return _name; } + char type() const { return _type; } void addRect(const int xl, const int yl, const int xh, const int yh); void resetRects() { sliceH(rects); } - }; } // namespace db - diff --git a/cpp_to_py/common/db/Row.h b/cpp_to_py/common/db/Row.h index 36e51d9..6319358 100644 --- a/cpp_to_py/common/db/Row.h +++ b/cpp_to_py/common/db/Row.h @@ -1,6 +1,16 @@ #pragma once +#include +#include namespace db { + +class Region; +class Row; +class RowSegment; + +using std::string; +using std::vector; + class Row { friend class Database; @@ -11,7 +21,7 @@ private: int _y = 0; unsigned _xNum = 0; unsigned _yNum = 0; - int _orient = 0; // 0:N, 1:W, 2:S, 3:E, 4:FN, 5:FW, 6:FS, 7:FE, -1:NONE + int _orient = 0; // 0:N, 1:W, 2:S, 3:E, 4:FN, 5:FW, 6:FS, 7:FE, -1:NONE bool _flip = false; unsigned _xStep = 0; unsigned _yStep = 0; @@ -71,7 +81,6 @@ public: void shiftY(const int value) { _y += value; } void shrinkXNum(const int value) { _xNum -= value; } void shrinkYNum(const int value) { _yNum -= value; } - }; class RowSegment { @@ -80,5 +89,4 @@ public: int w = 0; Region* region = nullptr; }; -} // namespace db - +} // namespace db diff --git a/cpp_to_py/common/db/SNet.h b/cpp_to_py/common/db/SNet.h index 2c2ade9..b010092 100644 --- a/cpp_to_py/common/db/SNet.h +++ b/cpp_to_py/common/db/SNet.h @@ -1,6 +1,14 @@ #pragma once +#include + +#include "Via.h" namespace db { + +using std::vector; + +class Geometry; + class SNet { public: string name; @@ -19,7 +27,5 @@ public: void addVia(Args&&... args) { vias.emplace_back(args...); } - }; -} - +} // namespace db diff --git a/cpp_to_py/common/db/Setting.h b/cpp_to_py/common/db/Setting.h index 12e422f..5ff6ebe 100644 --- a/cpp_to_py/common/db/Setting.h +++ b/cpp_to_py/common/db/Setting.h @@ -1,5 +1,6 @@ #pragma once -#include "common/common.h" +#include +#include namespace db { diff --git a/cpp_to_py/common/db/Site.h b/cpp_to_py/common/db/Site.h index 248b581..2e019ee 100644 --- a/cpp_to_py/common/db/Site.h +++ b/cpp_to_py/common/db/Site.h @@ -1,5 +1,10 @@ #pragma once +#include + namespace db { + +using std::string; + class Site { private: string _name = ""; diff --git a/cpp_to_py/common/db/SiteMap.cpp b/cpp_to_py/common/db/SiteMap.cpp index 5f2ada4..aa0c4dc 100644 --- a/cpp_to_py/common/db/SiteMap.cpp +++ b/cpp_to_py/common/db/SiteMap.cpp @@ -1,4 +1,9 @@ -#include "Database.h" +#include "SiteMap.h" + +#include "DatabaseClass.h" +#include "Region.h" +#include "common/utils/utils.h" + using namespace db; /***** SiteMap *****/ @@ -10,6 +15,18 @@ void SiteMap::initSiteMap(unsigned nx, unsigned ny) { regions.resize(nx, vector(ny)); } +void SiteMap::setSiteMap(const unsigned x, const unsigned y, const unsigned char property) { + setBit(sites[x][y], property); +} + +void SiteMap::unsetSiteMap(const unsigned x, const unsigned y, const unsigned char property) { + unsetBit(sites[x][y], property); +} + +bool SiteMap::getSiteMap(const unsigned x, const unsigned y, const unsigned char property) const { + return (getBit(sites[x][y], property) == property); +} + void SiteMap::getSiteBound(int x, int y, int &lx, int &ly, int &hx, int &hy) const { lx = siteL + x * siteStepX; ly = siteB + y * siteStepY; diff --git a/cpp_to_py/common/db/SiteMap.h b/cpp_to_py/common/db/SiteMap.h index 7ba1011..2e08828 100644 --- a/cpp_to_py/common/db/SiteMap.h +++ b/cpp_to_py/common/db/SiteMap.h @@ -1,6 +1,11 @@ #pragma once +#include + namespace db { + +using std::vector; + class SiteMap { private: unsigned nx = 0; @@ -24,13 +29,9 @@ public: void initSiteMap(unsigned nx, unsigned ny); - void setSiteMap(const unsigned x, const unsigned y, const unsigned char property) { setBit(sites[x][y], property); } - inline void unsetSiteMap(const unsigned x, const unsigned y, const unsigned char property) { - unsetBit(sites[x][y], property); - } - inline bool getSiteMap(const unsigned x, const unsigned y, const unsigned char property) const { - return (getBit(sites[x][y], property) == property); - } + void setSiteMap(const unsigned x, const unsigned y, const unsigned char property); + void unsetSiteMap(const unsigned x, const unsigned y, const unsigned char property); + bool getSiteMap(const unsigned x, const unsigned y, const unsigned char property) const; unsigned char getSiteMap(int x, int y) const { return sites[x][y]; } void getSiteBound(int x, int y, int& lx, int& ly, int& hx, int& hy) const; diff --git a/cpp_to_py/common/db/Via.h b/cpp_to_py/common/db/Via.h index 52a7458..ca64660 100644 --- a/cpp_to_py/common/db/Via.h +++ b/cpp_to_py/common/db/Via.h @@ -1,8 +1,18 @@ #pragma once #include +#include +#include namespace db { + +using std::string; + +class Geometry; +class Via; +class ViaRule; +class ViaType; + class Via { public: int x; diff --git a/cpp_to_py/common/io/file_bkshf_db.cpp b/cpp_to_py/common/io/file_bkshf_db.cpp index 4754f62..902daf6 100644 --- a/cpp_to_py/common/io/file_bkshf_db.cpp +++ b/cpp_to_py/common/io/file_bkshf_db.cpp @@ -1,4 +1,16 @@ +#include +#include +#include +#include + +#include "common/db/BsRouteInfo.h" +#include "common/db/Cell.h" #include "common/db/Database.h" +#include "common/db/GCellGrid.h" +#include "common/db/Layer.h" +#include "common/db/Net.h" +#include "common/db/Pin.h" +#include "common/db/Row.h" using namespace db; @@ -463,7 +475,8 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) if (minRowXStep != bsData.siteWidth) { if (bsData.siteWidth % minRowXStep == 0) { logger.warning( - "estimated siteWidth %d is not equal to the min rowXStep %d, but is a multiple of min rowXStep. Set " + "estimated siteWidth %d is not equal to the min rowXStep %d, " + "but is a multiple of min rowXStep. Set " "estimated siteWidth as %d.", bsData.siteWidth, minRowXStep, @@ -471,7 +484,10 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) bsData.siteWidth = minRowXStep; } else { logger.error( - "estimated siteWidth %d is not equal to the minimum rowXStep %d.", bsData.siteWidth, minRowXStep); + "estimated siteWidth %d is not equal to the minimum rowXStep " + "%d.", + bsData.siteWidth, + minRowXStep); } } @@ -481,17 +497,17 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) if (bsData.format == "dac2012") { isDac2012 = true; nLayers = bsData.gridNZ; - this->gcellgrid.numX = {bsData.gridNX + 1}; - this->gcellgrid.numY = {bsData.gridNY + 1}; - this->gcellgrid.startX = {bsData.gridOriginX}; - this->gcellgrid.startY = {bsData.gridOriginY}; - this->gcellgrid.stepX = {bsData.tileW}; - this->gcellgrid.stepY = {bsData.tileH}; - this->bsRouteInfo.hasInfo = true; - this->bsRouteInfo.capV = std::move(bsData.capV); - this->bsRouteInfo.capH = std::move(bsData.capH); - this->bsRouteInfo.viaSpace = std::move(bsData.viaSpace); - this->bsRouteInfo.blockagePorosity = bsData.blockagePorosity; + this->gcellgrid->numX = {bsData.gridNX + 1}; + this->gcellgrid->numY = {bsData.gridNY + 1}; + this->gcellgrid->startX = {bsData.gridOriginX}; + this->gcellgrid->startY = {bsData.gridOriginY}; + this->gcellgrid->stepX = {bsData.tileW}; + this->gcellgrid->stepY = {bsData.tileH}; + this->bsRouteInfo->hasInfo = true; + this->bsRouteInfo->capV = std::move(bsData.capV); + this->bsRouteInfo->capH = std::move(bsData.capH); + this->bsRouteInfo->viaSpace = std::move(bsData.viaSpace); + this->bsRouteInfo->blockagePorosity = bsData.blockagePorosity; // this->grGrid.gcellNX = bsData.gridNX; // this->grGrid.gcellNY = bsData.gridNY; // this->grGrid.gcellL = bsData.gridOriginX; @@ -505,13 +521,15 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) // this->grGrid.viaSpacing = std::move(bsData.viaSpace); // this->grGrid.minPitch.resize(nLayers); // for (int i = 0; i < nLayers; i++) { - // this->grGrid.minPitch[i] = this->grGrid.minWireWidth[i] + this->grGrid.minWireSpacing[i]; + // this->grGrid.minPitch[i] = this->grGrid.minWireWidth[i] + + // this->grGrid.minWireSpacing[i]; // } } - // NOTE: ICCAD/DAC 2012 does not define trackPitch and the capacity of each GCell - // cannot be directly computed by tracks. We restore the bookshelf capacity value - // in Database::Others::capV(H) and will handle them in GRDatabase. + // NOTE: ICCAD/DAC 2012 does not define trackPitch and the capacity of each + // GCell cannot be directly computed by tracks. We restore the bookshelf + // capacity value in Database::Others::capV(H) and will handle them in + // GRDatabase. logger.info("parsing layers"); int defaultPitch = bsData.siteWidth; int defaultWidth = bsData.siteWidth / 2; @@ -519,8 +537,8 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) char m1direction = 'h'; // M1 Route layer, rIndex == 0 char m2direction = 'v'; // M2 Route layer, rIndex == 1 if ((nLayers > 1) && (bsData.format == "dac2012")) { - m1direction = (this->bsRouteInfo.capV[1] > 0) ? 'h' : 'v'; - m2direction = (this->bsRouteInfo.capV[1] > 0) ? 'v' : 'h'; + m1direction = (this->bsRouteInfo->capV[1] > 0) ? 'h' : 'v'; + m2direction = (this->bsRouteInfo->capV[1] > 0) ? 'v' : 'h'; } for (unsigned i = 0; i != nLayers; ++i) { Layer& layer = this->addLayer(string("M").append(std::to_string(i + 1)), 'r'); @@ -579,7 +597,8 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) direction = 'o'; break; case 'B': - // We temporarily use 'x' to represent pin direction B in Bookshelf + // We temporarily use 'x' to represent pin direction B in + // Bookshelf direction = 'x'; break; default: @@ -620,7 +639,8 @@ bool Database::readBSAux(const std::string& auxFile, const std::string& plFile) } else { string celltypename(bsData.typeName[typeID]); Cell* cell = this->addCell(bsData.cellName[i], this->getCellType(celltypename)); - // In Bookshelf, we don't need to consider the cell orient, set it as -1 + // In Bookshelf, we don't need to consider the cell orient, set it + // as -1 cell->place(bsData.cellX[i], bsData.cellY[i], -1); // cout<x<<","<y<fixed((bsData.cellFixed[i] == (char)1)); @@ -717,7 +737,8 @@ bool Database::readBSNodes(const std::string& file) { cType = tokens[3]; } // if (cWidth == 0 || cHeight == 0) { - // logger.warning("Node %s (Type %s) has irregular shape: width %d height %d.", + // logger.warning("Node %s (Type %s) has irregular shape: width + // %d height %d.", // cName.c_str(), // cType.c_str(), // cWidth, @@ -810,11 +831,14 @@ bool Database::readBSNets(const std::string& file) { pinY = bsData.typeHeight[typeID] * 0.5 + (double)atof(tokens[3].c_str()); /* if(tokens.size() >= 6){ - //pinX = (int)round(atof(tokens[4].c_str())*bsData.siteWidth); - //pinY = (int)round(atof(tokens[5].c_str())*bsData.siteWidth); - }else{ - pinX = bsData.typeWidth[typeID] * 0.5 + (int)round(atof(tokens[2].c_str())); - pinY = bsData.typeHeight[typeID] * 0.5 + (int)round(atof(tokens[3].c_str())); + //pinX = + (int)round(atof(tokens[4].c_str())*bsData.siteWidth); + //pinY = + (int)round(atof(tokens[5].c_str())*bsData.siteWidth); }else{ + pinX = bsData.typeWidth[typeID] * 0.5 + + (int)round(atof(tokens[2].c_str())); pinY = + bsData.typeHeight[typeID] * 0.5 + + (int)round(atof(tokens[3].c_str())); } */ string pinName = (tokens.size() < 7) ? "" : tokens[6]; @@ -953,7 +977,8 @@ bool Database::readBSRoute(const std::string& file) { bsData.tileH = atoi(tokens[2].c_str()); } else if (tokens[0] == "BlockagePorosity") { bsData.blockagePorosity = atof(tokens[1].c_str()); - // assert_msg(bsData.blockagePorosity == 0, "We haven't yet supported non-zero blockagePorosity"); + // assert_msg(bsData.blockagePorosity == 0, "We haven't yet + // supported non-zero blockagePorosity"); } else if (tokens[0] == "NumNiTerminals") { status = ReadingPinLayer; } else if (tokens[0] == "NumBlockageNodes") { @@ -994,7 +1019,8 @@ bool Database::readBSRoute(const std::string& file) { int ty = atoi(tokens[4].c_str()); int tz = atoi(tokens[5].c_str()); int cap = atoi(tokens[6].c_str()); - cout< +#include +#include +#include + +#include "common/db/BsRouteInfo.h" +#include "common/db/Cell.h" #include "common/db/Database.h" +#include "common/db/DatabaseClass.h" +#include "common/db/DesignRule.h" +#include "common/db/GCellGrid.h" +#include "common/db/Geometry.h" +#include "common/db/Layer.h" +#include "common/db/Net.h" +#include "common/db/Pin.h" +#include "common/db/Region.h" +#include "common/db/Row.h" +#include "common/db/SNet.h" +#include "common/db/Site.h" +#include "common/db/SiteMap.h" +#include "common/db/Via.h" // tcl have another definition of EXTERN #undef EXTERN @@ -349,7 +369,7 @@ bool Database::readDEFPG(const std::string& file) { } // snet->addShape(*layer, lx, ly, hx, hy); if ((layer->rIndex == 0 || layer->rIndex == 1) && direction == 'h') { - // db->powerNet.addRail(snet, lx, hx, fy); + // db->powerNet->addRail(snet, lx, hx, fy); } } } @@ -385,17 +405,20 @@ bool Database::writeComponents(std::ofstream& ofs) { std::ofstream& oss = ofs; #endif oss << " - " << cell->name() << " " << cell->ctype()->name << std::endl; - // ofs << " - " << cell->name() << " " << cell->ctype()->name << std::endl; + // ofs << " - " << cell->name() << " " << cell->ctype()->name << + // std::endl; if (cell->fixed()) { oss << " + FIXED ( " << cell->lx() << " " << cell->ly() << " ) " << getOrient(cell->orient()) << " ;" << std::endl; - // ofs << " + FIXED ( " << cell->lx() << " " << cell->ly() << " ) " + // ofs << " + FIXED ( " << cell->lx() << " " << cell->ly() << " + // ) " // << getOrient(cell->orient()) // << " ;" << std::endl; } else if (cell->placed()) { oss << " + PLACED ( " << cell->lx() << " " << cell->ly() << " ) " << getOrient(cell->orient()) << " ;" << std::endl; - // ofs << " + PLACED ( " << cell->lx() << " " << cell->ly() << " ) " + // ofs << " + PLACED ( " << cell->lx() << " " << cell->ly() << + // " ) " // << getOrient(cell->orient()) // << " ;" << std::endl; } else { @@ -463,7 +486,8 @@ bool Database::writeICCAD2017(const string& outputDef) { } logger.info("writing %s", outputDef.c_str()); - writeComponents(ofs); // just replace the information of components, while others keep remain. + writeComponents(ofs); // just replace the information of components, while + // others keep remain. ofs << "END DESIGN\n\n" << std::endl; @@ -620,7 +644,9 @@ bool Database::writeBuffer(std::ofstream& ofs, const string& line) { b += nw; } - ofs.write(_buffer, _bufferCapacity); // From _buffer write _bufferCapacity charcters to ostream + ofs.write(_buffer, + _bufferCapacity); // From _buffer write _bufferCapacity + // charcters to ostream _bufferSize = 0; } @@ -698,36 +724,36 @@ int readLefProp(lefrCallbackType_e c, lefiProp* prop, lefiUserData ud) { if (setting.EdgeSpacing) { dbdist = (int)round(microndist * db->LefConvertFactor); } - int type1_idx = db->edgetypes.getEdgeType(type1); - int type2_idx = db->edgetypes.getEdgeType(type2); + int type1_idx = db->edgetypes->getEdgeType(type1); + int type2_idx = db->edgetypes->getEdgeType(type2); if (type1_idx < 0) { - type1_idx = db->edgetypes.types.size(); - db->edgetypes.types.push_back(type1); + type1_idx = db->edgetypes->types.size(); + db->edgetypes->types.push_back(type1); } if (type2_idx < 0) { - type2_idx = db->edgetypes.types.size(); - db->edgetypes.types.push_back(type2); + type2_idx = db->edgetypes->types.size(); + db->edgetypes->types.push_back(type2); } - int numEdgeTypes = db->edgetypes.types.size(); - if (numEdgeTypes > (int)db->edgetypes.distTable.size()) { - db->edgetypes.distTable.resize(numEdgeTypes); + int numEdgeTypes = db->edgetypes->types.size(); + if (numEdgeTypes > (int)db->edgetypes->distTable.size()) { + db->edgetypes->distTable.resize(numEdgeTypes); } for (int i = 0; i < numEdgeTypes; i++) { - db->edgetypes.distTable[i].resize(numEdgeTypes, 0); + db->edgetypes->distTable[i].resize(numEdgeTypes, 0); } - db->edgetypes.distTable[type1_idx][type2_idx] = dbdist; - db->edgetypes.distTable[type2_idx][type1_idx] = dbdist; + db->edgetypes->distTable[type1_idx][type2_idx] = dbdist; + db->edgetypes->distTable[type2_idx][type1_idx] = dbdist; } if (buffer == ";") { break; } } // default edge type dist - for (unsigned i = 0; i < db->edgetypes.types.size(); i++) { - db->edgetypes.distTable[0][i] = 0; - db->edgetypes.distTable[i][0] = 0; + for (unsigned i = 0; i < db->edgetypes->types.size(); i++) { + db->edgetypes->distTable[0][i] = 0; + db->edgetypes->distTable[i][0] = 0; } } return 0; @@ -820,7 +846,8 @@ int readLefLayer(lefrCallbackType_e c, lefiLayer* leflayer, lefiUserData ud) { if (leflayer->lefiLayer::hasSpacingNumber()) { for (int i = 0; i < leflayer->lefiLayer::numSpacing(); i++) { - // spaceType: 0 -> minSpacing, 1 -> maxEOLSpace, 2 -> maxEOLSpaceParallelEdge + // spaceType: 0 -> minSpacing, 1 -> maxEOLSpace, 2 -> + // maxEOLSpaceParallelEdge int spaceType = 0; int spacing, width, within, parSpace, parWithin; spacing = lround(leflayer->lefiLayer::spacing(i) * convertFactor); @@ -1233,9 +1260,9 @@ int readLefMacro(lefrCallbackType_e c, lefiMacro* macro, lefiUserData ud) { string edgetype; ssedgetype >> edgeside >> edgetype; if (edgeside == "LEFT") { - celltype->edgetypeL = db->edgetypes.getEdgeType(edgetype); + celltype->edgetypeL = db->edgetypes->getEdgeType(edgetype); } else if (edgeside == "RIGHT") { - celltype->edgetypeR = db->edgetypes.getEdgeType(edgetype); + celltype->edgetypeR = db->edgetypes->getEdgeType(edgetype); } else if (edgeside == "BOTTOM") { static bool missBot = true; if (missBot) { @@ -1350,13 +1377,13 @@ int readDefGcellGrid(defrCallbackType_e c, defiGcellGrid* dgrid, defiUserData ud Database* db = (Database*)ud; const string macro(dgrid->macro()); if (macro == "X") { - db->gcellgrid.numX.emplace_back(dgrid->xNum()); - db->gcellgrid.stepX.emplace_back(dgrid->xStep()); - db->gcellgrid.startX.emplace_back(dgrid->x()); + db->gcellgrid->numX.emplace_back(dgrid->xNum()); + db->gcellgrid->stepX.emplace_back(dgrid->xStep()); + db->gcellgrid->startX.emplace_back(dgrid->x()); } else if (macro == "Y") { - db->gcellgrid.numY.emplace_back(dgrid->xNum()); - db->gcellgrid.stepY.emplace_back(dgrid->xStep()); - db->gcellgrid.startY.emplace_back(dgrid->x()); + db->gcellgrid->numY.emplace_back(dgrid->xNum()); + db->gcellgrid->stepY.emplace_back(dgrid->xStep()); + db->gcellgrid->startY.emplace_back(dgrid->x()); } return 0; } @@ -1500,10 +1527,12 @@ int readDefComponent(defrCallbackType_e c, defiComponent* co, defiUserData ud) { cell->fixed(true); if (co->placementOrient() % 2 == 1) { // 0:N, 1:W, 2:S, 3:E, 4:FN, 5:FW, 6:FS, 7:FE, -1:NONE - logger.warning("Fixed Cell [%s]'s placementOrient [%s] is not supported, CLASS: %s.", - cell->name().c_str(), - getOrient(co->placementOrient()).c_str(), - celltype->cls.c_str()); + logger.warning( + "Fixed Cell [%s]'s placementOrient [%s] is not supported, " + "CLASS: %s.", + cell->name().c_str(), + getOrient(co->placementOrient()).c_str(), + celltype->cls.c_str()); } } return 0; @@ -1550,8 +1579,10 @@ int readDefPin(defrCallbackType_e c, defiPin* dpin, defiUserData ud) { for (int j = 0; j < dpin->numPorts(); j++) { if (j > 1) { string pinName(dpin->pinName()); - logger.warning("DefPin %s has multiple ports. We currently only support single port definition", - pinName.c_str()); + logger.warning( + "DefPin %s has multiple ports. We currently only support " + "single port definition", + pinName.c_str()); break; } defiPinPort* port = dpin->pinPort(j); @@ -1686,7 +1717,7 @@ int readDefSNet(defrCallbackType_e c, defiNet* dnet, defiUserData ud) { } snet->addShape(*layer, lx, ly, hx, hy); if ((layer->rIndex == 0 || layer->rIndex == 1) && fy == ty) { - db->powerNet.addRail(snet, lx, hx, fy); + db->powerNet->addRail(snet, lx, hx, fy); } fx = tx; fy = ty; @@ -1717,7 +1748,7 @@ int readDefSNet(defrCallbackType_e c, defiNet* dnet, defiUserData ud) { } snet->addShape(*layer, lx, ly, hx, hy); if ((layer->rIndex == 0 || layer->rIndex == 1) && fy == ty) { - db->powerNet.addRail(snet, lx, hx, fy); + db->powerNet->addRail(snet, lx, hx, fy); } fx = tx; fy = ty; @@ -1891,7 +1922,8 @@ int readDefRegion(defrCallbackType_e c, defiRegion* dreg, defiUserData ud) { } //-----Group----- -// #define GROUP_MARKER 9999999 //first mark all group member cell with this marker, then replace the value in one scan +// #define GROUP_MARKER 9999999 //first mark all group member cell with this +// marker, then replace the value in one scan int readDefGroupName(defrCallbackType_e c, const char* cl, defiUserData ud) { return 0; } int readDefGroupMember(defrCallbackType_e c, const char* cl, defiUserData ud) { diff --git a/cpp_to_py/common/io/file_verilog.cpp b/cpp_to_py/common/io/file_verilog.cpp index 1db5448..039f89f 100644 --- a/cpp_to_py/common/io/file_verilog.cpp +++ b/cpp_to_py/common/io/file_verilog.cpp @@ -1,4 +1,8 @@ +#include "common/db/Cell.h" #include "common/db/Database.h" +#include "common/db/Layer.h" +#include "common/db/Net.h" +#include "common/db/Pin.h" using namespace db; @@ -135,7 +139,7 @@ bool Database::readVerilog(const std::string &file) { if (!iopin) { logger.error("io pin not found: %s", pinName.c_str()); } - Pin* pin = iopin->pin; + Pin *pin = iopin->pin; iopin->is_connected = true; Net *net = addNet(pinName); diff --git a/cpp_to_py/draw_placement/CMakeLists.txt b/cpp_to_py/draw_placement/CMakeLists.txt index 67e836e..c8ba0a1 100644 --- a/cpp_to_py/draw_placement/CMakeLists.txt +++ b/cpp_to_py/draw_placement/CMakeLists.txt @@ -10,6 +10,4 @@ target_compile_definitions(${TARGET_NAME} PRIVATE TORCH_MINOR_VERSION=${TORCH_MINOR_VERSION} ENABLE_CUDA=0) -install(TARGETS - ${TARGET_NAME} - DESTINATION ${XPLACE_LIB_DIR}) \ No newline at end of file +install(TARGETS ${TARGET_NAME} DESTINATION ${XPLACE_LIB_DIR}) \ No newline at end of file diff --git a/cpp_to_py/gpudp/CMakeLists.txt b/cpp_to_py/gpudp/CMakeLists.txt index bcd5eab..4d5e815 100644 --- a/cpp_to_py/gpudp/CMakeLists.txt +++ b/cpp_to_py/gpudp/CMakeLists.txt @@ -8,30 +8,27 @@ file(GLOB_RECURSE SRC_FILES_DP_CUDA ${CMAKE_CURRENT_SOURCE_DIR}/*.cu) # OpenMP find_package(OpenMP REQUIRED) -# CUDA DP Kernel -cuda_add_library(dp_cuda_tmp STATIC ${SRC_FILES_DP_CUDA}) +# CUDA/CPP DP Kernel +add_library(dp STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../io_parser/gp/GPDatabase.cpp + ${SRC_FILES_DP} + ${SRC_FILES_DP_CUDA}) -set_target_properties(dp_cuda_tmp PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) -set_target_properties(dp_cuda_tmp PROPERTIES CUDA_SEPARABLE_COMPILATION ON) -set_target_properties(dp_cuda_tmp PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_target_properties(dp PROPERTIES + CUDA_RESOLVE_DEVICE_SYMBOLS ON + POSITION_INDEPENDENT_CODE ON) -target_include_directories(dp_cuda_tmp PRIVATE ${PROJECT_SOURCE_DIR}/cpp_to_py ${TORCH_INCLUDE_DIRS} ${FLUTE_INCLUDE_DIR}) -target_link_libraries(dp_cuda_tmp torch ${TORCH_PYTHON_LIBRARY} xplace_common flute OpenMP::OpenMP_CXX) - -# CPU DP object -add_library(dp SHARED ${CMAKE_CURRENT_SOURCE_DIR}/../io_parser/gp/GPDatabase.cpp - ${SRC_FILES_DP} - ${SRC_FILES_DP_CUDA}) - -target_include_directories(dp PRIVATE ${PROJECT_SOURCE_DIR}/cpp_to_py ${TORCH_INCLUDE_DIRS} ${FLUTE_INCLUDE_DIR}) -target_link_libraries(dp PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common flute dp_cuda_tmp pthread CUDA::curand) +target_include_directories(dp PRIVATE ${TORCH_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/cpp_to_py) +target_link_libraries(dp PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common OpenMP::OpenMP_CXX pthread CUDA::curand) target_compile_options(dp PRIVATE -fPIC) -install(TARGETS dp DESTINATION ${XPLACE_LIB_DIR}) +pybind11_add_module(gpudp MODULE PyBindCppMain.cpp) -# For Pybind -add_pytorch_extension(gpudp PyBindCppMain.cpp - EXTRA_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/cpp_to_py ${FLUTE_INCLUDE_DIR} - EXTRA_LINK_LIBRARIES xplace_common flute io_parser dp) +target_include_directories(gpudp PRIVATE ${TORCH_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/cpp_to_py) +target_link_libraries(gpudp PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common io_parser dp) +target_compile_definitions(gpudp PRIVATE + TORCH_EXTENSION_NAME=gpudp + TORCH_VERSION_MAJOR=${TORCH_VERSION_MAJOR} + TORCH_VERSION_MINOR=${TORCH_VERSION_MINOR} + ENABLE_CUDA=${TORCH_ENABLE_CUDA}) install(TARGETS gpudp DESTINATION ${XPLACE_LIB_DIR}) diff --git a/cpp_to_py/gpudp/db/dp_torch.h b/cpp_to_py/gpudp/db/dp_torch.h index e0ce4d2..f9d5df3 100644 --- a/cpp_to_py/gpudp/db/dp_torch.h +++ b/cpp_to_py/gpudp/db/dp_torch.h @@ -2,7 +2,10 @@ #include #include "common/common.h" -#include "common/db/Database.h" + +namespace db { +class Database; +} namespace dp { diff --git a/cpp_to_py/gpudp/dp/detailed_place_db.cuh b/cpp_to_py/gpudp/dp/detailed_place_db.cuh index d8e2705..285f808 100644 --- a/cpp_to_py/gpudp/dp/detailed_place_db.cuh +++ b/cpp_to_py/gpudp/dp/detailed_place_db.cuh @@ -4,7 +4,6 @@ #include #include "common/common.h" -#include "common/db/Database.h" #include "gpudp/db/dp_torch.h" #include "pitch_nested_vector.cuh" #include "utils.cuh" diff --git a/cpp_to_py/gpudp/lg/legalization_db.h b/cpp_to_py/gpudp/lg/legalization_db.h index e9ff209..e85856e 100644 --- a/cpp_to_py/gpudp/lg/legalization_db.h +++ b/cpp_to_py/gpudp/lg/legalization_db.h @@ -1,7 +1,6 @@ #pragma once #include "common/common.h" -#include "common/db/Database.h" #include "gpudp/db/dp_torch.h" namespace dp { diff --git a/cpp_to_py/gpugr/CMakeLists.txt b/cpp_to_py/gpugr/CMakeLists.txt index 8877e11..e7c9450 100644 --- a/cpp_to_py/gpugr/CMakeLists.txt +++ b/cpp_to_py/gpugr/CMakeLists.txt @@ -3,67 +3,29 @@ file(GLOB_RECURSE SRC_FILES_GGR ${CMAKE_CURRENT_SOURCE_DIR}/db/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gr/*.cpp) file(GLOB_RECURSE SRC_FILES_GGR_CUDA ${CMAKE_CURRENT_SOURCE_DIR}/*.cu) -# CUDA GGR Kernel -cuda_add_library(ggr_cuda_tmp STATIC ${SRC_FILES_GGR_CUDA}) - -set_target_properties(ggr_cuda_tmp PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) -set_target_properties(ggr_cuda_tmp PROPERTIES CUDA_SEPARABLE_COMPILATION ON) -set_target_properties(ggr_cuda_tmp PROPERTIES POSITION_INDEPENDENT_CODE ON) - -target_include_directories(ggr_cuda_tmp PRIVATE ${PROJECT_SOURCE_DIR}/cpp_to_py ${TORCH_INCLUDE_DIRS} ${FLUTE_INCLUDE_DIR}) -target_link_libraries(ggr_cuda_tmp torch ${TORCH_PYTHON_LIBRARY} xplace_common flute) -# target_compile_options(ggr_cuda_tmp PRIVATE "$<$:SHELL:-use_fast_math>") # not work... - - -# CPU GGR object -add_library(ggr SHARED ${CMAKE_CURRENT_SOURCE_DIR}/../io_parser/gp/GPDatabase.cpp +# CUDA/CPP GGR Kernel +add_library(ggr STATIC ${CMAKE_CURRENT_SOURCE_DIR}/../io_parser/gp/GPDatabase.cpp ${SRC_FILES_GGR} ${SRC_FILES_GGR_CUDA}) -target_include_directories(ggr PRIVATE ${PROJECT_SOURCE_DIR}/cpp_to_py ${TORCH_INCLUDE_DIRS} ${FLUTE_INCLUDE_DIR}) -target_link_libraries(ggr PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common flute ggr_cuda_tmp pthread) +set_target_properties(ggr PROPERTIES + CUDA_RESOLVE_DEVICE_SYMBOLS ON + POSITION_INDEPENDENT_CODE ON) + +target_include_directories(ggr PRIVATE ${TORCH_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/cpp_to_py ${FLUTE_INCLUDE_DIR}) +target_link_libraries(ggr PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common flute pthread) target_compile_options(ggr PRIVATE -fPIC) +target_compile_options(ggr PRIVATE "$<$:--extended-lambda>") -install(TARGETS ggr DESTINATION ${XPLACE_LIB_DIR}) +pybind11_add_module(gpugr MODULE PyBindCppMain.cpp) + +target_include_directories(gpugr PRIVATE ${TORCH_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/cpp_to_py ${FLUTE_INCLUDE_DIR}) +target_link_libraries(gpugr PRIVATE torch ${TORCH_PYTHON_LIBRARY} xplace_common flute io_parser ggr) +target_compile_definitions(gpugr PRIVATE + TORCH_EXTENSION_NAME=gpugr + TORCH_VERSION_MAJOR=${TORCH_VERSION_MAJOR} + TORCH_VERSION_MINOR=${TORCH_VERSION_MINOR} + ENABLE_CUDA=${TORCH_ENABLE_CUDA}) -# For Pybind -add_pytorch_extension(gpugr PyBindCppMain.cpp - EXTRA_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/cpp_to_py ${FLUTE_INCLUDE_DIR} - EXTRA_LINK_LIBRARIES xplace_common flute io_parser ggr) install(TARGETS gpugr DESTINATION ${XPLACE_LIB_DIR}) - -################ For debug only ################## - -# set(CMAKE_BUILD_TYPE Release) -# set(CMAKE_CXX_STANDARD 17) -# set(CMAKE_CUDA17_EXTENSION_COMPILE_OPTION "-std=c++17") -# set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch sm_86 --extended-lambda --use_fast_math ") -# project(ggr LANGUAGES C CXX CUDA) - -# file(GLOB_RECURSE SRC_FILES_GR2 ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -# file(GLOB_RECURSE SRC_FILES_GR2_CUDA ${CMAKE_CURRENT_SOURCE_DIR}/*.cu) - -# add_executable(gpugr_cpp PyBindCppMain.cpp -# ${CMAKE_CURRENT_SOURCE_DIR}/../io_parser/gp/GPDatabase.cpp -# ${SRC_FILES_GR2} -# ${SRC_FILES_GR2_CUDA}) - -# set_target_properties(gpugr_cpp PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) -# set_target_properties(gpugr_cpp PROPERTIES CUDA_SEPARABLE_COMPILATION ON) -# set_target_properties(gpugr_cpp PROPERTIES LINK_FLAGS "-Wl,--whole-archive -rdynamic -lpthread -Wl,--no-whole-archive") - -# target_include_directories( -# gpugr_cpp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/.. ${PROJECT_SOURCE_DIR}/cpp_to_py ${FLUTE_INCLUDE_DIR} ${TORCH_INCLUDE_DIRS}) -# target_link_libraries( -# gpugr_cpp PRIVATE torch ${TORCH_PYTHON_LIBRARY} flute xplace_common) - -# target_compile_options(gpugr_cpp PRIVATE $<$: -# -arch=sm_86 -# --use_fast_math -# -std=c++17 -# >) - -# install(TARGETS -# gpugr_cpp -# DESTINATION ${XPLACE_LIB_DIR}) \ No newline at end of file diff --git a/cpp_to_py/gpugr/PyBindCppMain.cpp b/cpp_to_py/gpugr/PyBindCppMain.cpp index b2393c4..23f1be6 100644 --- a/cpp_to_py/gpugr/PyBindCppMain.cpp +++ b/cpp_to_py/gpugr/PyBindCppMain.cpp @@ -1,5 +1,6 @@ #include "common/common.h" #include "common/db/Database.h" +#include "io_parser/gp/GPDatabase.h" #include "gpugr/db/GRDatabase.h" #include "gpugr/gr/RouteForce.h" #include "flute.h" diff --git a/cpp_to_py/gpugr/db/GRDatabase.cpp b/cpp_to_py/gpugr/db/GRDatabase.cpp index ae62631..473e6bc 100644 --- a/cpp_to_py/gpugr/db/GRDatabase.cpp +++ b/cpp_to_py/gpugr/db/GRDatabase.cpp @@ -1,5 +1,16 @@ #include "GRDatabase.h" +#include "common/db/BsRouteInfo.h" +#include "common/db/Cell.h" +#include "common/db/Database.h" +#include "common/db/Layer.h" +#include "common/db/GCellGrid.h" +#include "common/db/Net.h" +#include "common/db/Pin.h" +#include "common/db/SNet.h" +#include "common/db/Via.h" +#include "io_parser/gp/GPDatabase.h" + namespace gr { GRDatabase::~GRDatabase() { logger.info("destruct grdb"); } @@ -67,9 +78,9 @@ GRDatabase::GRDatabase(std::shared_ptr rawdb_, std::shared_ptrnumX.size() || !gcellgrid->numY.size()) { if (grSetting.routeXSize <= 0 || grSetting.routeYSize <= 0) { grSetting.routeXSize = 512; grSetting.routeYSize = 512; @@ -77,16 +88,16 @@ GRDatabase::GRDatabase(std::shared_ptr rawdb_, std::shared_ptrnumX.size(); idx++) { + for (int i = 1; i < gcellgrid->numX[idx]; i++) { + gridlines[0].emplace_back(gcellgrid->startX[idx] + i * gcellgrid->stepX[idx]); } } gridlines[1].emplace_back(0); - for (int idx = 0; idx < gcellgrid.numY.size(); idx++) { - for (int i = 1; i < gcellgrid.numY[idx]; i++) { - gridlines[1].emplace_back(gcellgrid.startY[idx] + i * gcellgrid.stepY[idx]); + for (int idx = 0; idx < gcellgrid->numY.size(); idx++) { + for (int i = 1; i < gcellgrid->numY[idx]; i++) { + gridlines[1].emplace_back(gcellgrid->startY[idx] + i * gcellgrid->stepY[idx]); } } } else { @@ -109,16 +120,16 @@ GRDatabase::GRDatabase(std::shared_ptr rawdb_, std::shared_ptrnumX.size(); idx++) { + if (largeNumX < gcellgrid->numX[idx]) { + largeNumX = gcellgrid->numX[idx]; + mainGcellStepX = gcellgrid->stepX[idx]; } } - for (int idx = 0; idx < gcellgrid.numY.size(); idx++) { - if (largeNumY < gcellgrid.numY[idx]) { - largeNumY = gcellgrid.numY[idx]; - mainGcellStepY = gcellgrid.stepY[idx]; + for (int idx = 0; idx < gcellgrid->numY.size(); idx++) { + if (largeNumY < gcellgrid->numY[idx]) { + largeNumY = gcellgrid->numY[idx]; + mainGcellStepY = gcellgrid->stepY[idx]; } } } else { @@ -191,7 +202,7 @@ void GRDatabase::setupCapacity() { void GRDatabase::setupCapacityBookshelf() { capacity.resize(gridGraphSize, 0); for (int i = 0; i < nLayers; i++) { - int oricap = std::max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); + int oricap = std::max(rawdb.bsRouteInfo->capH[i], rawdb.bsRouteInfo->capV[i]); float cap = oricap / (layerPitch[i]); if ((i & 1) ^ m1direction) { for (int j = 0; j < xSize; j++) { @@ -608,7 +619,7 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, std::vector layer2oricap(nLayers, 0.0); for (int i = 0; i < nLayers; i++) { - int oricap = std::max(rawdb.bsRouteInfo.capH[i], rawdb.bsRouteInfo.capV[i]); + int oricap = std::max(rawdb.bsRouteInfo->capH[i], rawdb.bsRouteInfo->capV[i]); float cap = oricap / (layerPitch[i]); layer2oricap[i] = oricap; } @@ -695,7 +706,7 @@ void GRDatabase::markObsBookShelf(std::vector& allObs, ovlpLen = buf[0].range(); } // Follow perl script dac2012_evaluate_solution.pl - float blocked = floor((float)ovlpLen * (1.0 - rawdb.bsRouteInfo.blockagePorosity)); + float blocked = floor((float)ovlpLen * (1.0 - rawdb.bsRouteInfo->blockagePorosity)); float availableSpace = ((float)gridIntvl.range() - blocked) / (float)gridIntvl.range(); int adjustedCap = layer2oricap[l] * availableSpace; adjustedCap = std::max(0, adjustedCap); diff --git a/cpp_to_py/gpugr/db/GRDatabase.h b/cpp_to_py/gpugr/db/GRDatabase.h index 7f4f501..e2d0e24 100644 --- a/cpp_to_py/gpugr/db/GRDatabase.h +++ b/cpp_to_py/gpugr/db/GRDatabase.h @@ -1,9 +1,15 @@ #pragma once -#include "GRSetting.h" #include "GrNet.h" #include "common/common.h" -#include "common/db/Database.h" -#include "io_parser/gp/GPDatabase.h" +#include "GRSetting.h" + +namespace db { +class Database; +class Cell; +} +namespace gp { +class GPDatabase; +} namespace gr { diff --git a/cpp_to_py/gpugr/gr/RouteForce.cpp b/cpp_to_py/gpugr/gr/RouteForce.cpp index 91f244e..a288ebf 100644 --- a/cpp_to_py/gpugr/gr/RouteForce.cpp +++ b/cpp_to_py/gpugr/gr/RouteForce.cpp @@ -1,4 +1,7 @@ #include "RouteForce.h" +#include "common/db/Database.h" +#include "io_parser/gp/GPDatabase.h" +#include "gpugr/db/GRDatabase.h" namespace gr { diff --git a/cpp_to_py/gpugr/gr/RouteForce.h b/cpp_to_py/gpugr/gr/RouteForce.h index 2528de6..0bb6f9a 100644 --- a/cpp_to_py/gpugr/gr/RouteForce.h +++ b/cpp_to_py/gpugr/gr/RouteForce.h @@ -1,9 +1,11 @@ #pragma once #include "common/common.h" -#include "common/db/Database.h" -#include "gpugr/db/GRDatabase.h" #include "gpugr/gr/GPURouter.h" +namespace gr { +class GRDatabase; +} + namespace gr { class RouteForce { diff --git a/cpp_to_py/io_parser/BindHelper.cpp b/cpp_to_py/io_parser/BindHelper.cpp index a6960b3..af9fe2b 100644 --- a/cpp_to_py/io_parser/BindHelper.cpp +++ b/cpp_to_py/io_parser/BindHelper.cpp @@ -1,4 +1,6 @@ #include "BindHelper.h" +#include "common/db/Database.h" +#include "io_parser/gp/GPDatabase.h" namespace Xplace { diff --git a/cpp_to_py/io_parser/BindHelper.h b/cpp_to_py/io_parser/BindHelper.h index 18d5aae..9d23ce1 100644 --- a/cpp_to_py/io_parser/BindHelper.h +++ b/cpp_to_py/io_parser/BindHelper.h @@ -1,8 +1,5 @@ #pragma once #include "common/common.h" -#include "common/db/Database.h" -#include "io_parser/gp/GPDatabase.h" - #include #include #include diff --git a/cpp_to_py/io_parser/PyBindCppMain.cpp b/cpp_to_py/io_parser/PyBindCppMain.cpp index dcc00a4..53cdc56 100644 --- a/cpp_to_py/io_parser/PyBindCppMain.cpp +++ b/cpp_to_py/io_parser/PyBindCppMain.cpp @@ -1,4 +1,6 @@ #include "BindHelper.h" +#include "common/db/Database.h" +#include "io_parser/gp/GPDatabase.h" namespace Xplace { diff --git a/cpp_to_py/io_parser/gp/GPDatabase.cpp b/cpp_to_py/io_parser/gp/GPDatabase.cpp index 9597dff..0dab4de 100644 --- a/cpp_to_py/io_parser/gp/GPDatabase.cpp +++ b/cpp_to_py/io_parser/gp/GPDatabase.cpp @@ -1,5 +1,15 @@ #include "GPDatabase.h" +#include "common/db/Cell.h" +#include "common/db/Database.h" +#include "common/db/Layer.h" +#include "common/db/Net.h" +#include "common/db/Pin.h" +#include "common/db/Region.h" +#include "common/db/Row.h" +#include "common/db/SNet.h" +#include "common/db/Via.h" + namespace gp { GPDatabase::~GPDatabase() { logger.info("destruct gpdb"); } @@ -364,7 +374,6 @@ orient_type rotate_180_orient(orient_type orient) { orient_type vflip_orient(orient_type orient) { return hflip_orient(rotate_180_orient(orient)); } - void GPDatabase::transferOrient() { // Transfer all gpdb nodes to "N" direction for global placement // NOTE: we don't change rawdb @@ -592,6 +601,8 @@ void GPDatabase::setup_random_place() { } } +const int GPDatabase::getM1Direction() const { return database.getRLayer(0)->direction == 'v' ? 1 : 0; } + // Torch Related torch::Tensor GPDatabase::getNodeLPosTensor() { torch::Tensor node_lpos = torch::zeros({num_nodes, 2}); diff --git a/cpp_to_py/io_parser/gp/GPDatabase.h b/cpp_to_py/io_parser/gp/GPDatabase.h index 44a212f..559c9b4 100644 --- a/cpp_to_py/io_parser/gp/GPDatabase.h +++ b/cpp_to_py/io_parser/gp/GPDatabase.h @@ -1,7 +1,12 @@ #pragma once #include #include "common/common.h" -#include "common/db/Database.h" + +namespace db { +class Database; +class Pin; +class PinType; +} namespace gp { @@ -210,7 +215,7 @@ public: const std::tuple& getCoreInfo() const { return coreInfo; } const int getSiteWidth() const { return siteW; } const int getSiteHeight() const { return siteH; } - const int getM1Direction() const { return database.getRLayer(0)->direction == 'v' ? 1 : 0; } + const int getM1Direction() const; // Torch related torch::Tensor getNodeLPosTensor(); diff --git a/cpp_to_py/routedp/PyBindCppMain.cpp b/cpp_to_py/routedp/PyBindCppMain.cpp index 6d151e8..44a68b8 100644 --- a/cpp_to_py/routedp/PyBindCppMain.cpp +++ b/cpp_to_py/routedp/PyBindCppMain.cpp @@ -1,7 +1,10 @@ #include #include "common/common.h" #include "common/db/Database.h" -#include "flute.h" +#include "common/db/Geometry.h" +#include "common/db/Layer.h" +#include "common/db/SNet.h" +#include "common/db/Via.h" #include "io_parser/gp/GPDatabase.h" namespace routedp { diff --git a/thirdparty/flute/CMakeLists.txt b/thirdparty/flute/CMakeLists.txt index eed89b5..39cb9c4 100644 --- a/thirdparty/flute/CMakeLists.txt +++ b/thirdparty/flute/CMakeLists.txt @@ -29,7 +29,7 @@ ## USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ################################################################################ -CMAKE_MINIMUM_REQUIRED (VERSION 3.1) +CMAKE_MINIMUM_REQUIRED (VERSION 3.18) PROJECT(flute) SET(CMAKE_CXX_STANDARD 11) diff --git a/thirdparty/pybind11 b/thirdparty/pybind11 index 128d988..83b92ce 160000 --- a/thirdparty/pybind11 +++ b/thirdparty/pybind11 @@ -1 +1 @@ -Subproject commit 128d988ef183cfb6334714f0bcf8b8e7b7e2e95b +Subproject commit 83b92ceb3537666fb0188f564e1d53bf8c80b0ba