├── LICENSE
├── README.md
├── cpp
├── CMakeLists.txt
└── src
│ ├── api
│ └── api.cpp
│ ├── db
│ ├── cstr
│ │ ├── dbNetPrioCstr.hpp
│ │ ├── dbPlaceAlignCstr.hpp
│ │ ├── dbPlaceArrayCstr.hpp
│ │ ├── dbPlaceClusterCstr.hpp
│ │ ├── dbPlaceDisjointCstr.hpp
│ │ ├── dbPlaceEdgeDistCstr.hpp
│ │ ├── dbPlaceExtCstr.hpp
│ │ ├── dbPlaceOrderCstr.hpp
│ │ ├── dbPlaceRowCstr.hpp
│ │ ├── dbPlaceSymCstr.hpp
│ │ ├── dbPrePlaceCstr.hpp
│ │ ├── dbRoutePathMatchCstr.hpp
│ │ └── dbRouteSymCstr.hpp
│ ├── dbBasic.cpp
│ ├── dbBasic.hpp
│ ├── dbCell.cpp
│ ├── dbCell.hpp
│ ├── dbCir.cpp
│ ├── dbCir.hpp
│ ├── dbDevMap.hpp
│ ├── dbGrid.hpp
│ ├── dbLayer.cpp
│ ├── dbLayer.hpp
│ ├── dbNet.cpp
│ ├── dbNet.hpp
│ ├── dbObs.hpp
│ ├── dbPin.hpp
│ ├── dbPrim.hpp
│ ├── dbRegion.hpp
│ └── dbVia.hpp
│ ├── drc
│ ├── drcMgr.cpp
│ └── drcMgr.hpp
│ ├── ds
│ ├── array2d.hpp
│ ├── array3d.hpp
│ ├── disjointSet.hpp
│ ├── hash.hpp
│ └── pqueue.hpp
│ ├── geo
│ ├── box.hpp
│ ├── box2polygon.hpp
│ ├── geometry.hpp
│ ├── interval.hpp
│ ├── kdTree.hpp
│ ├── point.hpp
│ ├── point3d.hpp
│ ├── polygon.hpp
│ ├── polygon2box.hpp
│ ├── segment.hpp
│ ├── segment3d.hpp
│ ├── spatial.hpp
│ └── spatial3d.hpp
│ ├── global
│ ├── define.hpp
│ ├── global.hpp
│ ├── namespace.hpp
│ └── type.hpp
│ ├── graph
│ └── mst.hpp
│ ├── io
│ ├── parGds.cpp
│ ├── parGds.hpp
│ ├── parHspice.cpp
│ ├── parHspice.hpp
│ ├── parLef.cpp
│ ├── parLef.hpp
│ ├── parser.cpp
│ └── parser.hpp
│ ├── main
│ └── main.cpp
│ ├── place
│ ├── placeMgr.cpp
│ ├── placeMgr.hpp
│ ├── placeSMT.cpp
│ └── placeSMT.hpp
│ ├── rl
│ ├── rlUtil.cpp
│ └── rlUtil.hpp
│ ├── route
│ ├── routeDrAstar.cpp
│ ├── routeDrAstar.hpp
│ ├── routeDrMgr.cpp
│ ├── routeDrMgr.hpp
│ ├── routeDrPS.cpp
│ ├── routeDrPS.hpp
│ ├── routeDrPost.cpp
│ ├── routeDrPost.hpp
│ ├── routeMgr.cpp
│ └── routeMgr.hpp
│ ├── thirdparty
│ └── spdlog.cpp
│ └── util
│ ├── util.cpp
│ └── util.hpp
└── python
├── main
├── __init__.py
├── config.yaml
├── main.py
├── rl_route_path_match_flat.py
├── rl_route_path_match_flat_group.py
└── rl_route_path_match_hier.py
└── rl
├── autocraft-rl
├── __init__.py
├── autocraft_rl
│ ├── __init__.py
│ ├── envs
│ │ ├── __init__.py
│ │ ├── ac_multicir_env.py
│ │ ├── ac_multicir_env_layer_match.py
│ │ ├── ac_multicir_env_match.py
│ │ ├── ac_multicir_env_path_match.py
│ │ ├── ac_multicir_env_path_match_group.py
│ │ └── ac_multicir_hier_env_path_match.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── ac_dqn_model.py
│ │ ├── ac_dqn_model_match.py
│ │ ├── ac_dqn_model_path.py
│ │ ├── ac_ppo_hier_model_path.py
│ │ ├── ac_ppo_model.py
│ │ ├── ac_ppo_model_match.py
│ │ ├── ac_ppo_model_path.py
│ │ └── ac_ppo_model_path_group.py
│ └── utils
│ │ ├── __init__.py
│ │ ├── callbacks.py
│ │ ├── callbacks_layer_match.py
│ │ ├── callbacks_match.py
│ │ ├── callbacks_path_match.py
│ │ ├── callbacks_path_match_group.py
│ │ ├── callbacks_path_match_group_hier.py
│ │ ├── helper.py
│ │ └── load_agent.py
└── setup.py
├── conf
├── arch
│ └── magic_array_dff_0.yaml
└── config.yaml
├── train.py
└── util
├── __init__.py
├── config.py
└── util.py
/LICENSE:
--------------------------------------------------------------------------------
1 | SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2 | SPDX-License-Identifier: Apache-2.0
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutoCRAFT: Layout Automation for Custom Circuits in Advanced FinFET Technologies
2 |
3 | AutoCRAFT is a semi-automated custom layout framework to improve the productivity of analog and high-speed custom digital circuit layout implementation.
4 | AutoCRAFT has been developed and tested on x64 linux machines.
5 |
6 | ## Modules Overview
7 | ```
8 | AutoCRAFT
9 | |---- Circuit
10 | | |---- Placement grid
11 | | |---- Routing grid
12 | | |---- Device mapping
13 | | |---- Primitive lib
14 | | |---- Region
15 | | |---- Cell
16 | | | |---- Pin
17 | | | |---- Obs (obstacle)
18 | | |---- Net
19 | | | |---- Pin
20 | | | |---- Via
21 | | | |---- Wire
22 | | | |---- TopoTree
23 | | | |---- Routable
24 | | |---- Layer
25 | | | |---- Metal layer
26 | | | |---- Cut layer
27 | | |---- Cstr (Constraint)
28 | | |---- Placement cstr
29 | | | |---- Net weighting
30 | | | |---- Array
31 | | | |---- Alignment (row/col)
32 | | | |---- Cluster
33 | | | |---- Disjoint (row/col)
34 | | | |---- Edge distance (to left/right/top/bottom boundaries)
35 | | | |---- Extension
36 | | | |---- Row (odd/even)
37 | | | |---- Symmetry
38 | | | |---- Pre-placed cell
39 | | |---- Routing cstr
40 | | |---- Symmetry
41 | | |---- Path matching (developing)
42 | |---- Placer
43 | | |---- SMT placer
44 | |---- Router
45 | | |---- Global routing manager (deprecated)
46 | | |---- Detailed routing manager
47 | | | |---- Path searching detailed router
48 | | |---- Post routing
49 | |---- I/O
50 | |---- Parser
51 | | |---- LEF primitive templates parser
52 | | |---- Hspice netlist parser
53 | | |---- Grid file parser
54 | | |---- Constraint file parser
55 |
56 | ```
57 |
58 | ## Dependencies
59 | * [CMake](https://cmake.org) >= 3.14.0
60 | * [pybind11](https://github.com/pybind/pybind11) >= 2.7.0 (Python 3.7/3.8)
61 | * [Boost](https://www.boost.org/) >= 1.6
62 | * [spdlog](https://github.com/gabime/spdlog)
63 | * [Limbo](https://github.com/limbo018/Limbo)
64 | * [phmap](https://github.com/greg7mdp/parallel-hashmap)
65 | * [z3](https://github.com/Z3Prover/z3) >= 4.8.11
66 | * [nanoflann](https://github.com/jlblancoc/nanoflann)
67 | * [lemon](https://lemon.cs.elte.hu/trac/lemon) >= 1.3.1
68 | * [zlib](https://github.com/madler/zlib)
69 | * [cxxopts](https://github.com/jarro2783/cxxopts) == 2.2.0
70 | * [lef/def](https://si2.org/oa-tools-utils-libs/) >= 5.8
71 |
72 | ## Installation
73 |
74 | Recommended GCC version: >= 8.3.0 (Tested on 8.3.0)
75 |
76 | ```sh
77 | mkdir -p cpp/build/ && cd cpp/build/
78 | cmake .. -DPYTHON_EXECUTABLE= -DPYTHON_LIBRARY=
79 | make
80 | ```
81 | A binary executable `autocraftE` and a python library `autocraft.cpython-3x-x86_64-linux-gnu.so` will be generated after compilation. Copy the file to your python site-packages path by
82 |
83 | ```sh
84 | cp autocraft.cpython-3x-x86_64-linux-gnu.so
85 | ```
86 |
87 | or put it under the path with the files importing `autocraft`.
88 |
89 |
90 | ## Usage
91 |
92 | Using the Python interface is recommended.
93 | The binary executable `autocraftE` can still be used for debugging purpose. Run
94 | ```sh
95 | autocraftE [OPTION...]
96 | --laygo_config= # laygo configuration (.yml)
97 | --tech_grid= # placement anf routing grids definition (.yml)
98 | --tech_map= # device-to-primitive mapping (.yml)
99 | --constraint= # constraint specification
100 | --lef= # primitive and via templates (.lef)
101 | --netlist= # spice netlist (.cir)
102 | --drc= # abstracted drc rules (.yml)
103 | --in_place= # placement input (optional)
104 | --out_place= # cells location after placement (optional)
105 | --out_gv= # gated verilog netlist output (optional)
106 | --out_tcl= # ICC2 Tcl commands output (optional)
107 | --threads= # number of CPU threads for placement (optional, not necessarily faster)
108 | --place_ar= # user-defined aspect ratio of the design area
109 | --place_ur= # user-defined utilization ratio of the design
110 | --place_ur_reg_name= # utilization ratio for some regions (should be used together with --place_ur_reg_val)
111 | --place_ur_reg_val= # utilization ratio values for some regions
112 | --place_bbox= # design bounding box
113 | --place_iter= # placemnt WL optimization iterations
114 | -h, --help # print usage
115 |
116 | Example:
117 | autocraftE --laygo_config=laygo_config.yaml \
118 | --tech_grid=dv5t_crg_fll_ana_obsd.grid.yaml \
119 | --tech_map=dv5t_crg_fll_ana_obsd.map.yaml \
120 | --constraint=dv5t_crg_fll_ana_obsd.constraint.yaml \
121 | --lef=dv5t_crg_fll_ana_obsd.template.lef,dv5t_crg_fll_ana_obsd.via.lef \
122 | --netlist=dv5t_crg_fll_ana_obsd.cir \
123 | --drc=layers.drc.yaml \
124 | --threads=1 \
125 | --place_ar=1.1 \
126 | --place_ur=0.4 \
127 | --place_ur_reg_name=region1 \
128 | --place_ur_reg_val=0.4 \
129 | --place_iter=2 \
130 | --out_gv=dv5t_crg_fll_ana_obsd.gv \
131 | --out_tcl=dv5t_crg_fll_ana_obsd_pnr.tcl
132 | ```
133 | to execute the program
134 |
135 |
--------------------------------------------------------------------------------
/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | #set(CMAKE_VERBOSE_MAKEFILE ON)
3 |
4 | set(PROJECT_NAME "autocraft")
5 | project(${PROJECT_NAME})
6 |
7 | set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
8 |
9 | #################################################
10 | # Dependencies #
11 | #################################################
12 | #pybind11
13 | if (PYBIND11_DIR)
14 | set(PYBIND11_ROOT_DIR ${PYBIND11_DIR})
15 | else()
16 | set(PYBIND11_ROOT_DIR $ENV{PYBIND11_DIR})
17 | endif()
18 | message(STATUS "pybind11: ${PYBIND11_ROOT_DIR}")
19 | unset(PYBIND11_DIR CACHE)
20 |
21 | add_subdirectory(${PYBIND11_ROOT_DIR} "./pybind11")
22 |
23 | # boost
24 | set(Boost_USE_STATIC_LIBS ON)
25 | find_package(Boost 1.6 REQUIRED COMPONENTS system graph)
26 |
27 | # Python
28 | find_package(PythonLibs REQUIRED)
29 |
30 |
31 | # yaml-cpp
32 | if (YAML_CPP_DIR)
33 | set(YAML_CPP_ROOT_DIR ${YAML_CPP_DIR})
34 | else()
35 | set(YAML_CPP_ROOT_DIR $ENV{YAML_CPP_DIR})
36 | endif()
37 | message(STATUS "yaml-cpp: ${YAML_CPP_ROOT_DIR}")
38 | unset(YAML_CPP_DIR CACHE)
39 |
40 | # z3
41 | #find_package(Z3 CONFIG REQUIRED)
42 | if (Z3_DIR)
43 | set(Z3_ROOT_DIR ${Z3_DIR})
44 | else()
45 | set(Z3_ROOT_DIR $ENV{Z3_DIR})
46 | endif()
47 | message(STATUS "z3: ${Z3_ROOT_DIR}")
48 | unset(Z3_DIR CACHE)
49 |
50 | # spdlog
51 | if (SPDLOG_DIR)
52 | set(SPDLOG_ROOT_DIR ${SPDLOG_DIR})
53 | else()
54 | set(SPDLOG_ROOT_DIR $ENV{SPDLOG_DIR})
55 | endif()
56 | message(STATUS "spdlog: ${SPDLOG_ROOT_DIR}")
57 | unset(SPDLOG_DIR CACHE)
58 |
59 | # phmap
60 | if (PHMAP_DIR)
61 | set(PHMAP_ROOT_DIR ${PHMAP_DIR})
62 | else()
63 | set(PHMAP_ROOT_DIR $ENV{PHMAP_DIR})
64 | endif()
65 | message(STATUS "phmap: ${PHMAP_ROOT_DIR}")
66 | unset(PHMAP_DIR CACHE)
67 |
68 | # nanoflann
69 | if (NANOFLANN_DIR)
70 | set(NANOFLANN_ROOT_DIR ${NANOFLANN_DIR})
71 | else()
72 | set(NANOFLANN_ROOT_DIR $ENV{NANOFLANN_DIR})
73 | endif()
74 | message(STATUS "nanoflann: ${NANOFLANN_ROOT_DIR}")
75 | unset(NANOFLANN_DIR CACHE)
76 |
77 | # limbo
78 | if (LIMBO_DIR)
79 | set(LIMBO_ROOT_DIR ${LIMBO_DIR})
80 | else()
81 | set(LIMBO_ROOT_DIR $ENV{LIMBO_DIR})
82 | endif()
83 | message(STATUS "limbo: ${LIMBO_ROOT_DIR}")
84 | unset(LIMBO_DIR CACHE)
85 |
86 | # lefdef
87 | if (LEF_DIR)
88 | set(LEF_ROOT_DIR ${LEF_DIR})
89 | else()
90 | set(LEF_ROOT_DIR $ENV{LEF_DIR})
91 | endif()
92 | message(STATUS "lef: ${LEF_ROOT_DIR}")
93 | unset(LEF_DIR CACHE)
94 | if (DEF_DIR)
95 | set(DEF_ROOT_DIR ${DEF_DIR})
96 | else()
97 | set(DEF_ROOT_DIR $ENV{DEF_DIR})
98 | endif()
99 | message(STATUS "def: ${DEF_ROOT_DIR}")
100 | unset(DEF_DIR CACHE)
101 |
102 | # lemon
103 | if (LEMON_DIR)
104 | set(LEMON_ROOT_DIR ${LEMON_DIR})
105 | else()
106 | set(LEMON_ROOT_DIR $ENV{LEMON_DIR})
107 | endif()
108 | message(STATUS "lemon: ${LEMON_ROOT_DIR}")
109 | unset(LEMON_DIR CACHE)
110 |
111 | # cxxopts
112 | if (CXXOPTS_DIR)
113 | set(CXXOPTS_ROOT_DIR ${CXXOPTS_DIR})
114 | else()
115 | set(CXXOPTS_ROOT_DIR $ENV{CXXOPTS_DIR})
116 | endif()
117 | message(STATUS "cxxopts: ${CXXOPTS_ROOT_DIR}")
118 | unset(CXXOPTS_DIR CACHE)
119 |
120 | # zlib
121 | if (ZLIB_DIR)
122 | set(ZLIB_ROOT_DIR ${ZLIB_DIR})
123 | else()
124 | set(ZLIB_ROOT_DIR $ENV{ZLIB_DIR})
125 | endif()
126 | message(STATUS "zlib: ${ZLIB_ROOT_DIR}")
127 | unset(ZLIB_DIR CACHE)
128 |
129 | #################################################
130 |
131 |
132 | # set(CMAKE_BUILD_TYPE Debug)
133 | set(CMAKE_BUILD_TYPE Release)
134 | message(STATUS "Using build type ${CMAKE_BUILD_TYPE}")
135 |
136 | set(CMAKE_CXX_FLAGS "-std=c++2a -Wall -fopenmp -fPIC -fconcepts -lz")
137 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -fno-inline")
138 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
139 | set(CMAKE_EXE_LINKER_FLAGS "-pthread")
140 |
141 | add_definitions(-DSPDLOG_COMPILED_LIB)
142 |
143 | #################################################
144 | # Include library path
145 | #################################################
146 | include_directories (
147 | ${CMAKE_CURRENT_SOURCE_DIR}/src
148 | ${SPDLOG_ROOT_DIR}/include
149 | ${YAML_CPP_ROOT_DIR}/include
150 | ${SPDLOG_ROOT_DIR}/include
151 | ${PHMAP_ROOT_DIR}/include
152 | ${NANOFLANN_ROOT_DIR}/include
153 | ${LIMBO_ROOT_DIR}/include
154 | ${LEF_ROOT_DIR}/include
155 | ${DEF_ROOT_DIR}/include
156 | ${Z3_ROOT_DIR}/include
157 | ${LEMON_ROOT_DIR}/include
158 | ${CXXOPTS_ROOT_DIR}/include
159 | )
160 |
161 | file(GLOB LIB
162 | ${SPDLOG_ROOT_DIR}/lib/libspdlog.a
163 | ${YAML_CPP_ROOT_DIR}/lib/libyaml-cpp.a
164 | ${LIMBO_ROOT_DIR}/lib/libgdsdb.a
165 | ${LIMBO_ROOT_DIR}/lib/libgdsparser.a
166 | ${LIMBO_ROOT_DIR}/lib/libgzstream.a
167 | ${LEF_ROOT_DIR}/lib/liblef.a
168 | ${DEF_ROOT_DIR}/lib/libdef.a
169 | ${Z3_ROOT_DIR}/lib/libz3.a
170 | ${LEMON_ROOT_DIR}/lib/libemon.a
171 | #${ZLIB_DIR}/lib/libz.a
172 | )
173 |
174 | link_libraries (
175 | ${PYTHON_LIBRARIES}
176 | )
177 |
178 |
179 | ###############################################
180 | # SRC
181 | ###############################################
182 | set(SRC
183 | src/thirdparty/spdlog.cpp
184 | src/util/util.cpp
185 | src/io/parser.cpp
186 | src/io/parHspice.cpp
187 | src/io/parLef.cpp
188 | src/io/parGds.cpp
189 | src/io/writer.cpp
190 | src/db/dbBasic.cpp
191 | src/db/dbCell.cpp
192 | src/db/dbCir.cpp
193 | src/db/dbNet.cpp
194 | src/db/dbLayer.cpp
195 | src/place/placeMgr.cpp
196 | src/place/placeSMT.cpp
197 | src/route/routeMgr.cpp
198 | # src/route/routeGrMgr.cpp
199 | src/route/routeDrMgr.cpp
200 | src/route/routeDrPS.cpp
201 | src/route/routeDrAstar.cpp
202 | src/route/routeDrPost.cpp
203 | src/drc/drcMgr.cpp
204 | src/rl/rlUtil.cpp
205 | )
206 |
207 | # executable
208 | add_executable(${PROJECT_NAME}E ${SRC} src/main/main.cpp)
209 | #target_link_libraries(${PROJECT_NAME}E PUBLIC Boost::system Boost::graph ${LIB} ortools::ortools z3::libz3)
210 | target_link_libraries(${PROJECT_NAME}E PUBLIC Boost::system Boost::graph ${LIB})
211 |
212 | # Add modules to pybind
213 | pybind11_add_module(${PROJECT_NAME} ${SRC} src/api/api.cpp)
214 | target_link_libraries(${PROJECT_NAME} PUBLIC ${Boost_LIBRARIES} ${LIB})
215 |
216 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbNetPrioCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbBasic.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class Net;
25 |
26 | class NetPrioCstr {
27 | friend class Parser;
28 |
29 | public:
30 | NetPrioCstr()
31 | : _idx(-1), _priority(0)
32 | {}
33 |
34 | const String& name() const { return _name; }
35 | Int idx() const { return _idx; }
36 |
37 | Net& net(const Int i) { return *_vpNets.at(i); }
38 | const Net& net(const Int i) const { return *_vpNets.at(i); }
39 | Net* pNet(const Int i) { return _vpNets.at(i); }
40 | const Net* pNet(const Int i) const { return _vpNets.at(i); }
41 | Vector& vpNets() { return _vpNets; }
42 | const Vector& vpNets() const { return _vpNets; }
43 | Int numNets() const { return _vpNets.size(); }
44 |
45 | Int priority() const { return _priority; }
46 |
47 | private:
48 | String _name;
49 | Int _idx;
50 |
51 | Vector _vpNets;
52 | Int _priority;
53 |
54 | };
55 |
56 | PROJECT_NAMESPACE_END
57 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceAlignCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 | #include "db/dbRegion.hpp"
22 | #include "db/cstr/dbPlaceArrayCstr.hpp"
23 |
24 | PROJECT_NAMESPACE_START
25 |
26 | class PlaceAlignCstr {
27 | friend class Parser;
28 |
29 | public:
30 | PlaceAlignCstr()
31 | : _idx(-1), _isHor(false), _isHigh(false)
32 | {}
33 | ~PlaceAlignCstr() {}
34 |
35 | const String& name() const { return _name; }
36 | Int idx() const { return _idx; }
37 |
38 | Cell& cell(const Int i) { return *_vpCells.at(i); }
39 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
40 | Cell* pCell(const Int i) { return _vpCells.at(i); }
41 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
42 | Vector& vpCells() { return _vpCells; }
43 | const Vector& vpCells() const { return _vpCells; }
44 | Int numCells() const { return _vpCells.size(); }
45 |
46 | Region& region(const Int i) { return *_vpRegions.at(i); }
47 | const Region& region(const Int i) const { return *_vpRegions.at(i); }
48 | Region* pRegion(const Int i) { return _vpRegions.at(i); }
49 | const Region* pRegion(const Int i) const { return _vpRegions.at(i); }
50 | Vector& vpRegions() { return _vpRegions; }
51 | const Vector& vpRegions() const { return _vpRegions; }
52 | Int numRegions() const { return _vpRegions.size(); }
53 |
54 | PlaceArrayCstr& placeArrayCstr(const Int i) { return *_vpArrays.at(i); }
55 | const PlaceArrayCstr& placeArrayCstr(const Int i) const { return *_vpArrays.at(i); }
56 | PlaceArrayCstr* pPlaceArrayCstr(const Int i) { return _vpArrays.at(i); }
57 | const PlaceArrayCstr* pPlaceArrayCstr(const Int i) const { return _vpArrays.at(i); }
58 | Vector& vpPlaceArrayCstrs() { return _vpArrays; }
59 | const Vector& vpPlaceArrayCstrs() const { return _vpArrays; }
60 | Int numPlaceArrayCstrs() const { return _vpArrays.size(); }
61 |
62 | bool isHor() const { return _isHor; }
63 | bool isVer() const { return !_isHor; }
64 |
65 | bool isHigh() const { return _isHigh; }
66 | bool isLow() const { return !_isHigh; }
67 |
68 |
69 | private:
70 | String _name;
71 | Int _idx;
72 | Vector _vpCells;
73 | Vector _vpRegions;
74 | Vector _vpArrays;
75 | bool _isHor;
76 | bool _isHigh;
77 | };
78 |
79 | PROJECT_NAMESPACE_END
80 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceArrayCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceArrayCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceArrayCstr() : _idx(-1), _col(0), _row(0), _size(0), _pattern(ArrayPatternE::undef) {}
29 | ~PlaceArrayCstr() {}
30 |
31 | const String& name() const { return _name; }
32 | Int idx() const { return _idx; }
33 |
34 | Int col() const { return _col; }
35 | Int row() const { return _row; }
36 | bool hasCol() const { return _col > 0; }
37 | bool hasRow() const { return _row > 0; }
38 |
39 | Int size() const { return _size; }
40 | bool hasSize() const { return _size > 0; }
41 | bool useAutoSize() const { return _size == 0; }
42 |
43 | ArrayPatternE pattern() const { return _pattern; }
44 | bool isID() const { return _pattern == ArrayPatternE::id; }
45 | bool isCC() const { return _pattern == ArrayPatternE::cc; }
46 | bool isCS() const { return _pattern == ArrayPatternE::cs; }
47 | bool hasPattern() const { return _pattern != ArrayPatternE::undef; }
48 |
49 | Cell& cell(const Int i) { return *_vpCells.at(i); }
50 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
51 | Cell* pCell(const Int i) { return _vpCells.at(i); }
52 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
53 | Vector& vpCells() { return _vpCells; }
54 | const Vector& vpCells() const { return _vpCells; }
55 | Int numCells() const { return _vpCells.size(); }
56 |
57 | ArrayPartE arrayPart(const Int i) const { return _vArrayPartEs.at(i); }
58 | ArrayPartE arrayPart(const Cell& c) const { return _vArrayPartEs.at(cellIdx2Idx(c.idx())); }
59 | bool isPartA(const Int i) const { return arrayPart(i) == ArrayPartE::a; }
60 | bool isPartA(const Cell& c) const { return arrayPart(c) == ArrayPartE::a; }
61 | bool isPartB(const Int i) const { return arrayPart(i) == ArrayPartE::b; }
62 | bool isPartB(const Cell& c) const { return arrayPart(c) == ArrayPartE::b; }
63 |
64 | Int cellIdx2Idx(const Int idx) const { return _mCellIdx2Idx.at(idx); }
65 |
66 | PlaceArrayCstr& placeArrayCstr(const Int i) { return *_vpArrays.at(i); }
67 | const PlaceArrayCstr& placeArrayCstr(const Int i) const { return *_vpArrays.at(i); }
68 | PlaceArrayCstr* pPlaceArrayCstr(const Int i) { return _vpArrays.at(i); }
69 | const PlaceArrayCstr* pPlaceArrayCstr(const Int i) const { return _vpArrays.at(i); }
70 | Vector& vpPlaceArrayCstrs() { return _vpArrays; }
71 | const Vector& vpPlaceArrayCstrs() const { return _vpArrays; }
72 | Int numPlaceArrayCstrs() const { return _vpArrays.size(); }
73 |
74 | Int arrayIdx2Idx(const Int idx) const { return _mArrayIdx2Idx.at(idx); }
75 | bool hasArray(const PlaceArrayCstr& arr) const { return _mArrayIdx2Idx.find(arr.idx()) != _mArrayIdx2Idx.end(); }
76 |
77 | const Region& region() const { return _vpCells.size() ? const_cast(_vpCells.at(0)->region()) : _vpArrays.at(0)->region(); }
78 | const Region* pRegion() const { return _vpCells.size() ? const_cast(_vpCells.at(0)->pRegion()) : _vpArrays.at(0)->pRegion(); }
79 |
80 | bool hasCell(const Cell& c) const {
81 | std::function
82 | hasCellImpl = [&] (const PlaceArrayCstr& ac, const Cell& c) -> bool {
83 | if (!ac._mCellIdx2Idx.empty()) {
84 | return ac._mCellIdx2Idx.find(c.idx()) != ac._mCellIdx2Idx.end();
85 | }
86 | else {
87 | assert(ac._vpArrays.size() > 0);
88 | for (const PlaceArrayCstr* pArr : ac._vpArrays) {
89 | if (hasCellImpl(*pArr, c)) {
90 | return true;
91 | }
92 | }
93 | return false;
94 | }
95 | };
96 | return hasCellImpl(*this, c);
97 | }
98 |
99 | private:
100 | String _name;
101 | Int _idx;
102 | Int _col;
103 | Int _row;
104 | Int _size;
105 | ArrayPatternE _pattern;
106 |
107 | Vector _vpCells;
108 | Vector _vArrayPartEs;
109 | FlatHashMap _mCellIdx2Idx;
110 |
111 | Vector _vpArrays; // for array of array constraints
112 | FlatHashMap _mArrayIdx2Idx;
113 | };
114 |
115 |
116 | PROJECT_NAMESPACE_END
117 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceClusterCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceClusterCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceClusterCstr()
29 | : _idx(-1), _weight(0)
30 | {}
31 | ~PlaceClusterCstr() {}
32 |
33 | const String& name() const { return _name; }
34 | Int idx() const { return _idx; }
35 |
36 | Cell& cell(const Int i) { return *_vpCells.at(i); }
37 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
38 | Cell* pCell(const Int i) { return _vpCells.at(i); }
39 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
40 | Vector& vpCells() { return _vpCells; }
41 | const Vector& vpCells() const { return _vpCells; }
42 | Int numCells() const { return _vpCells.size(); }
43 |
44 | Int weight() const { return _weight; }
45 |
46 | private:
47 | String _name;
48 | Int _idx;
49 | Vector _vpCells;
50 | Int _weight;
51 | };
52 |
53 | PROJECT_NAMESPACE_END
54 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceDisjointCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceDisjointCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceDisjointCstr()
29 | : _idx(-1), _isRow(false)
30 | {}
31 | ~PlaceDisjointCstr() {}
32 |
33 | const String& name() const { return _name; }
34 | Int idx() const { return _idx; }
35 |
36 | Cell& cell(const Int i) { return *_vpCells.at(i); }
37 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
38 | Cell* pCell(const Int i) { return _vpCells.at(i); }
39 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
40 | Vector& vpCells() { return _vpCells; }
41 | const Vector& vpCells() const { return _vpCells; }
42 | Int numCells() const { return _vpCells.size(); }
43 |
44 | bool isRow() const { return _isRow; }
45 | bool isCol() const { return !_isRow; }
46 |
47 |
48 | private:
49 | String _name;
50 | Int _idx;
51 | Vector _vpCells;
52 | bool _isRow;
53 | };
54 |
55 | PROJECT_NAMESPACE_END
56 |
57 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceEdgeDistCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class Cell;
25 | class Region;
26 |
27 | class PlaceEdgeDistCstr {
28 | friend class Parser;
29 |
30 | public:
31 | PlaceEdgeDistCstr() : _idx(-1), _distL(0), _distR(0), _distB(0), _distT(0) {}
32 | ~PlaceEdgeDistCstr() {}
33 |
34 | const String& name() const { return _name; }
35 | Int idx() const { return _idx; }
36 |
37 | Cell& cell(const Int i) { return *_vpCells.at(i); }
38 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
39 | Cell* pCell(const Int i) { return _vpCells.at(i); }
40 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
41 | Vector& vpCells() { return _vpCells; }
42 | const Vector& vpCells() const { return _vpCells; }
43 | Int numCells() const { return _vpCells.size(); }
44 |
45 | Int distL() const { return _distL; }
46 | Int distR() const { return _distR; }
47 | Int distB() const { return _distB; }
48 | Int distT() const { return _distT; }
49 |
50 | const Region& region() const { return _vpCells.at(0)->region(); }
51 | const Region* pRegion() const { return _vpCells.at(0)->pRegion(); }
52 |
53 | private:
54 | String _name;
55 | Int _idx;
56 | Vector _vpCells;
57 | Int _distL;
58 | Int _distR;
59 | Int _distB;
60 | Int _distT;
61 | };
62 |
63 | PROJECT_NAMESPACE_END
64 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceExtCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class Primitive;
25 | class Cell;
26 | class PlaceArrayCstr;
27 | class Region;
28 |
29 | class PlaceExtCstr {
30 | friend class Parser;
31 |
32 | public:
33 | PlaceExtCstr()
34 | : _idx(0), _type(ExtTypeE::undef)
35 | {}
36 | ~PlaceExtCstr() {}
37 |
38 | const String& name() const { return _name; }
39 | Int idx() const { return _idx; }
40 | ExtTypeE type() const { return _type; }
41 | bool isCell() const { return _type == ExtTypeE::cell; }
42 | bool isRegion() const { return _type == ExtTypeE::region; }
43 | bool isArray() const { return _type == ExtTypeE::array; }
44 |
45 | Cell& cell(const Int i) { return *_vpCells.at(i); }
46 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
47 | Cell* pCell(const Int i) { return _vpCells.at(i); }
48 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
49 | Vector& vpCells() { return _vpCells; }
50 | const Vector& vpCells() const { return _vpCells; }
51 | Int numCells() const { return _vpCells.size(); }
52 |
53 | Region& region(const Int i) { return *_vpRegions.at(i); }
54 | const Region& region(const Int i) const { return *_vpRegions.at(i); }
55 | Region* pRegion(const Int i) { return _vpRegions.at(i); }
56 | const Region* pRegion(const Int i) const { return _vpRegions.at(i); }
57 | Vector& vpRegions() { return _vpRegions; }
58 | const Vector& vpRegions() const { return _vpRegions; }
59 | Int numRegions() const { return _vpRegions.size(); }
60 |
61 | PlaceArrayCstr& placeArrayCstr(const Int i) { return *_vpPlaceArrayCstrs.at(i); }
62 | const PlaceArrayCstr& placeArrayCstr(const Int i) const { return *_vpPlaceArrayCstrs.at(i); }
63 | PlaceArrayCstr* pPlaceArrayCstr(const Int i) { return _vpPlaceArrayCstrs.at(i); }
64 | const PlaceArrayCstr* pPlaceArrayCstr(const Int i) const { return _vpPlaceArrayCstrs.at(i); }
65 | Vector& vpPlaceArrayCstrs() { return _vpPlaceArrayCstrs; }
66 | const Vector& vpPlaceArrayCstrs() const { return _vpPlaceArrayCstrs; }
67 | Int numPlaceArrayCstrs() const { return _vpPlaceArrayCstrs.size(); }
68 |
69 | const Pair& leftExt() const { return _left; }
70 | const Pair& rightExt() const { return _right; }
71 | const Pair& bottomExt() const { return _bottom; }
72 | const Pair& topExt() const { return _top; }
73 | Pair leftExtIdx() const { return std::make_pair(_left.first->idx(), _left.second); }
74 | Pair rightExtIdx() const { return std::make_pair(_right.first->idx(), _right.second); }
75 | Pair bottomExtIdx() const { return std::make_pair(_bottom.first->idx(), _bottom.second); }
76 | Pair topExtIdx() const { return std::make_pair(_top.first->idx(), _top.second); }
77 |
78 | private:
79 | String _name;
80 | Int _idx;
81 |
82 | ExtTypeE _type;
83 |
84 | Vector _vpCells;
85 | Vector _vpRegions;
86 | Vector _vpPlaceArrayCstrs;
87 |
88 | Pair _left; // (prim, numGrids)
89 | Pair _right;
90 | Pair _bottom;
91 | Pair _top;
92 | };
93 |
94 | PROJECT_NAMESPACE_END
95 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceOrderCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceOrderCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceOrderCstr() : _idx(-1), _dir(Direction2dE::undef), _isStrict(false) {}
29 | ~PlaceOrderCstr() {}
30 |
31 | const String& name() const { return _name; }
32 | Int idx() const { return _idx; }
33 |
34 | Cell& cell(const Int i, const Int j) { return *_vvpCells.at(i).at(j); }
35 | const Cell& cell(const Int i, const Int j) const { return *_vvpCells.at(i).at(j); }
36 | Cell* pCell(const Int i, const Int j) { return _vvpCells.at(i).at(j); }
37 | const Cell* pCell(const Int i, const Int j) const { return _vvpCells.at(i).at(j); }
38 | Vector& vpCells(const Int i) { return _vvpCells.at(i); }
39 | const Vector& vpCells(const Int i) const { return _vvpCells.at(i); }
40 | Int numCells(const Int i) const { return _vvpCells.at(i).size(); }
41 | Vector>& vvpCells() { return _vvpCells; }
42 | const Vector>& vvpCells() const { return _vvpCells; }
43 | Int numCellGroups() const { return _vvpCells.size(); }
44 |
45 | Direction2dE dir() const { return _dir; }
46 | bool isStrict() const { return _isStrict; }
47 | bool isWeak() const { return !_isStrict; }
48 |
49 | private:
50 | String _name;
51 | Int _idx;
52 | Vector> _vvpCells; // should be in the desired order
53 | Direction2dE _dir;
54 | bool _isStrict;
55 | };
56 |
57 | PROJECT_NAMESPACE_END
58 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceRowCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceRowCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceRowCstr()
29 | : _idx(-1), _isOdd(false)
30 | {}
31 | ~PlaceRowCstr() {}
32 |
33 | const String& name() const { return _name; }
34 | Int idx() const { return _idx; }
35 |
36 | Cell& cell(const Int i) { return *_vpCells.at(i); }
37 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
38 | Cell* pCell(const Int i) { return _vpCells.at(i); }
39 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
40 | Vector& vpCells() { return _vpCells; }
41 | const Vector& vpCells() const { return _vpCells; }
42 | Int numCells() const { return _vpCells.size(); }
43 |
44 | bool isOdd() const { return _isOdd; }
45 | bool isEven() const { return !_isOdd; }
46 |
47 |
48 | private:
49 | String _name;
50 | Int _idx;
51 | Vector _vpCells;
52 | bool _isOdd;
53 | };
54 |
55 | PROJECT_NAMESPACE_END
56 |
57 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPlaceSymCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class PlaceSymCstr {
25 | friend class Parser;
26 |
27 | public:
28 | PlaceSymCstr() : _idx(-1), _axis(SymAxisE::undef), _numPartAs(0), _numSelfSyms(0) {}
29 | ~PlaceSymCstr() {}
30 |
31 | const String& name() const { return _name; }
32 | Int idx() const { return _idx; }
33 |
34 | SymAxisE axis() const { return _axis; }
35 | bool isHor() const { return _axis == SymAxisE::hor; }
36 | bool isVer() const { return _axis == SymAxisE::ver; }
37 |
38 | Cell& cell(const Int i) { return *_vpCells.at(i); }
39 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
40 | Cell* pCell(const Int i) { return _vpCells.at(i); }
41 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
42 | Vector& vpCells() { return _vpCells; }
43 | const Vector& vpCells() const { return _vpCells; }
44 | Int numCells() const { return _vpCells.size(); }
45 |
46 | SymPartE symPart(const Int i) const { return _vSymPartEs.at(i); }
47 | SymPartE symPart(const Cell& c) const { return _vSymPartEs.at(cellIdx2Idx(c.idx())); }
48 | bool isPartA(const Int i) const { return symPart(i) == SymPartE::a; }
49 | bool isPartA(const Cell& c) const { return symPart(c) == SymPartE::a; }
50 | bool isPartB(const Int i) const { return symPart(i) == SymPartE::b; }
51 | bool isPartB(const Cell& c) const { return symPart(c) == SymPartE::b; }
52 | bool isSelfSym(const Int i) const { return symPart(i) == SymPartE::self; }
53 | bool isSelfSym(const Cell& c) const { return symPart(c) == SymPartE::self; }
54 | Int numSelfSyms() const { return _numSelfSyms; }
55 | Int numPartAs() const { return _numPartAs; }
56 | bool hasSelfSym() const { return _numSelfSyms > 0; }
57 |
58 | Int cellIdx2Idx(const Int idx) const { return _mCellIdx2Idx.at(idx); }
59 | Int cellIdx2SymIdx(const Int idx) const { return _vSymCellIds.at(cellIdx2Idx(idx)); }
60 | bool hasCell(const Cell& c) const { return _mCellIdx2Idx.find(c.idx()) != _mCellIdx2Idx.end(); }
61 |
62 | Cell& symCell(const Int i) { return *_vpCells.at(_vSymCellIds.at(i)); }
63 | Cell& symCell(const Cell& c) { return *_vpCells.at(cellIdx2SymIdx(c.idx())); }
64 | const Cell& symCell(const Int i) const { return *_vpCells.at(_vSymCellIds.at(i)); }
65 | const Cell& symCell(const Cell& c) const { return *_vpCells.at(cellIdx2SymIdx(c.idx())); }
66 | Cell* pSymCell(const Int i) { return _vpCells.at(_vSymCellIds.at(i)); }
67 | Cell* pSymCell(const Cell& c) { return _vpCells.at(cellIdx2SymIdx(c.idx())); }
68 | const Cell* pSymCell(const Int i) const { return _vpCells.at(_vSymCellIds.at(i)); }
69 | const Cell* pSymCell(const Cell& c) const { return _vpCells.at(cellIdx2SymIdx(c.idx())); }
70 |
71 | const Region& region() const { return _vpCells.at(0)->region(); }
72 | const Region* pRegion() const { return _vpCells.at(0)->pRegion(); }
73 |
74 | // for debug
75 | bool check() {
76 | bool b = true;
77 | const Region* pReg = _vpCells.at(0)->pRegion();
78 | for (Int i = 1; i < (Int)_vpCells.size(); ++i) {
79 | Cell& c = *_vpCells.at(i);
80 | if (c.pRegion() != pReg) {
81 | b = false;
82 | }
83 | }
84 | return b;
85 | }
86 |
87 | private:
88 |
89 | String _name;
90 | Int _idx;
91 | SymAxisE _axis;
92 |
93 | Vector _vpCells;
94 | Vector _vSymPartEs;
95 | Vector _vSymCellIds;
96 | Int _numPartAs;
97 | Int _numSelfSyms;
98 |
99 | FlatHashMap _mCellIdx2Idx; // cell.idx() -> idx in _vpCells
100 |
101 | };
102 |
103 | PROJECT_NAMESPACE_END
104 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbPrePlaceCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCell.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class Cell;
25 | class Region;
26 |
27 | class PrePlaceCstr {
28 | friend class Parser;
29 |
30 | public:
31 | PrePlaceCstr()
32 | : _idx(-1)
33 | {}
34 | ~PrePlaceCstr() {}
35 |
36 | const String& name() const { return _name; }
37 | Int idx() const { return _idx; }
38 |
39 | Cell& cell(const Int i) { return *_vpCells.at(i); }
40 | const Cell& cell(const Int i) const { return *_vpCells.at(i); }
41 | Cell* pCell(const Int i) { return _vpCells.at(i); }
42 | const Cell* pCell(const Int i) const { return _vpCells.at(i); }
43 | Vector& vpCells() { return _vpCells; }
44 | const Vector& vpCells() const { return _vpCells; }
45 | Int numCells() const { return _vpCells.size(); }
46 |
47 | Point cellLoc(const Int i) const { return _vCellLocs.at(i); }
48 | bool hasCellLoc(const Int i) const { return _vCellLocs.at(i) != Point(-1, -1); }
49 |
50 | Orient2dE cellOrient(const Int i) const { return _vCellOrients.at(i); }
51 | bool hasCellOrient(const Int i) const { return _vCellOrients.at(i) != Orient2dE::undef; }
52 |
53 | Region& region(const Int i) { return *_vpRegions.at(i); }
54 | const Region& region(const Int i) const { return *_vpRegions.at(i); }
55 | Region* pRegion(const Int i) { return _vpRegions.at(i); }
56 | const Region* pRegion(const Int i) const { return _vpRegions.at(i); }
57 | Vector& vpRegions() { return _vpRegions; }
58 | const Vector& vpRegions() const { return _vpRegions; }
59 | Int numRegions() const { return _vpRegions.size(); }
60 |
61 | Point regLoc(const Int i) const { return _vRegLocs.at(i); }
62 | bool hasRegLoc(const Int i) const { return _vRegLocs.at(i) != Point(-1, -1); }
63 |
64 |
65 | private:
66 | String _name;
67 | Int _idx;
68 | Vector _vpCells;
69 | Vector> _vCellLocs;
70 | Vector _vCellOrients;
71 |
72 | Vector _vpRegions;
73 | Vector> _vRegLocs;
74 |
75 | };
76 |
77 | PROJECT_NAMESPACE_END
78 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbRoutePathMatchCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbBasic.hpp"
21 | #include "ds/hash.hpp"
22 |
23 | PROJECT_NAMESPACE_START
24 |
25 | class Pin;
26 | class Net;
27 |
28 |
29 | class RoutePathMatchCstr {
30 | friend class Parser;
31 | public:
32 |
33 | class PathCstr {
34 | friend class Parser;
35 | public:
36 | PathCstr() : _idx(-1) {}
37 | ~PathCstr() {}
38 |
39 | Int idx() const { return _idx; }
40 |
41 | Pin& srcPin(const Int i) { return *_vConns.at(i).first; }
42 | const Pin& srcPin(const Int i) const { return *_vConns.at(i).first; }
43 | Pin* pSrcPin(const Int i) { return _vConns.at(i).first; }
44 | const Pin* pSrcPin(const Int i) const { return _vConns.at(i).first; }
45 |
46 | Pin& tarPin(const Int i) { return *_vConns.at(i).second; }
47 | const Pin& tarPin(const Int i) const { return *_vConns.at(i).second; }
48 | Pin* pTarPin(const Int i) { return _vConns.at(i).second; }
49 | const Pin* pTarPin(const Int i) const { return _vConns.at(i).second; }
50 |
51 | Pair& conn(const Int i) { return _vConns.at(i); }
52 | const Pair& conn(const Int i) const { return _vConns.at(i); }
53 |
54 | Vector>& vConns() { return _vConns; }
55 | const Vector>& vConns() const { return _vConns; }
56 | Int numConns() const { return _vConns.size(); }
57 |
58 | bool hasNet(const Net* p) const { return _spNets.find(p) != _spNets.end(); }
59 |
60 | private:
61 | Int _idx; // idx in its parent cstr (the "idx"-th path cstr in the parent cstr)
62 | Vector> _vConns;
63 | FlatHashSet _spNets;
64 | };
65 |
66 | RoutePathMatchCstr()
67 | : _idx(-1)
68 | {}
69 | ~RoutePathMatchCstr() {}
70 |
71 | const String& name() const { return _name; }
72 | Int idx() const { return _idx; }
73 |
74 |
75 | Net& net(const Int i) { return *_vpNets.at(i); }
76 | const Net& net(const Int i) const { return *_vpNets.at(i); }
77 | Net* pNet(const Int i) { return _vpNets.at(i); }
78 | const Net* pNet(const Int i) const { return _vpNets.at(i); }
79 | Vector& vpNets() { return _vpNets; }
80 | const Vector& vpNets() const { return _vpNets; }
81 | Int numNets() const { return _vpNets.size(); }
82 |
83 | PathCstr& pathCstr(const Int i) { return _vPathCstrs.at(i); }
84 | const PathCstr& pathCstr(const Int i) const { return _vPathCstrs.at(i); }
85 | PathCstr& pathCstr(const Net* p) { return _vPathCstrs.at(netIdx(p)); }
86 | const PathCstr& pathCstr(const Net* p) const { return _vPathCstrs.at(netIdx(p)); }
87 | Vector& vPathCstrs() { return _vPathCstrs; }
88 | const Vector& vPathCstrs() const { return _vPathCstrs; }
89 | Int numPathCstrs() const { return _vPathCstrs.size(); }
90 |
91 | Int netIdx(const Net* p) const { return _mNet2NetIdx.at(p); }
92 | bool hasNet(const Net* p) const { return _mNet2NetIdx.find(p) != _mNet2NetIdx.end(); }
93 |
94 | private:
95 | String _name;
96 | Int _idx;
97 | Vector _vpNets;
98 | Vector _vPathCstrs;
99 | FlatHashMap _mNet2NetIdx;
100 | };
101 |
102 | PROJECT_NAMESPACE_END
103 |
--------------------------------------------------------------------------------
/cpp/src/db/cstr/dbRouteSymCstr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbNet.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class RouteSymCstr {
25 | friend class Parser;
26 |
27 | public:
28 | RouteSymCstr()
29 | : _idx(-1), _axis(SymAxisE::undef),
30 | _numPartAs(0), _numSelfSyms(0)
31 | {}
32 | ~RouteSymCstr() {}
33 |
34 | const String& name() const { return _name; }
35 | Int idx() const { return _idx; }
36 |
37 | SymAxisE axis() const { return _axis; }
38 |
39 | Net& net(const Int i) { return *_vpNets.at(i); }
40 | const Net& net(const Int i) const { return *_vpNets.at(i); }
41 | Net* pNet(const Int i) { return _vpNets.at(i); }
42 | const Net* pNet(const Int i) const { return _vpNets.at(i); }
43 | Vector& vpNets() { return _vpNets; }
44 | const Vector& vpNets() const { return _vpNets; }
45 | Int numNets() const { return _vpNets.size(); }
46 |
47 | SymPartE symPart(const Int i) const { return _vSymPartEs.at(i); }
48 | SymPartE symPart(const Net& n) const { return _vSymPartEs.at(netIdx2Idx(n.idx())); }
49 | bool isPartA(const Int i) const { return symPart(i) == SymPartE::a; }
50 | bool isPartA(const Net& n) const { return symPart(n) == SymPartE::a; }
51 | bool isPartB(const Int i) const { return symPart(i) == SymPartE::b; }
52 | bool isPartB(const Net& n) const { return symPart(n) == SymPartE::b; }
53 | bool isSelfSym(const Int i) const { return symPart(i) == SymPartE::self; }
54 | bool isSelfSym(const Net& n) const { return symPart(n) == SymPartE::self; }
55 | Int numSelfSyms() const { return _numSelfSyms; }
56 | Int numPartAs() const { return _numPartAs; }
57 | bool hasSelfSym() const { return _numSelfSyms > 0; }
58 |
59 | Int netIdx2Idx(const Int idx) const { return _mNetIdx2Idx.at(idx); }
60 | Int netIdx2SymIdx(const Int idx) const { return _vSymNetIds.at(netIdx2Idx(idx)); }
61 |
62 | Net& symNet(const Int i) { return *_vpNets.at(_vSymNetIds.at(i)); }
63 | Net& symNet(const Net& n) { return *_vpNets.at(netIdx2SymIdx(n.idx())); }
64 | const Net& symNet(const Int i) const { return *_vpNets.at(_vSymNetIds.at(i)); }
65 | const Net& symNet(const Net& n) const { return *_vpNets.at(netIdx2SymIdx(n.idx())); }
66 | Net* pSymNet(const Int i) { return _vpNets.at(_vSymNetIds.at(i)); }
67 | Net* pSymNet(const Net& n) { return _vpNets.at(netIdx2SymIdx(n.idx())); }
68 | const Net* pSymNet(const Int i) const { return _vpNets.at(_vSymNetIds.at(i)); }
69 | const Net* pSymNet(const Net& n) const { return _vpNets.at(netIdx2SymIdx(n.idx())); }
70 |
71 | const Region& region() const { return _vpNets.at(0)->region(); }
72 | const Region* pRegion() const { return _vpNets.at(0)->pRegion(); }
73 |
74 | private:
75 | String _name;
76 | Int _idx;
77 |
78 | SymAxisE _axis;
79 |
80 | Vector _vpNets;
81 | Vector _vSymPartEs;
82 | Vector _vSymNetIds;
83 | Int _numPartAs;
84 | Int _numSelfSyms;
85 |
86 | FlatHashMap _mNetIdx2Idx; // net.idx() -> idx in _vpNets;
87 | };
88 |
89 | PROJECT_NAMESPACE_END
90 |
--------------------------------------------------------------------------------
/cpp/src/db/dbBasic.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #include "dbBasic.hpp"
19 |
20 | PROJECT_NAMESPACE_START
21 |
22 | namespace orient2d {
23 |
24 | Orient2dE rotate90(const Orient2dE o)
25 | {
26 | switch (o) {
27 | case Orient2dE::n: return Orient2dE::w;
28 | case Orient2dE::w: return Orient2dE::s;
29 | case Orient2dE::s: return Orient2dE::e;
30 | case Orient2dE::e: return Orient2dE::n;
31 | case Orient2dE::fn: return Orient2dE::fe;
32 | case Orient2dE::fw: return Orient2dE::fn;
33 | case Orient2dE::fs: return Orient2dE::fw;
34 | case Orient2dE::fe: return Orient2dE::fs;
35 | default: assert(false);
36 | }
37 | return Orient2dE::undef;
38 | }
39 |
40 | Orient2dE rotate180(const Orient2dE o)
41 | {
42 | switch (o) {
43 | case Orient2dE::n: return Orient2dE::s;
44 | case Orient2dE::w: return Orient2dE::e;
45 | case Orient2dE::s: return Orient2dE::n;
46 | case Orient2dE::e: return Orient2dE::w;
47 | case Orient2dE::fn: return Orient2dE::fs;
48 | case Orient2dE::fw: return Orient2dE::fe;
49 | case Orient2dE::fs: return Orient2dE::fn;
50 | case Orient2dE::fe: return Orient2dE::fw;
51 | default: assert(false);
52 | }
53 | return Orient2dE::undef;
54 | }
55 |
56 | Orient2dE rotate270(const Orient2dE o)
57 | {
58 | switch (o) {
59 | case Orient2dE::n: return Orient2dE::e;
60 | case Orient2dE::w: return Orient2dE::n;
61 | case Orient2dE::s: return Orient2dE::w;
62 | case Orient2dE::e: return Orient2dE::s;
63 | case Orient2dE::fn: return Orient2dE::fw;
64 | case Orient2dE::fw: return Orient2dE::fs;
65 | case Orient2dE::fs: return Orient2dE::fe;
66 | case Orient2dE::fe: return Orient2dE::fn;
67 | default: assert(false);
68 | }
69 | return Orient2dE::undef;
70 | }
71 |
72 | Orient2dE flipX(const Orient2dE o)
73 | {
74 | switch (o) {
75 | case Orient2dE::n: return Orient2dE::fn;
76 | case Orient2dE::w: return Orient2dE::fw;
77 | case Orient2dE::s: return Orient2dE::fs;
78 | case Orient2dE::e: return Orient2dE::fe;
79 | case Orient2dE::fn: return Orient2dE::n;
80 | case Orient2dE::fw: return Orient2dE::w;
81 | case Orient2dE::fs: return Orient2dE::s;
82 | case Orient2dE::fe: return Orient2dE::e;
83 | default: assert(false);
84 | }
85 | return Orient2dE::undef;
86 | }
87 |
88 | Orient2dE flipY(const Orient2dE o)
89 | {
90 | switch (o) {
91 | case Orient2dE::n: return Orient2dE::fs;
92 | case Orient2dE::w: return Orient2dE::fe;
93 | case Orient2dE::s: return Orient2dE::fn;
94 | case Orient2dE::e: return Orient2dE::fw;
95 | case Orient2dE::fn: return Orient2dE::s;
96 | case Orient2dE::fw: return Orient2dE::e;
97 | case Orient2dE::fs: return Orient2dE::n;
98 | case Orient2dE::fe: return Orient2dE::w;
99 | default: assert(false);
100 | }
101 | return Orient2dE::undef;
102 | }
103 |
104 | }
105 |
106 | namespace direction3d {
107 |
108 | Direction3dE findDir(const Point3d& u, const Point3d& v)
109 | {
110 | if (u.z() == v.z()) {
111 | if (u.x() == v.x()) {
112 | assert(u.y() != v.y());
113 | return u.y() < v.y() ? Direction3dE::up : Direction3dE::down;
114 | }
115 | else {
116 | assert(u.x() != v.x());
117 | return u.x() < v.x() ? Direction3dE::right : Direction3dE::left;
118 | }
119 | }
120 | else {
121 | assert(u.x() == v.x() and u.y() == v.y());
122 | return u.z() < v.z() ? Direction3dE::via_up : Direction3dE::via_down;
123 | }
124 | }
125 |
126 | }
127 |
128 | PROJECT_NAMESPACE_END
129 |
--------------------------------------------------------------------------------
/cpp/src/db/dbDevMap.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "dbPrim.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class DevMap { // device to primitives mapping
25 | friend class Parser;
26 |
27 | public:
28 | DevMap()
29 | : _name(""), _pPrim(nullptr), _multiplier(1), _bAbutment(false) {}
30 | ~DevMap() {}
31 |
32 | const String& name() const { return _name; }
33 |
34 | const Primitive& prim() const { return *_pPrim; }
35 | const Primitive* pPrim() const { return _pPrim; }
36 | Int multiplier() const { return _multiplier; }
37 |
38 | bool isAbutment() const { return _bAbutment; }
39 |
40 | const String& devNet(const Int i) const { return _vNetMaps.at(i).first; }
41 | const String& primNet(const Int i) const { return _vNetMaps.at(i).second; }
42 | const String& devNet2PrimNet(const String& n) const { return _vNetMaps.at(_mDevNetMap2Idx.at(n)).second; }
43 | const String& primNet2DevNet(const String& n) const { return _vNetMaps.at(_mPrimNetMap2Idx.at(n)).first; }
44 | Int numNets() const { return _vNetMaps.size(); }
45 |
46 | private:
47 | String _name;
48 | const Primitive* _pPrim;
49 | Int _multiplier; // number of prims to use
50 | bool _bAbutment;
51 | Vector> _vNetMaps;
52 | FlatHashMap _mDevNetMap2Idx;
53 | FlatHashMap _mPrimNetMap2Idx;
54 | };
55 |
56 | PROJECT_NAMESPACE_END
57 |
--------------------------------------------------------------------------------
/cpp/src/db/dbLayer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #include "dbLayer.hpp"
19 |
20 | PROJECT_NAMESPACE_START
21 |
22 | Int MetalLayer::eolIdx(const Int eolWidth) const
23 | {
24 | //Int idx = 0;
25 | //for (size_t i = 0; i < _vEolWidths.size(); ++i) {
26 | //if (_vEolWidths.at(i) < eolWidth) {
27 | //idx = i;
28 | //}
29 | //else {
30 | //break;
31 | //}
32 | //}
33 | //return idx;
34 | const Int idx = std::upper_bound(_vEolWidths.begin(), _vEolWidths.end(), eolWidth) - _vEolWidths.begin();
35 | return idx >= static_cast(_vEolWidths.size()) ? _vEolWidths.size() - 1 : idx;
36 | }
37 |
38 | Int MetalLayer::prlSpacing(const Int width, const Int prl) const
39 | {
40 |
41 | // find prl
42 | Int prlIdx = std::upper_bound(_vSpacingTablePrl.begin(), _vSpacingTablePrl.end(), prl) - _vSpacingTablePrl.begin() - 1;
43 | if (prlIdx >= static_cast(_vSpacingTablePrl.size())) {
44 | prlIdx = _vSpacingTablePrl.size() - 1;
45 | }
46 | assert(_vSpacingTablePrl.at(prlIdx) <= prl);
47 |
48 | // find width
49 | Int wIdx = std::upper_bound(_vSpacingTableWidth.begin(), _vSpacingTableWidth.end(), width) - _vSpacingTableWidth.begin() - 1;
50 | if (wIdx >= static_cast(_vSpacingTableWidth.size())) {
51 | wIdx = _vSpacingTableWidth.size() - 1;
52 | }
53 | assert(_vSpacingTableWidth.at(wIdx) <= width);
54 |
55 | return _spacingTable.at(wIdx, prlIdx);
56 |
57 | }
58 |
59 | Int MetalLayer::validWidthIdx(const Int w) const
60 | {
61 | //Int idx = 0;
62 | //for (size_t i = 0; i < _vValidWidths.size(); ++i) {
63 | //if (_vValidWidths.at(i) >= w) {
64 | //idx = i;
65 | //break;
66 | //}
67 | //}
68 | //return idx;
69 |
70 | return std::lower_bound(_vValidWidths.begin(), _vValidWidths.end(), w) - _vValidWidths.begin();
71 | }
72 |
73 | Int MetalLayer::validLengthIdx(const Int l) const
74 | {
75 | //Int idx = 0;
76 | //for (size_t i = 0; i < _vValidLengths.size(); ++i) {
77 | //if (_vValidLengths.at(i) >= l) {
78 | //idx = i;
79 | //break;
80 | //}
81 | //}
82 | //return idx;
83 |
84 | return std::lower_bound(_vValidLengths.begin(), _vValidLengths.end(), l) - _vValidLengths.begin();
85 | }
86 |
87 |
88 | PROJECT_NAMESPACE_END
89 |
--------------------------------------------------------------------------------
/cpp/src/db/dbObs.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "geo/box.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class Cell;
25 |
26 | class Obs {
27 | friend class Cell;
28 | friend class Parser;
29 | friend class LefReader;
30 |
31 | public:
32 | Obs()
33 | : _pCell(nullptr), _layerIdx(-1) {}
34 | Obs(const Box& b, const Int z)
35 | : _pCell(nullptr), _box(b), _layerIdx(z) {}
36 | ~Obs() {}
37 | Cell& cell() { return *_pCell; }
38 | const Cell& cell() const { return *_pCell; }
39 | Cell* pCell() { return _pCell; }
40 | const Cell* pCell() const { return _pCell; }
41 |
42 | Box& box() { return _box; }
43 | const Box& box() const { return _box; }
44 | Int layerIdx() const { return _layerIdx; }
45 |
46 | private:
47 | Cell* _pCell;
48 | Box _box;
49 | Int _layerIdx;
50 | };
51 |
52 | PROJECT_NAMESPACE_END
53 |
--------------------------------------------------------------------------------
/cpp/src/db/dbPrim.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "ds/hash.hpp"
21 | #include "dbPin.hpp"
22 | #include "dbObs.hpp"
23 |
24 | PROJECT_NAMESPACE_START
25 |
26 |
27 | class Primitive {
28 | friend class Parser;
29 | friend class LefReader;
30 |
31 | public:
32 |
33 | Primitive()
34 | : _idx(-1), _originX(0), _originY(0), _sizeX(0), _sizeY(0), _foreignX(0), _foreignY(0),
35 | _isXSym(false), _isYSym(false), _is90Sym(false) {}
36 | ~Primitive() {}
37 |
38 | const String& name() const { return _name; }
39 | Int idx() const { return _idx; }
40 | const String& classType() const { return _classType; }
41 |
42 | Int originX() const { return _originX; }
43 | Int originY() const { return _originY; }
44 | Int sizeX() const { return _sizeX; }
45 | Int sizeY() const { return _sizeY; }
46 | Int area() const { return _sizeX * _sizeY; }
47 |
48 | const String& foreignCellName() const { return _foreignCellName; }
49 | Int foreignX() const { return _foreignX; }
50 | Int foreignY() const { return _foreignY; }
51 |
52 | const Pin& pin(const Int i) const { return _vPins.at(i); }
53 | const Pin& pin(const String& n) const { return _vPins.at(pinName2Idx(n)); }
54 | Int pinName2Idx(const String& n) const { return _mPinName2Idx.at(n); }
55 | const Vector& vPins() const { return _vPins; }
56 | Int numPins() const { return _vPins.size(); }
57 |
58 | const Obs& obs(const Int i) const { return _vObs.at(i); }
59 | const Vector& vObs() const { return _vObs; }
60 | Int numObs() const { return _vObs.size(); }
61 |
62 | private:
63 | String _name;
64 | Int _idx;
65 | String _classType;
66 | Int _originX, _originY;
67 | Int _sizeX, _sizeY;
68 | String _foreignCellName;
69 | Int _foreignX, _foreignY;
70 | bool _isXSym;
71 | bool _isYSym;
72 | bool _is90Sym;
73 |
74 | Vector _vPins;
75 | FlatHashMap _mPinName2Idx;
76 |
77 | Vector _vObs;
78 | };
79 |
80 |
81 | PROJECT_NAMESPACE_END
82 |
--------------------------------------------------------------------------------
/cpp/src/db/dbVia.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "geo/box.hpp"
21 | #include "dbBasic.hpp"
22 |
23 | PROJECT_NAMESPACE_START
24 |
25 | class Via {
26 | friend class Parser;
27 | friend class LefReader;
28 |
29 | public:
30 | Via()
31 | : _name(""), _idx(-1), _type(ViaTypeE::undef),
32 | _minLayerIdx(MAX_INT), _maxLayerIdx(0)
33 | {}
34 | ~Via() {}
35 |
36 | const String& name() const { return _name; }
37 | Int idx() const { return _idx; }
38 |
39 | ViaTypeE type() const { return _type; }
40 | bool isDefault() const { return _type == ViaTypeE::def; }
41 | bool isGenerated() const { return _type == ViaTypeE::generated; }
42 |
43 | Box& box(const Int i) { return _vBoxes.at(i); }
44 | const Box& box(const Int i) const { return _vBoxes.at(i); }
45 | Box& box(const Int l, const Int i) { return _vBoxes.at(_vvBoxIds.at(l).at(i)); }
46 | const Box& box(const Int l, const Int i) const { return _vBoxes.at(_vvBoxIds.at(l).at(i)); }
47 | Vector>& vBoxes() { return _vBoxes; }
48 | const Vector>& vBoxes() const { return _vBoxes; }
49 | Int boxLayerIdx(const Int i) const { return _vBoxLayerIds.at(i); }
50 | Int numBoxes() const { return _vBoxes.size(); }
51 | Int numBoxes(const Int l) const { return _vvBoxIds.at(l).size(); }
52 |
53 | Int minLayerIdx() const { return _minLayerIdx; }
54 | Int maxLayerIdx() const { return _maxLayerIdx; }
55 |
56 |
57 | private:
58 | String _name;
59 | Int _idx;
60 | ViaTypeE _type;
61 |
62 | Vector> _vBoxes;
63 | Vector _vBoxLayerIds;
64 | Vector> _vvBoxIds;
65 | Int _minLayerIdx;
66 | Int _maxLayerIdx;
67 |
68 | };
69 |
70 | #define Via_ForEachLayerIdx(via, i) \
71 | for (i = via.minLayerIdx(); i <= via.maxLayerIdx(); ++i)
72 |
73 | #define Via_ForEachMetalLayerIdx(via, i) \
74 | for (i = via.minLayerIdx(); i <= via.maxLayerIdx(); i += 2)
75 |
76 | #define Via_ForEachCutLayerIdx(via, i) \
77 | for (i = via.minLayerIdx() + 1; i < via.maxLayerIdx(); i += 2)
78 |
79 | #define Via_ForEachLayerBox(via, layerIdx, pBox_, i) \
80 | for (i = 0; i < via.numBoxes(layerIdx) and (pBox_ = &via.box(layerIdx, i)); ++i)
81 |
82 | PROJECT_NAMESPACE_END
83 |
--------------------------------------------------------------------------------
/cpp/src/drc/drcMgr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "db/dbCir.hpp"
21 | #include "geo/polygon.hpp"
22 |
23 | PROJECT_NAMESPACE_START
24 |
25 | class DrcMgr {
26 | public:
27 | DrcMgr(CirDB& cir)
28 | : _cir(cir)
29 | {}
30 | ~DrcMgr() {}
31 |
32 | ////////////////////////////////////////
33 | // Wire level checking //
34 | ////////////////////////////////////////
35 |
36 | // min/max width
37 | bool checkWireValidWidth(const Int layerIdx, const Box& b) const;
38 |
39 | // min/max length
40 | bool checkWireValidLength(const Int layerIdx, const Box& b) const;
41 |
42 | // spacing
43 | bool checkWireMetalSpacing(const Net& net, const Int layerIdx, const Box& b) const;
44 | bool checkWireMetalPrlSpacing(const Net& net, const Int layerIdx, const Box& b, const Int prl = 0) const;
45 | bool checkWireMetalEolSpacing(const Net& net, const Int layerIdx, const Box& b) const;
46 | bool checkWireCutSpacing(const Net& net, const Int layerIdx, const Box& b) const;
47 |
48 | // min area
49 | bool checkWireMinArea(const Int layerIdx, const Box& b) const;
50 |
51 | // via
52 | bool checkViaSpacing(const Net& net, const Int x, const Int y, const Via& via, const Orient2dE orient) const;
53 |
54 | // min step
55 | bool checkWireMinStep(const Int layerIdx, const Box& b) const;
56 | bool checkWireMinStep(const Int layerIdx, const Polygon& p) const;
57 |
58 | // total
59 | bool checkWire(const Net& net, const Pair, Int>& wire) const;
60 | ////////////////////////////////////////
61 | // Net level checking //
62 | ////////////////////////////////////////
63 | DrvE checkNet(const Net& net) const;
64 |
65 | ////////////////////////////////////////
66 | // Fix Funcs //
67 | ////////////////////////////////////////
68 | void fitWire2ValidLength(const Int layerIdx, Box& b) const;
69 |
70 | private:
71 | CirDB& _cir;
72 | };
73 |
74 | PROJECT_NAMESPACE_END
75 |
--------------------------------------------------------------------------------
/cpp/src/ds/array2d.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "global/global.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | template
25 | class Array2d {
26 | public:
27 | Array2d() : _numX(0), _numY(0) {}
28 | Array2d(const Int x, const Int y) : _numX(x), _numY(y), _vec(x * y) {}
29 | Array2d(const Int x, const Int y, const T& val) : _numX(x), _numY(y), _vec(x * y, val) {}
30 | ~Array2d() {}
31 |
32 | // get
33 | Int numX() const { return _numX; }
34 | Int numY() const { return _numY; }
35 | Int size() const { return _vec.size(); }
36 | T& at(const Int i) { return _vec.at(i); }
37 | const T& at(const Int i) const { return _vec.at(i); }
38 | T& at(const Int x, const Int y) { return _vec.at(flatIdx(x, y)); }
39 | const T& at(const Int x, const Int y) const { return _vec.at(flatIdx(x, y)); }
40 |
41 | // iterator
42 | inline typename Vector::iterator begin() { return _vec.begin(); }
43 | inline typename Vector::const_iterator cbegin() const { return _vec.cbegin(); }
44 | inline typename Vector::iterator end() { return _vec.end(); }
45 | inline typename Vector::const_iterator cend() const { return _vec.cend(); }
46 |
47 | // set
48 | void clear() { _numX = _numY = 0; _vec.clear(); }
49 | void resize(const Int x, const Int y) { _numX = x; _numY = y; _vec.resize(x * y); }
50 | void resize(const Int x, const Int y, const T& val) { _numX = x; _numY = y; _vec.resize(x * y, val); }
51 | void set(const Int x, const Int y, const T& val) { _vec[flatIdx(x, y)] = val; }
52 |
53 | T& operator [] (const Int i) { return _vec.at(i); }
54 |
55 | private:
56 | Int _numX;
57 | Int _numY;
58 | Vector _vec;
59 |
60 | Int flatIdx(const Int x, const Int y) const {
61 | assert(0 <= x and x < _numX);
62 | assert(0 <= y and y < _numY);
63 | return x * _numY + y;
64 | }
65 | Pair nestedIdx(const Int i) const { return std::make_pair(i / _numY, i % _numY); }
66 | };
67 |
68 |
69 | #define Array2d_ForEachEntryX(a2d, y, pEntry_, i) \
70 | for (i = 0; i < a2d.numX() and (pEntry_ = &a2d.at(i, y)); ++i)
71 |
72 | #define Array2d_ForEachEntryY(a2d, x, pEntry_, i) \
73 | for (i = 0; i < a2d.numY() and (pEntry_ = &a2d.at(x, i)); ++i)
74 |
75 |
76 | PROJECT_NAMESPACE_END
77 |
78 |
--------------------------------------------------------------------------------
/cpp/src/ds/array3d.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "global/global.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | template
25 | class Array3d {
26 | public:
27 | Array3d() : _numX(0), _numY(0), _numZ(0), _numYZ(0) {}
28 | Array3d(const Int x, const Int y, const Int z) : _numX(x), _numY(y), _numZ(z), _numYZ(y * z), _vec(x * y * z) {}
29 | Array3d(const Int x, const Int y, const Int z, const T& val) : _numX(x), _numY(y), _numZ(z), _numYZ(y * z), _vec(x * y * z, val) {}
30 | ~Array3d() {}
31 |
32 | // get
33 | Int numX() const { return _numX; }
34 | Int numY() const { return _numY; }
35 | Int numZ() const { return _numZ; }
36 | Int size() const { return _vec.size(); }
37 | T& at(const Int i) { return _vec.at(i); }
38 | const T& at(const Int i) const { return _vec.at(i); }
39 | T& at(const Int x, const Int y, const Int z) { return _vec.at(flatIdx(x, y, z)); }
40 | const T& at(const Int x, const Int y, const Int z) const { return _vec.at(flatIdx(x, y, z)); }
41 |
42 | // iterator
43 | inline typename Vector::iterator begin() { return _vec.begin(); }
44 | inline typename Vector::const_iterator cbegin() const { return _vec.cbegin(); }
45 | inline typename Vector::iterator end() { return _vec.end(); }
46 | inline typename Vector::const_iterator cend() const { return _vec.cend(); }
47 |
48 | // set
49 | void clear() { _numX = _numY = _numZ = _numYZ = 0; _vec.clear(); }
50 | void resize(const Int x, const Int y, const Int z) { _numX = x; _numY = y; _numZ = z; _numYZ = y * z; _vec.resize(x * y * z); }
51 | void resize(const Int x, const Int y, const Int z, const T& val) { _numX = x; _numY = y; _numZ = z; _numYZ = y * z; _vec.resize(x * y * z, val); }
52 | void set(const Int x, const Int y, const Int z, const T& val) { _vec[flatIdx(x, y, z)] = val; }
53 |
54 | T& operator [] (const Int i) { return _vec.at(i); }
55 |
56 | private:
57 | Int _numX;
58 | Int _numY;
59 | Int _numZ;
60 | Int _numYZ;
61 | Vector _vec;
62 |
63 | Int flatIdx(const Int x, const Int y, const Int z) const {
64 | assert(0 <= x and x < _numX);
65 | assert(0 <= y and y < _numY);
66 | assert(0 <= z and z < _numZ);
67 | return x * _numYZ + y * _numZ + z;
68 | }
69 | };
70 |
71 | #define Array3d_ForEachEntryX(a3d, y, z, pEntry_, i) \
72 | for (i = 0; i < a3d.numX() and (pEntry_ = &a3d.at(i, y, z)); ++i)
73 |
74 | #define Array3d_ForEachEntryY(a3d, x, z, pEntry_, i) \
75 | for (i = 0; i < a3d.numY() and (pEntry_ = &a3d.at(x, i, z)); ++i)
76 |
77 | #define Array3d_ForEachEntryZ(a3d, x, y, pEntry_, i) \
78 | for (i = 0; i < a3d.numZ() and (pEntry_ = &a3d.at(x, y, i)); ++i)
79 |
80 | PROJECT_NAMESPACE_END
81 |
82 |
--------------------------------------------------------------------------------
/cpp/src/ds/disjointSet.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "global/namespace.hpp"
21 |
22 | PROJECT_NAMESPACE_START
23 |
24 | class DisjointSet {
25 | public:
26 | DisjointSet()
27 | : parent(0), rnk(0), n(0) {}
28 | DisjointSet(Int n) { init(n); }
29 | ~DisjointSet() {
30 | delete [] parent;
31 | delete [] rnk;
32 | }
33 |
34 | void init(Int n) {
35 | this->n = n;
36 | parent = new Int[n];
37 | rnk = new Int[n];
38 | for (Int i = 0; i < n; ++i) {
39 | rnk[i] = 0;
40 | parent[i] = i;
41 | }
42 | }
43 | // Find set
44 | Int find(Int u) {
45 | return (u == parent[u] ? u : parent[u] = find(parent[u]));
46 | }
47 |
48 | // Union by rank
49 | void merge(Int x, Int y) {
50 | x = find(x), y = find(y);
51 | if (x == y)
52 | return;
53 | if (rnk[x] > rnk[y])
54 | parent[y] = x;
55 | else // If rnk[x] <= rnk[y]
56 | parent[x] = y;
57 | if (rnk[x] == rnk[y])
58 | rnk[y]++;
59 | }
60 |
61 | // Number of disjoint sets
62 | Int nSets() {
63 | Int nSets = 0;
64 | for (Int i = 0; i < n; ++i)
65 | if (parent[i] == i) ++nSets;
66 | return nSets;
67 | }
68 |
69 | private:
70 | Int *parent, *rnk;
71 | Int n;
72 | };
73 |
74 | PROJECT_NAMESPACE_END
75 |
76 |
--------------------------------------------------------------------------------
/cpp/src/ds/hash.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include
21 |
22 | #include "global/namespace.hpp"
23 |
24 | PROJECT_NAMESPACE_START
25 |
26 | template
27 | using FlatHashSet = phmap::flat_hash_set;
28 |
29 | template
30 | using FlatHashMap = phmap::flat_hash_map;
31 |
32 | template
33 | using ParallelFlatHashSet = phmap::parallel_flat_hash_set;
34 |
35 | template
36 | using ParallelFlatHashMap = phmap::parallel_flat_hash_map;
37 |
38 | template
39 | using NodeHashSet = phmap::node_hash_set;
40 |
41 | template
42 | using NodeHashMap = phmap::node_hash_map;
43 |
44 | template
45 | using ParallelNodeHashSet = phmap::parallel_node_hash_set;
46 |
47 | template
48 | using ParallelNodeHashMap = phmap::parallel_node_hash_map;
49 |
50 | PROJECT_NAMESPACE_END
51 |
52 |
--------------------------------------------------------------------------------
/cpp/src/ds/pqueue.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include
21 |
22 | #include "global/namespace.hpp"
23 |
24 | PROJECT_NAMESPACE_START
25 |
26 |
27 | template >
28 | using Pqueue = __gnu_pbds::priority_queue;
29 |
30 | template >
31 | using BinaryHeap = __gnu_pbds::priority_queue;
32 |
33 | template >
34 | using BinomialHeap = __gnu_pbds::priority_queue;
35 |
36 | template >
37 | using RCBinomialHeap = __gnu_pbds::priority_queue;
38 |
39 | template >
40 | using PairingHeap = __gnu_pbds::priority_queue;
41 |
42 | template >
43 | using ThinHeap = __gnu_pbds::priority_queue;
44 |
45 | PROJECT_NAMESPACE_END
46 |
47 |
--------------------------------------------------------------------------------
/cpp/src/geo/box2polygon.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include
21 | #include "polygon2box.hpp"
22 | #include "polygon.hpp"
23 | #include "ds/hash.hpp"
24 |
25 | PROJECT_NAMESPACE_START
26 |
27 | namespace geo {
28 | template
29 | inline boost::polygon::polygon_90_set_data box2NativePolygon(const Vector>& vBoxes)
30 | {
31 | typedef boost::polygon::property_merge_90 PropertyMergeType; // use Int as property_type
32 | typedef boost::polygon::polygon_90_set_data PolygonSetType;
33 | typedef Map, PolygonSetType> PropertyMergeResultType;
34 | PropertyMergeType pm;
35 | for (size_t idx = 0; idx < vBoxes.size(); ++idx) {
36 | pm.insert(vBoxes[idx], 0); // Use 0 as property -> do not distinguish shapes
37 | }
38 | PropertyMergeResultType result;
39 | pm.merge(result);
40 | for (const auto& mapPair : result) {
41 | return mapPair.second;
42 | }
43 | assert(false);
44 | return (*result.begin()).second;
45 | }
46 |
47 | template
48 | void box2Polygon(const Vector>& vBoxes, Vector>& polygonVec)
49 | {
50 | if (vBoxes.empty()) {
51 | return;
52 | }
53 | const auto& polygonSet = box2NativePolygon(vBoxes);
54 | polygonSet.get_polygons(polygonVec);
55 | }
56 |
57 | // convert the boxes into nonoverlapping boxes
58 | template
59 | inline void boxes2Boxes(const Vector>& vBoxes, Vector>& results)
60 | {
61 | if (vBoxes.empty()) {
62 | return;
63 | }
64 | const auto& polygon = box2NativePolygon(vBoxes);
65 | polygon.get_rectangles(results);
66 | }
67 |
68 | // convert the boxes into nonoverlapping boxes
69 | template
70 | inline void boxes2BoxesEmplace(Vector>& vBoxes)
71 | {
72 | if (vBoxes.empty()) {
73 | return;
74 | }
75 | const auto& polygon = box2NativePolygon(vBoxes);
76 | vBoxes.clear();
77 | polygon.get_rectangles(vBoxes);
78 | }
79 |
80 |
81 | // do difference on two vector of boxes
82 | template
83 | inline void boxesDiffAssign(Vector>& lhs, const Vector>& rhs)
84 | {
85 | typedef boost::polygon::polygon_90_set_data PolygonSetType;
86 | PolygonSetType lps, rps;
87 | for (const auto& rect : lhs) {
88 | lps.insert(rect);
89 | }
90 | for (const auto& rect : rhs) {
91 | rps.insert(rect);
92 | }
93 | boost::polygon::operators::operator-=(lps, rps);
94 | lhs.clear();
95 | lps.get_rectangles(lhs);
96 | }
97 |
98 | /// @brief do difference on two vector of boxes
99 | template
100 | inline void boxesAddAssign(Vector>& lhs, const Vector>& rhs)
101 | {
102 | typedef boost::polygon::polygon_90_set_data PolygonSetType;
103 | PolygonSetType lps, rps;
104 | for (const auto &rect : lhs)
105 | {
106 | lps.insert(rect);
107 | }
108 | for (const auto &rect : rhs)
109 | {
110 | rps.insert(rect);
111 | }
112 | boost::polygon::operators::operator+=(lps, rps);
113 | lhs.clear();
114 | lps.get_rectangles(lhs);
115 | }
116 | };
117 |
118 | PROJECT_NAMESPACE_END
119 |
120 |
--------------------------------------------------------------------------------
/cpp/src/geo/geometry.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | #pragma once
18 |
19 | #include "point.hpp"
20 | #include "point3d.hpp"
21 | #include "segment.hpp"
22 | #include "segment3d.hpp"
23 | #include "box.hpp"
24 | #include "kdtree.hpp"
25 | #include "intervaltree.hpp"
26 | #include "spatial.hpp"
27 | #include "spatial3d.hpp"
28 | #include "polygon2box.hpp"
29 |
30 |
--------------------------------------------------------------------------------
/cpp/src/geo/interval.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 | * SPDX-License-Identifier: Apache-2.0
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | #pragma once
18 |
19 | #include /// std::max std::min
20 | //#include
21 | #include "global/namespace.hpp"
22 | #include
23 | #include
24 |
25 | PROJECT_NAMESPACE_START
26 |
27 | template class Interval {
28 | public:
29 | explicit Interval() = default;
30 | explicit Interval(const T &begin, const T &end) {
31 | _begin = std::min(begin, end);
32 | _end = std::max(begin, end);
33 | }
34 |
35 | // Getters
36 | const T &begin() const { return _begin; }
37 | T &begin() { return _begin; }
38 | const T &end() const { return _end; }
39 | T &end() { return _end; }
40 | /// @brief get the length of the interval
41 | /// @return the length of the interval
42 | T length() const { return _end - _begin; }
43 |
44 | // setters
45 | void setBegin(const T &begin) {
46 | _begin = std::min(begin, _end);
47 | _end = std::max(begin, _end);
48 | }
49 | void setEnd(const T &end) {
50 | _begin = std::min(_begin, end);
51 | _end = std::max(_begin, end);
52 | }
53 |
54 | /*------------------------------*/
55 | /* Useful operations */
56 | /*------------------------------*/
57 | /// @brief determine if two interval are adjacent
58 | /// @param another Interval want to compare
59 | /// @return true if two intervals are adjacent to each other, false if not
60 | bool adjacent(const Interval &other) const;
61 | /// @brief operator <
62 | /// @param another Interval
63 | bool operator<(const Interval &rhs) const {
64 | return this->begin() == rhs.begin() ? this->end() < rhs.end()
65 | : this->begin() < rhs.end();
66 | }
67 | /// @brief operator ==
68 | /// @pararm another Interval
69 | bool operator==(const Interval &rhs) const {
70 | return this->begin() == rhs.begin() && this->end() == rhs.end();
71 | }
72 |
73 | private:
74 | T _begin;
75 | T _end;
76 | };
77 |
78 | template
79 | bool Interval::adjacent(const Interval &other) const {
80 |
81 | if (this->end() == other.begin()) {
82 | return true;
83 | }
84 | if (this->begin() == other.end()) {
85 | return true;
86 | }
87 | if (this->begin() == other.begin()) {
88 | return true;
89 | }
90 | if (this->end() == other.end()) {
91 | return true;
92 | }
93 | return false;
94 | }
95 |
96 | PROJECT_NAMESPACE_END
97 |
98 | /// @brief hash function for PROJECT_NAMASPACE::Interval
99 | namespace std {
100 | template | | | | | | | | | | | | | | | | | | | | | | | | | | | | |