11#! /bin/bash
22# ============================================================================
3- # SAGE-DB-Bench 部署脚本 (仅 PyCANDYAlgo)
3+ # SAGE-DB-Bench 部署脚本
44# ============================================================================
55#
66# 本脚本会:
99# 3. 安装 Python 依赖包
1010# 4. 初始化 Git submodules
1111# 5. 构建 PyCANDYAlgo
12- # 6. 安装 PyCANDYAlgo 到虚拟环境
13- # 7. 验证 PyCANDYAlgo 导入
12+ # 6. 构建 GTI、IP-DiskANN、PLSH
13+ # 7. 安装所有模块到虚拟环境
14+ # 8. 验证所有模块导入
1415#
1516# 使用方法:
1617# ./deploy.sh
@@ -117,7 +118,7 @@ print_info "Python 版本: $(python3.10 --version)"
117118# ============================================================================
118119# 开始部署
119120# ============================================================================
120- print_banner " SAGE-DB-Bench 部署 (PyCANDYAlgo) "
121+ print_banner " SAGE-DB-Bench 部署"
121122
122123SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
123124cd " $SCRIPT_DIR "
@@ -129,7 +130,7 @@ echo ""
129130# 步骤 1: 系统依赖
130131# ============================================================================
131132if [ " $SKIP_SYSTEM_DEPS " = false ]; then
132- print_header " 步骤 1/7 : 安装系统依赖"
133+ print_header " 步骤 1/8 : 安装系统依赖"
133134
134135 if [ -f /etc/os-release ]; then
135136 . /etc/os-release
@@ -163,13 +164,13 @@ if [ "$SKIP_SYSTEM_DEPS" = false ]; then
163164 print_warning " 非 Ubuntu/Debian 系统,请手动安装依赖"
164165 fi
165166else
166- print_header " 步骤 1/7 : 跳过系统依赖安装"
167+ print_header " 步骤 1/8 : 跳过系统依赖安装"
167168fi
168169
169170# ============================================================================
170171# 步骤 2: 创建虚拟环境
171172# ============================================================================
172- print_header " 步骤 2/7 : 创建 Python 虚拟环境"
173+ print_header " 步骤 2/8 : 创建 Python 虚拟环境"
173174
174175VENV_DIR=" $SCRIPT_DIR /sage-db-bench"
175176
@@ -191,7 +192,7 @@ pip install --upgrade pip setuptools wheel -q
191192# ============================================================================
192193# 步骤 3: 安装 Python 依赖
193194# ============================================================================
194- print_header " 步骤 3/7 : 安装 Python 依赖"
195+ print_header " 步骤 3/8 : 安装 Python 依赖"
195196
196197print_step " 安装 PyTorch (CPU 版本)..."
197198pip install torch --index-url https://download.pytorch.org/whl/cpu -q
@@ -204,7 +205,7 @@ print_success "Python 依赖安装完成"
204205# ============================================================================
205206# 步骤 4: 初始化 Git Submodules
206207# ============================================================================
207- print_header " 步骤 4/7 : 初始化 Git Submodules"
208+ print_header " 步骤 4/8 : 初始化 Git Submodules"
208209
209210if [ -f " .gitmodules" ]; then
210211 print_step " 初始化 submodules..."
218219# 步骤 5: 构建 PyCANDYAlgo
219220# ============================================================================
220221if [ " $SKIP_BUILD " = false ]; then
221- print_header " 步骤 5/7 : 构建 PyCANDYAlgo"
222+ print_header " 步骤 5/8 : 构建 PyCANDYAlgo"
222223
223224 cd " $SCRIPT_DIR /algorithms_impl"
224225
@@ -248,13 +249,93 @@ if [ "$SKIP_BUILD" = false ]; then
248249
249250 cd " $SCRIPT_DIR "
250251else
251- print_header " 步骤 5/7 : 跳过构建"
252+ print_header " 步骤 5/8 : 跳过构建"
252253fi
253254
254255# ============================================================================
255- # 步骤 6: 安装 PyCANDYAlgo
256+ # 步骤 6: 构建 GTI、IP-DiskANN、PLSH
256257# ============================================================================
257- print_header " 步骤 6/7: 安装 PyCANDYAlgo"
258+ if [ " $SKIP_BUILD " = false ]; then
259+ print_header " 步骤 6/8: 构建 GTI、IP-DiskANN、PLSH"
260+
261+ SITE_PACKAGES=$( python3 -c " import site; print(site.getsitepackages()[0])" )
262+
263+ # 计算并行编译数
264+ NPROC=$( nproc 2> /dev/null || echo 4)
265+ JOBS=$(( NPROC > 8 ? 8 : NPROC))
266+
267+ # --- 构建 GTI ---
268+ print_step " 构建 GTI (gti_wrapper)..."
269+ GTI_DIR=" $SCRIPT_DIR /algorithms_impl/gti/GTI"
270+ if [ -d " $GTI_DIR " ]; then
271+ cd " $GTI_DIR "
272+ rm -rf build 2> /dev/null || true
273+ mkdir -p build && cd build
274+ cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=$( which python3) 2>&1 | tail -5
275+ make -j${JOBS} 2>&1 | tail -10
276+ # 查找并复制 .so 文件
277+ SO_FILE=$( find . -name " gti_wrapper*.so" 2> /dev/null | head -1)
278+ if [ -n " $SO_FILE " ]; then
279+ cp " $SO_FILE " " $SITE_PACKAGES /"
280+ print_success " GTI (gti_wrapper) 构建完成"
281+ else
282+ print_warning " gti_wrapper.so 未找到"
283+ fi
284+ else
285+ print_warning " GTI 目录不存在: $GTI_DIR "
286+ fi
287+
288+ # --- 构建 IP-DiskANN ---
289+ print_step " 构建 IP-DiskANN (ipdiskann)..."
290+ IPDISKANN_DIR=" $SCRIPT_DIR /algorithms_impl/ipdiskann"
291+ if [ -d " $IPDISKANN_DIR " ]; then
292+ cd " $IPDISKANN_DIR "
293+ rm -rf build 2> /dev/null || true
294+ mkdir -p build && cd build
295+ cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=$( which python3) 2>&1 | tail -5
296+ make -j${JOBS} 2>&1 | tail -10
297+ # 查找并复制 .so 文件
298+ SO_FILE=$( find . -name " ipdiskann*.so" 2> /dev/null | head -1)
299+ if [ -n " $SO_FILE " ]; then
300+ cp " $SO_FILE " " $SITE_PACKAGES /"
301+ print_success " IP-DiskANN (ipdiskann) 构建完成"
302+ else
303+ print_warning " ipdiskann.so 未找到"
304+ fi
305+ else
306+ print_warning " IP-DiskANN 目录不存在: $IPDISKANN_DIR "
307+ fi
308+
309+ # --- 构建 PLSH ---
310+ print_step " 构建 PLSH (plsh_python)..."
311+ PLSH_DIR=" $SCRIPT_DIR /algorithms_impl/plsh"
312+ if [ -d " $PLSH_DIR " ]; then
313+ cd " $PLSH_DIR "
314+ rm -rf build 2> /dev/null || true
315+ mkdir -p build && cd build
316+ cmake .. -DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=$( which python3) 2>&1 | tail -5
317+ make -j${JOBS} 2>&1 | tail -10
318+ # 查找并复制 .so 文件
319+ SO_FILE=$( find . -name " plsh_python*.so" 2> /dev/null | head -1)
320+ if [ -n " $SO_FILE " ]; then
321+ cp " $SO_FILE " " $SITE_PACKAGES /"
322+ print_success " PLSH (plsh_python) 构建完成"
323+ else
324+ print_warning " plsh_python.so 未找到"
325+ fi
326+ else
327+ print_warning " PLSH 目录不存在: $PLSH_DIR "
328+ fi
329+
330+ cd " $SCRIPT_DIR "
331+ else
332+ print_header " 步骤 6/8: 跳过构建"
333+ fi
334+
335+ # ============================================================================
336+ # 步骤 7: 安装 PyCANDYAlgo
337+ # ============================================================================
338+ print_header " 步骤 7/8: 安装 PyCANDYAlgo"
258339
259340cd " $SCRIPT_DIR /algorithms_impl"
260341
284365cd " $SCRIPT_DIR "
285366
286367# ============================================================================
287- # 步骤 7: 验证 PyCANDYAlgo 导入
368+ # 步骤 8: 验证所有模块导入
288369# ============================================================================
289- print_header " 步骤 7/7: 验证 PyCANDYAlgo"
290-
291- print_step " 测试导入..."
370+ print_header " 步骤 8/8: 验证所有模块导入"
292371
293- # 测试 PyCANDYAlgo 导入
372+ print_step " 测试 PyCANDYAlgo... "
294373if python3 -c " import PyCANDYAlgo; print('VERSION:', PyCANDYAlgo.__version__)" 2>&1 ; then
295374 print_success " PyCANDYAlgo 导入成功"
296375else
297376 print_error " PyCANDYAlgo 导入失败"
298- # 显示详细错误
299377 python3 -c " import PyCANDYAlgo" 2>&1 || true
300378 exit 1
301379fi
302380
381+ print_step " 测试 gti_wrapper..."
382+ if python3 -c " import gti_wrapper; print('gti_wrapper OK')" 2>&1 ; then
383+ print_success " gti_wrapper 导入成功"
384+ else
385+ print_warning " gti_wrapper 导入失败 (可选模块)"
386+ fi
387+
388+ print_step " 测试 ipdiskann..."
389+ if python3 -c " import ipdiskann; print('ipdiskann OK')" 2>&1 ; then
390+ print_success " ipdiskann 导入成功"
391+ else
392+ print_warning " ipdiskann 导入失败 (可选模块)"
393+ fi
394+
395+ print_step " 测试 plsh_python..."
396+ if python3 -c " import plsh_python; print('plsh_python OK')" 2>&1 ; then
397+ print_success " plsh_python 导入成功"
398+ else
399+ print_warning " plsh_python 导入失败 (可选模块)"
400+ fi
401+
303402# 测试核心依赖
304403print_step " 测试核心依赖..."
305404python3 -c " import numpy; print('numpy:', numpy.__version__)" || print_warning " numpy 不可用"
@@ -310,7 +409,11 @@ python3 -c "import torch; print('torch:', torch.__version__)" || print_warning "
310409# ============================================================================
311410print_banner " 部署完成!"
312411
313- echo " ✅ PyCANDYAlgo 已成功构建并安装"
412+ echo " ✅ 已成功构建并安装以下模块:"
413+ echo " - PyCANDYAlgo"
414+ echo " - gti_wrapper (GTI)"
415+ echo " - ipdiskann (IP-DiskANN)"
416+ echo " - plsh_python (PLSH)"
314417echo " "
315418echo " 使用方法:"
316419echo " source sage-db-bench/bin/activate"
0 commit comments