平行化分析 #4
5000user5000
started this conversation in
General
Replies: 2 comments 3 replies
-
|
CUDA 加速面向筆記 1️⃣ 批量距離計算 為什麼適合:
應該加速的地方: CUDA 優勢:
2️⃣ 批量查詢優化(GPU 最佳使用場景) 為什麼重要: CUDA 優勢:
3️⃣ K-means 訓練加速(中等優先)
CUDA 優勢:
實作建議 📋 CUDA 實作優先順序建議 ● 🏗️ 實作架構設計
📊 性能預期
註: GPU 有記憶體傳輸開銷,小規模計算反而可能更慢 🎯 關鍵設計決策
🔧 Makefile 修改 需要加入 CUDA 編譯器總結建議 ✅ 優先實作
📈 預期效果
|
Beta Was this translation helpful? Give feedback.
3 replies
-
|
11/25 update 已完成 CUDA 版本的大致雛形, 現在的問題是 k=100 會產生 shared memory 不夠的 error 而無法執行, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
層次 1:SIMD 向量化(資料層級平行化)
位置:SimdUtils.h - L2 距離計算
程式碼位置:include/zenann/SimdUtils.h:5-14
當前實現(Naive):
平行化潛力:
被調用處:
IVFFlatIndex::search()- 第 52, 69 行IVFFlatIndex::train()- 第 32-34 行(內嵌版本)IVFFlatIndex::kmeans()- 第 144-147 行(內嵌版本)優化方向:
層次 2:OpenMP 多線程(任務層級平行化)
2.1
IVFFlatIndex::search()- 質心距離計算位置:src/IVFFlatIndex.cpp:51-54
當前實現:
平行化潛力:
-條件:nlist 足夠大(通常 100+)
優化方向:
2.2
IVFFlatIndex::search()- 列表探測位置:src/IVFFlatIndex.cpp:65-81
當前實現:
平行化潛力:
優化方向:
2.3
IVFFlatIndex::search_batch()- 批量查詢位置:src/IVFFlatIndex.cpp:108-110
當前實現:
平行化潛力:
優化方向:
2.4
IVFFlatIndex::kmeans()- K-means 訓練位置:src/IVFFlatIndex.cpp:139-155 和 160-165
2.4.1 Assignment 階段(E-step)
平行化潛力:
2.4.2 Update 階段(M-step)
平行化潛力:
優化方向:
2.5
IVFFlatIndex::train()- 構建倒排表位置:src/IVFFlatIndex.cpp:26-42
當前實現:
平行化潛力:
層次 3:其他平行化機會
3.1 Pipeline 平行化
概念:將索引構建和搜尋流水線化
場景:
3.2 GPU 加速(未來方向)
適合 GPU 的操作:
平行化優先級
高優先級(容易 + 高回報)
中優先級(中等難度 + 中等回報)
低優先級(複雜 + 回報不確定)
組合優化效果預估
假設 8 核心 CPU + AVX2:
實作順序
階段 1:基礎 SIMD(1-2 天)
SimdUtils.h: l2_naive → l2_simd (AVX2)
階段 2:簡單 OpenMP(1 天)
階段 3:複雜 OpenMP(2-3 天)
3. search() 列表探測(thread-local heap)
4. kmeans() E-step
階段 4:進階優化(選做)
5. kmeans() M-step (reduction)
6. train() 倒排表構建
Beta Was this translation helpful? Give feedback.
All reactions