DreamPlace 是一款芯片放置工具,用于宏单元(macro)和标准单元(Standard Cell)的放置以及布线,并计算 HPWL、Overlap 等用于衡量芯片性能的参数。
文章目录
一、环境
1. 系统环境:Ubuntu 20.04
DreamPlace 只能在 Linux 环境使用
2. Python 环境:
- Python 3.8
- PyTorch 2.0.0
- Cuda 11.8
前排提醒:如果使用 conda 创建了不同的 python 环境,则每个环境如果想使用 DREAMPlace 都要各自安装一遍
二、安装 Dreamplace
1. 安装第三方 Dependency
- Boost
sudo apt-get update sudo apt-get install libboost-all-dev
- Bison & flex
sudo apt-get install flex bison
2. 下载 DreamPlace
git clone --recursive https://github.com/limbo018/DREAMPlace.git
3. 安装 Python Dependency
cd DREAMPlace
pip install -r requirements.txt
4. Build Dreamplace
build 之前需要先打开 DREAMPlace/dreamplace/ops/CMakeLists.txt
文件,把第 12 行的注释打开(不然无法安装这个包,我在运行 deepplace 的时候用到了这个包,其他情况下还没有用到)
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=<installation directory> -DPython_EXECUTABLE=$(which python)
make
make install
-DCMAKE_INSTALL_PREFIX
是安装路径,默认是DREAMPLACE/install
-DPython_EXECUTABLE
是 python 路径,如果有 anaconda 默认是 base 环境
5. Install Benchmarks
cd ../install
python benchmarks/ispd2005_2015.py
另外,benchmark 也可以自己下载并解压到正确的文件夹下,具体位置可参考下文目录树。DreamPlace 只支持 bookshelf 和 Lef/Def 格式的文件。
6. 测试是否安装成功
python dreamplace/Placer.py test/ispd2005/adaptec1.json
python unittest/ops/hpwl_unittest.py
安装完成后的目录结构如下,主要用到的东西都在 install
文件夹内:
DREAMPlace
|-- CMakeLists.txt
|-- Dockerfile
|-- LICENSE
|-- README.md
|-- benchmarks
|-- build
|-- cmake
|-- dreamplace
|-- images
|-- install
| |-- benchmarks
| | |-- ispd2005
| | | |-- adaptec1
| | | | |-- adaptec1.aux
| | | | |-- adaptec1.dp.aux
| | | | |-- adaptec1.eplace-ip.pl
| | | | |-- adaptec1.eplace.aux
| | | | |-- adaptec1.lg.pl
| | | | |-- adaptec1.nets
| | | | |-- adaptec1.nodes
| | | | |-- adaptec1.pl
| | | | |-- adaptec1.scl
| | | | `-- adaptec1.wts
| | | |-- adaptec2
| | | |-- adaptec3
| | | |-- adaptec4
| | | |-- bigblue1
| | | |-- bigblue2
| | | |-- bigblue3
| | | `-- bigblue4
| | |-- ispd2005_2015.py
| | `-- ispd2019.py
| |-- bin
| |-- dreamplace
| | |-- BasicPlace.py
| | |-- EvalMetrics.py
| | |-- NesterovAcceleratedGradientOptimizer.py
| | |-- NonLinearPlace.py
| | |-- Params.py
| | |-- PlaceDB.py
| | |-- PlaceObj.py
| | |-- Placer.py
| | |-- Timer.py
| | |-- __init__.py
| | |-- configure.py
| | |-- ops
| | `-- params.json
| |-- include
| |-- lib
| |-- test
| | |-- dac2012
| | |-- iccad2014
| | |-- iccad2015.ot
| | |-- ispd2005
| | |-- ispd2015
| | `-- ispd2019
| |-- thirdparty
| `-- unittest
|-- requirements.txt
|-- test
|-- thirdparty
`-- unittest
三、测试脚本
回到根目录根目录创建新文件夹,并创建测试脚本
cd ~
mkdir test_dreamplace
cd test_dreamplace
vim main.py
脚本内容如下,其中 params 用来加载配置参数,我们需要提供关于 bechmark 的配置文件,配置文件格式可以参考 test
文件夹内的文件:
import Params, Placer
params = Params.Params()
# load parameters
add = "./test/ispd2005/adaptec3.json"
params.load(add)
r = Placer.place(params)
r = r[-3][0]
wl = float(r[0].hpwl.data)
overf = float(r[0].overflow.data)
print(wl)
print(overf)
将 DreamPlace 移植到该目录下:
cd ~
cp -r DREAMPlace/install/* test_dreamplace/
然后将 test_dreamplace/dreamplace
文件夹下的除 ops、init.py、configure.py 之外的其他文件移动到 test_dreamplace/
目录下。
之后运行脚本跑通即可:
python main.py
目前该文件夹结构为:
test_dreamplace
|-- BasicPlace.py
|-- EvalMetrics.py
|-- NesterovAcceleratedGradientOptimizer.py
|-- NonLinearPlace.py
|-- Params.py
|-- PlaceDB.py
|-- PlaceObj.py
|-- Placer.py
|-- Timer.py
|-- __pycache__
|-- benchmarks
| |-- ispd2005
| |-- ispd2005_2015.py
| `-- ispd2019.py
|-- bin
|-- dreamplace
| |-- __init__.py
| |-- __pycache__
| |-- configure.py
| `-- ops
|-- include
|-- lib
|-- main.py
|-- params.json
|-- results
| `-- adaptec3
|-- test
|-- thirdparty
`-- unittest
四、遇到的问题
4.1 Ubuntu 系统版本不一致
在使用 make
时出现如下报错信息:
error: size of array 'altStackMem' is not an integral constant-expression
4008 | static char altStackMem[4 * SIGSTKSZ];
| ^
原因是使用了 Ubuntu 21.x 或者 22.x 版本,应该使用 Ubuntu 20.x 版本。因为在新版本中的一个改动 ABI change introduced in glibc 2.34 修改了 SIGSTKSZ
的定义,导致它不再是一个常量,而是通过 sysconf (_SC_SIGSTKSZ)
函数计算得到,而且也很明确说明了如果假设 SIGSTKSZ
是常量的话会报错。
解决方法
- 更换 Linux 系统
- 在报错的文件开头重定义
SIGSTKSZ
#undef #define SIGSTKSZ 32768
- 直接将用到
SIGSTKSZ
的位置替换为 32768
4.2 anaconda 环境 version ‘GLIBCXX_3.4.30’ not found 问题
在运行 dreamplace/Placer.py
程序时出现以下错误:
ImportError: /home/[用户名]/anaconda3/envs/[环境名]/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found
解决方法
- 检查是否存在
GLIBCXX_3.4.30
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
- 如果存在,建立软链接
cd /home/[用户名]/anaconda3/envs/[环境名]/lib/ mv libstdc++.so.6 libstdc++.so.6.old ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 libstdc++.so.6
4.3 C++ 编译器版本问题
在使用 circuit_training
这个分支进行 make
的时候,出现如下错误:
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:4:2: error: #error C++17 or later compatible compiler is required to use PyTorch.
4 | #error C++17 or later compatible compiler is required to use PyTorch.
| ^~~~~
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/c10/util/string_view.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/c10/util/StringUtil.h:6,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/c10/util/Exception.h:5,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/c10/core/Device.h:5,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/TensorBody.h:11,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/Tensor.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/Tensor.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/function_hook.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/cpp_hook.h:2,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/variable.h:6,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/autograd.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/autograd.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:7,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/c10/util/C++17.h:27:2: error: #error You need C++17 to compile PyTorch
27 | #error You need C++17 to compile PyTorch
| ^~~~~
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:9,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/ATen.h:4:2: error: #error C++17 or later compatible compiler is required to use ATen.
4 | #error C++17 or later compatible compiler is required to use ATen.
| ^~~~~
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/jit/ir/ir.h:18,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/jit/api/function_impl.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/jit/api/method.h:7,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/jit/api/object.h:6,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/jit/api/module.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/serialize/input-archive.h:6,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/serialize/archive.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/samplers/serialize.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/samplers.h:8,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets/chunk.h:7,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data/datasets.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/data.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:9,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/interned_strings.h:354:1: error: macro "assert_msg" requires 2 arguments, but only 1 given
354 | FORALL_NS_SYMBOLS(DEFINE_SYMBOL)
| ^~~~~~~~~~~~~~~
In file included from /home/yzc/git_repo/DREAMPlace/thirdparty/Limbo/limbo/programoptions/ProgramOptions.h:21,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/Params.h:14,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PlaceDB.h:26,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:16,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/git_repo/DREAMPlace/thirdparty/Limbo/limbo/preprocessor/AssertMsg.h:34: note: macro "assert_msg" defined here
34 | #define assert_msg(condition, message) \
|
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue.h:1499,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/List_inl.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/List.h:490,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/IListRef_inl.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/IListRef.h:632,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/WrapDimUtils.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/TensorNames.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/NamedTensorUtils.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/variable.h:11,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/autograd.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/autograd.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:7,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h: In lambda function:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h:1061:30: error: ‘is_convertible_v’ is not a member of ‘std’; did you mean ‘is_convertible’?
1061 | if constexpr (::std::is_convertible_v<typename c10::invoke_result_t<T &&, Future&>, IValueWithStorages>) {
| ^~~~~~~~~~~~~~~~
| is_convertible
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h:1061:91: error: expected ‘(’ before ‘,’ token
1061 | s_convertible_v<typename c10::invoke_result_t<T &&, Future&>, IValueWithStorages>) {
| ^
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h:1061:111: error: expected primary-expression before ‘>’ token
1061 | _v<typename c10::invoke_result_t<T &&, Future&>, IValueWithStorages>) {
| ^
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/ivalue_inl.h:1061:112: error: expected primary-expression before ‘)’ token
1061 | _v<typename c10::invoke_result_t<T &&, Future&>, IValueWithStorages>) {
| ^
In file included from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/KernelFunction_impl.h:1,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/KernelFunction.h:251,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/op_registration/op_registration.h:11,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/library.h:68,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/autograd/autograd_not_implemented_fallback.h:3,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/autograd.h:4,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/csrc/api/include/torch/all.h:7,
from /home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/torch/extension.h:5,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/../utility/src/torch.h:13,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.h:18,
from /home/yzc/git_repo/DREAMPlace/dreamplace/ops/place_io/src/PyPlaceDB.cpp:8:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/impl/boxing.h: In static member function ‘static Result c10::impl::BoxedKernelWrapper<Result(Args ...), typename std::enable_if<((c10::guts::conjunction<c10::guts::disjunction<std::is_constructible<c10::IValue, typename std::decay<Args>::type>, std::is_same<c10::TensorOptions, typename std::decay<Args>::type> >...>::value && c10::guts::conjunction<c10::guts::disjunction<c10::impl::has_ivalue_to<T, void>, std::is_same<void, ReturnType> >, c10::guts::negation<std::is_lvalue_reference<_Tp> > >::value) && (! c10::impl::is_tuple_of_mutable_tensor_refs<Result>::value)), void>::type>::call(const c10::BoxedKernel&, const c10::OperatorHandle&, c10::DispatchKeySet, Args ...)’:
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/impl/boxing.h:229:25: error: ‘is_same_v’ is not a member of ‘std’; did you mean ‘is_same’?
229 | if constexpr (!std::is_same_v<void, Result>) {
| ^~~~~~~~~
| is_same
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/impl/boxing.h:229:35: error: expected primary-expression before ‘void’
229 | if constexpr (!std::is_same_v<void, Result>) {
| ^~~~
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/impl/boxing.h:229:35: error: expected ‘)’ before ‘void’
/home/yzc/anaconda3/envs/graphplace/lib/python3.9/site-packages/torch/include/ATen/core/boxing/impl/boxing.h:229:18: note: to match this ‘(’
229 | if constexpr (!std::is_same_v<void, Result>) {
| ^
make[2]: *** [dreamplace/ops/place_io/CMakeFiles/place_io_cpp.dir/build.make:233:dreamplace/ops/place_io/CMakeFiles/place_io_cpp.dir/src/PyPlaceDB.cpp.o] 错误 1
make[2]: 离开目录“/home/yzc/git_repo/DREAMPlace/build”
make[1]: *** [CMakeFiles/Makefile2:2862:dreamplace/ops/place_io/CMakeFiles/place_io_cpp.dir/all] 错误 2
make[1]: 离开目录“/home/yzc/git_repo/DREAMPlace/build”
make: *** [Makefile:139:all] 错误 2
解决方法:
问题在于最新的 Pytorch 版本不兼容(2.1.2),将 torch 换成 2.0.1 版本即可