forked from ccf-ai-infra/Intro-ops
165 lines
4.5 KiB
Plaintext
165 lines
4.5 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"# 00 — 环境配置与验证\n",
|
||
"\n",
|
||
"本 Notebook 帮助你验证 intro-ops 开发环境是否正确配置。\n",
|
||
"\n",
|
||
"## 检查清单\n",
|
||
"\n",
|
||
"1. GPU 是否可用\n",
|
||
"2. CUDA Toolkit 版本\n",
|
||
"3. PyTorch 是否正确安装\n",
|
||
"4. intro-ops 是否成功构建\n",
|
||
"5. 运行一个简单的基线测试"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Step 1: 检查 GPU 和 CUDA"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import torch\n",
|
||
"\n",
|
||
"print(f\"PyTorch 版本: {torch.__version__}\")\n",
|
||
"print(f\"CUDA 可用: {torch.cuda.is_available()}\")\n",
|
||
"\n",
|
||
"if torch.cuda.is_available():\n",
|
||
" print(f\"GPU 型号: {torch.cuda.get_device_name(0)}\")\n",
|
||
" print(f\"CUDA 版本: {torch.version.cuda}\")\n",
|
||
" print(f\"GPU 数量: {torch.cuda.device_count()}\")\n",
|
||
" print(f\"当前设备: {torch.cuda.current_device()}\")\n",
|
||
"else:\n",
|
||
" print(\"⚠️ 未检测到 CUDA GPU。intro-ops 需要 NVIDIA GPU 才能运行。\")\n",
|
||
" print(\" 请确认 CUDA Toolkit 和 NVIDIA 驱动已正确安装。\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Step 2: 检查 intro-ops 构建产物"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import os\n",
|
||
"import sys\n",
|
||
"\n",
|
||
"# 检查 CAMP_BUILD_DIR 环境变量\n",
|
||
"build_dir = os.environ.get(\"CAMP_BUILD_DIR\", \"build-nvidia\")\n",
|
||
"lib_path = os.path.join(build_dir, \"libcamp_ops.so\")\n",
|
||
"\n",
|
||
"print(f\"构建目录: {build_dir}\")\n",
|
||
"print(f\"库文件路径: {lib_path}\")\n",
|
||
"print(f\"库文件存在: {os.path.exists(lib_path)}\")\n",
|
||
"\n",
|
||
"if not os.path.exists(lib_path):\n",
|
||
" print(\"\\n⚠️ libcamp_ops.so 未找到。请先构建项目:\")\n",
|
||
" print(\" bash scripts/build_nvidia.sh configure\")\n",
|
||
" print(\" bash scripts/build_nvidia.sh build\")\n",
|
||
" print(f\"\\n 然后设置环境变量: export CAMP_BUILD_DIR={build_dir}\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Step 3: 验证 Python 依赖"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import importlib\n",
|
||
"\n",
|
||
"deps = [\"torch\", \"pytest\", \"cmake\", \"ninja\"]\n",
|
||
"for dep in deps:\n",
|
||
" try:\n",
|
||
" mod = importlib.import_module(dep)\n",
|
||
" version = getattr(mod, \"__version__\", \"unknown\")\n",
|
||
" print(f\"✓ {dep}: {version}\")\n",
|
||
" except ImportError:\n",
|
||
" print(f\"✗ {dep}: 未安装\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## Step 4: 运行基线测试\n",
|
||
"\n",
|
||
"如果以上检查全部通过,运行一个简单的 copy 算子测试验证端到端流程。"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import subprocess\n",
|
||
"import sys\n",
|
||
"\n",
|
||
"result = subprocess.run([\n",
|
||
" sys.executable, \"-m\", \"pytest\",\n",
|
||
" \"tests/op_tests/test_copy.py\", \"-v\",\n",
|
||
" \"--backend\", \"nvidia\",\n",
|
||
" \"-x\", # 遇到第一个失败就停止\n",
|
||
"], capture_output=True, text=True)\n",
|
||
"\n",
|
||
"print(result.stdout)\n",
|
||
"if result.returncode != 0:\n",
|
||
" print(result.stderr)\n",
|
||
" print(\"\\n⚠️ 基线测试失败。请检查上面的错误信息。\")\n",
|
||
"else:\n",
|
||
" print(\"\\n✓ 环境配置正确,可以开始学习了!\")"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "markdown",
|
||
"metadata": {},
|
||
"source": [
|
||
"## 常见问题\n",
|
||
"\n",
|
||
"- **`torch.cuda.is_available()` 返回 False**:检查 NVIDIA 驱动和 CUDA Toolkit 安装\n",
|
||
"- **`libcamp_ops.so` 不存在**:运行 `bash scripts/build_nvidia.sh configure && bash scripts/build_nvidia.sh build`\n",
|
||
"- **ImportError**:运行 `pip install -r requirements.txt`\n",
|
||
"\n",
|
||
"更多帮助见 `docs/FAQ.md` 和 `docs/troubleshooting.md`。"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "Python 3",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"name": "python",
|
||
"version": "3.12.0"
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 5
|
||
}
|