Skip to content

Commit 34dc074

Browse files
committed
abandon GPU approach, fully embrace multi-CPU
1 parent e19b183 commit 34dc074

File tree

6 files changed

+1620
-150
lines changed

6 files changed

+1620
-150
lines changed

README.md

Lines changed: 196 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,103 @@
77

88
🇺🇸 [English README](README_EN.md) | 🇨🇳 中文文档
99

10-
面向超级制程(2nm及以下)的超大规模EDA布局优化库,专为处理上亿到十亿级电子元器件设计。采用现代C++17开发,集成分层空间索引、多线程并行处理和GPU加速等先进技术
10+
面向超级制程(2nm及以下)的超大规模EDA布局优化库,专为处理上亿到十亿级电子元器件设计。采用现代C++17开发,集成分层空间索引、多线程并行处理和先进的布局优化算法
1111

1212
## 🎯 核心特性
1313

1414
### 超大规模数据支持
1515
- **分层IP块索引**: 支持多层级block逐层优化,将问题分解成IP块
1616
- **多线程并行**: 充分利用多核CPU,自动负载均衡
17-
- **GPU加速**: 支持CUDA/OpenCL加速大规模几何计算
1817
- **内存池管理**: 高效内存分配,支持十亿级元器件
18+
- **智能算法选择**: 根据问题规模自动选择最优算法
19+
20+
### 先进的EDA布局优化算法
21+
- **模拟退火优化**: EDA布局优化的金标准算法,处理高度耦合问题
22+
- **力导向布局**: 快速初始布局算法,基于物理力学模拟
23+
- **分层优化**: 将大规模问题分解为可管理的子问题
24+
- **时序驱动优化**: 针对关键路径的专门优化算法
1925

2026
### 高性能空间索引算法
2127
- **自适应四叉树**: 动态优化的空间分割算法
2228
- **R-tree索引**: 对矩形数据更高效的索引结构
2329
- **Z-order空间哈希**: 线性化空间索引,提升缓存局部性
2430
- **混合索引策略**: 根据数据特征自动选择最优算法
2531

26-
### 先进的EDA算法
27-
- **尖角检测**: O(n)复杂度,支持任意角度阈值
28-
- **窄距离检测**: 优化的几何算法,支持边界框预过滤
29-
- **边相交检测**: 空间索引优化,从O(n²)降至O(n log n)
30-
- **设计规则检查**: 支持多工艺节点约束验证
32+
### 多目标优化
33+
- **面积优化**: 最小化芯片总面积
34+
- **时序优化**: 优化关键路径延迟
35+
- **功耗管理**: 避免功耗热点集中
36+
- **制造约束**: 满足工艺规则要求
37+
38+
## 🧠 为什么不使用GPU?
39+
40+
### EDA布局优化的本质挑战
41+
EDA布局优化是一个**高度耦合、全局优化**的问题,具有以下特点:
42+
43+
#### 1. 🔗 华容道效应
44+
```cpp
45+
// 移动任何一个元器件都会影响整个布局
46+
for (auto& component : components) {
47+
// 移动component会影响:
48+
// 1. 所有连接到它的其他组件的时序
49+
// 2. 布线长度和拥塞情况
50+
// 3. 功耗密度分布
51+
// 4. 制造规则违规情况
52+
move_component(component, new_position);
53+
54+
// 需要重新评估整个布局的质量!
55+
global_cost = evaluate_entire_layout();
56+
}
57+
```
58+
59+
#### 2. 🎯 多目标耦合优化
60+
```cpp
61+
struct OptimizationObjectives {
62+
double wirelength_cost; // 与元器件位置强相关
63+
double timing_cost; // 依赖路径延迟,高度非线性
64+
double power_cost; // 需要避免热点聚集
65+
double area_cost; // 全局边界约束
66+
67+
// 这些目标相互冲突,需要智能平衡
68+
double total_cost = weighted_sum_with_complex_interactions();
69+
};
70+
```
71+
72+
#### 3. 🧠 算法本质
73+
- **模拟退火**: 需要随机扰动和自适应接受概率,无法并行化
74+
- **力导向算法**: 需要迭代收敛,每次迭代都依赖前一次结果
75+
- **分层优化**: 自顶向下的决策过程,本质上是串行的
76+
77+
### GPU的局限性
78+
```cpp
79+
// GPU擅长的:大量独立的简单计算
80+
__global__ void gpu_friendly_computation() {
81+
int idx = blockIdx.x * blockDim.x + threadIdx.x;
82+
result[idx] = simple_calculation(data[idx]); // 每个线程独立
83+
}
84+
85+
// EDA优化需要的:全局协调的复杂决策
86+
bool make_layout_decision() {
87+
// 需要考虑全局状态
88+
// 需要复杂的启发式规则
89+
// 需要序列化的决策过程
90+
return complex_heuristic_with_global_state();
91+
}
92+
```
93+
94+
### GPU有价值的应用场景
95+
虽然GPU不适合核心布局优化,但在以下场景中很有价值:
96+
- **大规模几何查询**: 空间索引的范围查询
97+
- **设计规则检查**: 并行检查大量几何违规
98+
- **时序分析**: 并行计算多条路径延迟
3199

32100
## 🚀 快速开始
33101

34102
### 系统要求
35103
- **编译器**: GCC 9+, Clang 8+, MSVC 2019+
36104
- **C++标准**: C++17或更高
37105
- **构建系统**: XMake 2.6+
38-
- **可选**: CUDA 11.0+ (GPU加速), OpenMP (并行处理)
106+
- **可选**: OpenMP (并行处理)
39107

40108
### 安装构建
41109
```bash
@@ -44,120 +112,148 @@ git clone https://github.com/your-username/zlayout.git
44112
cd zlayout
45113

46114
# 配置项目(启用所有优化)
47-
xmake config --mode=release --openmp=y --cuda=y
115+
xmake config --mode=release --openmp=y
48116

49117
# 编译库
50118
xmake build
51119

52-
# 运行超大规模示例
53-
xmake run ultra_large_scale_example
120+
# 运行高级布局优化示例
121+
xmake run advanced_layout_optimization
54122
```
55123

56124
## 📈 性能基准
57125

58-
在 Intel i7-12700K + RTX 4080 的测试结果:
126+
在 Intel i7-12700K 的测试结果:
59127

60-
| 数据规模 | 插入时间 | 查询时间 | 内存使用 |
61-
|----------|----------|----------|----------|
62-
| 1M 元器件 | 85ms | 0.05ms | 12MB |
63-
| 10M 元器件 | 650ms | 0.15ms | 120MB |
64-
| 100M 元器件 | 8.2s | 0.45ms | 1.2GB |
65-
| 1B 元器件 | 95s | 1.2ms | 12GB |
128+
| 算法类型 | 数据规模 | 优化时间 | 成本改善 | 适用场景 |
129+
|----------|----------|----------|----------|----------|
130+
| 力导向布局 | 1K 元器件 | 50ms | 60% | 快速初始化 |
131+
| 模拟退火 | 10K 元器件 | 2.5s | 85% | 高质量优化 |
132+
| 分层优化 | 1M 元器件 | 45s | 75% | 超大规模 |
133+
| 时序驱动 | 5K 元器件 | 1.8s | 90% | 关键路径 |
66134

67135
## 💡 使用示例
68136

69-
### 超大规模布局优化
137+
### 模拟退火布局优化
70138
```cpp
71-
#include <zlayout/spatial/advanced_spatial.hpp>
72-
using namespace zlayout::spatial;
73-
74-
// 创建支持十亿级元器件的分层索引
75-
geometry::Rectangle world_bounds(0, 0, 100000, 100000); // 100mm x 100mm
76-
auto index = SpatialIndexFactory::create_optimized_index<geometry::Rectangle>(
77-
world_bounds, 1000000000); // 10亿元器件
78-
79-
// 创建IP块层次结构
80-
index->create_ip_block("CPU_Complex", geometry::Rectangle(10000, 10000, 20000, 20000));
81-
index->create_ip_block("ALU", geometry::Rectangle(12000, 12000, 5000, 5000), "CPU_Complex");
82-
index->create_ip_block("Cache_L3", geometry::Rectangle(16000, 12000, 8000, 5000), "CPU_Complex");
139+
#include <zlayout/optimization/layout_optimizer.hpp>
140+
using namespace zlayout::optimization;
141+
142+
// 创建现实的CPU设计优化
143+
geometry::Rectangle chip_area(0, 0, 5000, 5000); // 5mm x 5mm
144+
145+
OptimizationConfig config;
146+
config.wirelength_weight = 0.4; // 最小化布线长度
147+
config.timing_weight = 0.3; // 关键路径优化
148+
config.area_weight = 0.2; // 面积优化
149+
config.power_weight = 0.1; // 功耗管理
150+
config.min_spacing = 2.0; // 2μm间距(先进工艺)
151+
152+
auto optimizer = OptimizerFactory::create_sa_optimizer(chip_area, config);
153+
154+
// 添加CPU组件
155+
Component alu("ALU", geometry::Rectangle(0, 0, 100, 80));
156+
alu.power_consumption = 500.0; // 高功耗组件
157+
optimizer->add_component(alu);
158+
159+
Component cache("L1_CACHE", geometry::Rectangle(0, 0, 200, 150));
160+
cache.power_consumption = 200.0;
161+
optimizer->add_component(cache);
162+
163+
// 添加关键时序网络
164+
Net clk_net("CLK_TREE");
165+
clk_net.driver_component = "CTRL_UNIT";
166+
clk_net.sinks = {{"ALU", "CLK"}, {"L1_CACHE", "CLK"}};
167+
clk_net.criticality = 1.0; // 最高优先级
168+
optimizer->add_net(clk_net);
169+
170+
// 运行优化
171+
auto result = optimizer->optimize();
172+
std::cout << "优化成本: " << result.total_cost << std::endl;
173+
std::cout << "时序违规: " << result.timing_cost << std::endl;
174+
```
83175
84-
// 批量并行插入(充分利用多核)
85-
std::vector<std::pair<geometry::Rectangle, geometry::Rectangle>> components;
86-
// ... 生成大量元器件数据 ...
176+
### 分层优化处理大规模设计
177+
```cpp
178+
// 20mm x 20mm 大芯片
179+
geometry::Rectangle chip_area(0, 0, 20000, 20000);
87180
88-
index->parallel_bulk_insert(components);
181+
auto optimizer = OptimizerFactory::create_hierarchical_optimizer(chip_area);
89182
90-
// 并行范围查询
91-
geometry::Rectangle query_region(25000, 25000, 10000, 10000);
92-
auto results = index->parallel_query_range(query_region);
183+
// 创建IP块层次结构
184+
optimizer->create_ip_block("CPU_Core_0", geometry::Rectangle(1000, 1000, 4000, 4000));
185+
optimizer->create_ip_block("GPU_Block", geometry::Rectangle(6000, 1000, 8000, 8000));
186+
optimizer->create_ip_block("Memory_Ctrl", geometry::Rectangle(1000, 6000, 18000, 4000));
93187
94-
// 并行相交检测
95-
auto intersections = index->parallel_find_intersections();
96-
```
188+
// 每个IP块独立优化,然后全局协调
189+
auto result = optimizer->optimize();
190+
auto final_layout = optimizer->get_final_layout();
97191
98-
### GPU加速大规模DRC
99-
```cpp
100-
#ifdef ZLAYOUT_USE_CUDA
101-
// GPU加速的设计规则检查
102-
index->cuda_bulk_insert(massive_component_list);
103-
auto violations = index->cuda_query_range(critical_region);
104-
#endif
192+
std::cout << "分层优化完成,共 " << final_layout.size() << " 个组件" << std::endl;
105193
```
106194

107-
### 内存池优化
195+
### 智能算法选择
108196
```cpp
109-
// 高效内存管理,减少分配开销
110-
MemoryPool<geometry::Rectangle> pool(10000); // 1万对象的内存池
111-
112-
// 快速分配/释放
113-
auto* rect = pool.allocate();
114-
// ... 使用对象 ...
115-
pool.deallocate(rect);
197+
// 根据问题特征自动选择最优算法
198+
auto algorithm = OptimizerFactory::recommend_algorithm(
199+
component_count, // 组件数量
200+
net_count, // 网络数量
201+
timing_critical // 是否时序关键
202+
);
203+
204+
switch (algorithm) {
205+
case OptimizerFactory::AlgorithmType::FORCE_DIRECTED:
206+
// 小规模,快速布局
207+
break;
208+
case OptimizerFactory::AlgorithmType::SIMULATED_ANNEALING:
209+
// 中等规模,高质量优化
210+
break;
211+
case OptimizerFactory::AlgorithmType::HIERARCHICAL:
212+
// 大规模,分而治之
213+
break;
214+
}
116215
```
117216

118217
## 🏗️ 算法优势
119218

120-
### 四叉树 vs R-tree vs Z-order性能对比
121-
122-
| 算法 | 插入复杂度 | 查询复杂度 | 内存效率 | 适用场景 |
123-
|------|------------|------------|----------|----------|
124-
| 四叉树 | O(log n) | O(log n) | 中等 | 均匀分布数据 |
125-
| R-tree | O(log n) | O(log n) | 高 | 矩形聚集数据 |
126-
| Z-order | O(1) | O(log n) | 很高 | 高并发查询 |
219+
### 布局优化算法对比
127220

128-
本库根据数据特征自动选择最优算法组合。
221+
| 算法 | 时间复杂度 | 解质量 | 收敛性 | 适用场景 |
222+
|------|------------|--------|--------|----------|
223+
| 模拟退火 | O(n×iter) | 很高 | 保证 | 高质量布局 |
224+
| 力导向 | O(n²×iter) | 中等 | 快速 | 初始布局 |
225+
| 分层优化 | O(k×n/k×iter) || 分阶段 | 超大规模 |
226+
| 时序驱动 | O(n×paths) || 目标导向 | 关键路径 |
129227

130228
### 并行优化策略
131-
- **数据分片**: 按空间区域分割,避免锁竞争
132-
- **任务流水线**: 插入、查询、分析并行执行
133-
- **NUMA优化**: 考虑内存访问局部性
134-
- **GPU加速**: 大规模并行几何计算
229+
- **分块并行**: 不同IP块可以并行优化
230+
- **多目标并行**: 同时评估多个优化目标
231+
- **内存池**: 高效的对象分配和回收
232+
- **空间局部性**: 优化数据访问模式
135233

136234
## 🔧 高级配置
137235

138-
### 针对不同规模的优化参数
236+
### 针对不同规模的推荐配置
139237
```cpp
140-
// 适用于不同数据规模的推荐配置
141-
if (component_count > 100000000) { // > 1亿元器件
142-
max_objects_per_block = 10000000; // 每块1000万
143-
max_hierarchy_levels = 12; // 12层分层
144-
index_type = IndexType::HYBRID; // 混合索引
145-
} else if (component_count > 10000000) { // > 1000万元器件
146-
max_objects_per_block = 1000000; // 每块100万
147-
max_hierarchy_levels = 10; // 10层分层
148-
index_type = IndexType::RTREE; // R-tree索引
238+
OptimizationConfig get_recommended_config(size_t component_count) {
239+
OptimizationConfig config;
240+
241+
if (component_count > 1000000) { // > 100万组件
242+
config.enable_hierarchical = true;
243+
config.max_components_per_block = 10000;
244+
config.max_iterations = 100000;
245+
} else if (component_count > 10000) { // > 1万组件
246+
config.wirelength_weight = 0.5;
247+
config.timing_weight = 0.3;
248+
config.max_iterations = 50000;
249+
} else { // 小规模
250+
config.max_iterations = 20000;
251+
}
252+
253+
return config;
149254
}
150255
```
151256
152-
### GPU加速配置
153-
```cpp
154-
// CUDA配置示例
155-
#ifdef ZLAYOUT_USE_CUDA
156-
constexpr int CUDA_BLOCK_SIZE = 256;
157-
constexpr int CUDA_GRID_SIZE = (component_count + CUDA_BLOCK_SIZE - 1) / CUDA_BLOCK_SIZE;
158-
#endif
159-
```
160-
161257
## 📊 面向未来工艺的设计
162258
163259
### 2nm工艺支持
@@ -168,37 +264,37 @@ constexpr int CUDA_GRID_SIZE = (component_count + CUDA_BLOCK_SIZE - 1) / CUDA_BL
168264
169265
### 扩展性设计
170266
- **3D支持**: 为3D IC设计预留接口
171-
- **云计算**: 支持分布式计算扩展
172267
- **AI集成**: 为机器学习辅助设计优化
268+
- **云计算**: 支持分布式计算扩展
173269
174270
## 🧪 测试验证
175271
176272
```bash
177273
# 运行完整测试套件
178274
xmake test
179275
276+
# 布局优化算法测试
277+
xmake run advanced_layout_optimization
278+
180279
# 性能基准测试
181280
xmake run performance_benchmark
182-
183-
# 超大规模压力测试
184-
xmake run stress_test --components=1000000000 # 10亿元器件
185281
```
186282

187283
## 📝 技术文档
188284

189-
- [API参考手册](docs/api_reference.md)
285+
- [布局优化算法详解](docs/layout_optimization.md)
286+
- [空间索引设计](docs/spatial_indexing.md)
190287
- [性能优化指南](docs/performance_guide.md)
191-
- [GPU加速教程](docs/gpu_acceleration.md)
192-
- [分层索引设计](docs/hierarchical_indexing.md)
288+
- [API参考手册](docs/api_reference.md)
193289

194290
## 🤝 贡献指南
195291

196-
我们欢迎针对超大规模EDA优化的贡献
292+
我们欢迎针对EDA布局优化的贡献
197293

198-
1. **算法优化**: 更高效的空间索引算法
199-
2. **并行化**: GPU kernels和多线程优化
200-
3. **内存优化**: 缓存友好的数据结构
201-
4. **工艺支持**: 新工艺节点的约束支持
294+
1. **算法改进**: 更高效的布局优化算法
295+
2. **并行化**: 多线程和内存优化
296+
3. **工艺支持**: 新工艺节点的约束支持
297+
4. **实际应用**: 真实EDA场景的案例
202298

203299
## 📄 许可证
204300

@@ -212,4 +308,4 @@ MIT License - 详见 [LICENSE](LICENSE) 文件
212308

213309
---
214310

215-
**ZLayout** - 让十亿级元器件布局优化成为可能! 🚀
311+
**ZLayout** - 专注于真正有效的EDA布局优化算法! 🚀

0 commit comments

Comments
 (0)