# XMake-AscendC **Repository Path**: sutonghua/xmake-ascend-c ## Basic Information - **Project Name**: XMake-AscendC - **Description**: No description available - **Primary Language**: C/C++ - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-19 - **Last Updated**: 2025-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
# 🛠️ xmake-ascend-c **🚀 为华为昇腾 Ascend C 算子开发打造的现代化 xmake 构建工具链** [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![XMake](https://img.shields.io/badge/xmake-≥2.3.4-22c55e.svg)](https://xmake.io) [![Platform](https://img.shields.io/badge/platform-Linux%20|%20Ascend-orange.svg)]() [![CANN](https://img.shields.io/badge/CANN-8.x-red.svg)](https://www.hiascend.com/) [快速开始](#-快速开始) • [配置选项](#-配置选项) • [使用示例](#-使用示例) • [常见问题](#-常见问题)
--- ## ✨ 特性 - 🔧 **开箱即用** - 自动检测 ASCEND SDK 和毕昇编译器,无需复杂配置 - ⚡ **构建高效** - 支持 ccache 加速,增量编译快如闪电 - 🎯 **灵活配置** - 支持模拟器、性能分析、调试等多种模式 - 📦 **易于集成** - 单文件工具链,复制即用 - 🔄 **持续更新** - 跟进最新 CANN SDK 和毕昇编译器变更 ## 🚀 快速开始 ```bash # 克隆项目 git clone https://gitee.com/sutonghua/xmake-ascend-c.git cd xmake-ascend-c # 构建 xmake # 运行示例 xmake run main ``` ## ⚙️ 配置选项 ### 工具链参数 在 `set_toolchains()` 中配置: ```lua set_toolchains("ascend", { npu_arch = "dav-2201", -- NPU 架构(必需) npu_soc = "Ascend910B2", -- 芯片型号(可选) cxxstd = "17", -- C++ 标准 simulator = false, -- 模拟器模式 msprof = false, -- 性能分析 ascendc = true -- AscendC 支持 }) ``` ### 完整参数表 | 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | `npu_arch` | string | `"dav-2201"` | NPU 架构版本 | | `npu_soc` | string | - | 具体芯片型号,如 `Ascend910B2` | | `cxxstd` | string | `"17"` | C++ 标准版本 | | `simulator` | bool | `false` | 启用模拟器模式 | | `simulator_model` | string | 自动检测 | 模拟器型号 | | `msprof` | bool | `false` | 启用 MSProf 性能分析 | | `msdebug` | bool | `false` | 启用简化调试模式 | | `ascendc` | bool | `true` | 启用 AscendC DevKit | ## 📖 使用示例 ### 基础项目配置 ```lua -- xmake.lua set_project("my-ascend-project") set_version("1.0.0") add_rules("mode.debug", "mode.release") includes("xmake/toolchain_ascend.lua") -- 算子库 target("my_kernel") set_kind("shared") set_toolchains("ascend") add_files("src/kernel.cpp") -- 主程序 target("app") set_kind("binary") set_toolchains("ascend") add_files("src/main.cpp") add_deps("my_kernel") add_links("ascendcl") ``` ### 构建命令 ```bash # Debug 构建 xmake f -m debug && xmake # Release 构建 xmake f -m release && xmake # 清理 xmake clean # 详细输出 xmake -v ``` ## 📁 项目结构 ``` xmake-ascend-c/ ├── 📄 xmake.lua # 主构建脚本 ├── 📂 src/ │ ├── add.cpp # Add 算子实现 │ └── main.cpp # 示例主程序 ├── 📂 xmake/ │ ├── toolchain_ascend.lua # 🔧 Ascend 工具链(核心) │ └── README_XMAKE.md # 工具链详细文档 ├── 📄 LICENSE # MIT 许可证 └── 📄 README.md ``` ## 🔧 在其他项目中使用 只需 **3 步** 即可集成: ```bash # 1. 复制工具链文件 cp xmake/toolchain_ascend.lua your-project/ # 2. 在 xmake.lua 中引入 includes("toolchain_ascend.lua") # 3. 为 target 设置工具链 set_toolchains("ascend") ``` ## ❓ 常见问题
Q: 提示 "ASCEND_HOME_PATH environment variable not set" 请确保已正确设置 `ASCEND_HOME_PATH` 环境变量指向 CANN SDK 安装路径。
Q: 提示 "BiSheng compiler not found in PATH" 请确保毕昇编译器已添加到 `PATH` 环境变量中。
Q: 如何启用模拟器模式? ```lua set_toolchains("ascend", { simulator = true, simulator_model = "Ascend910B1" }) ```
## 🤝 贡献 欢迎提交 Issue 和 Pull Request! ## 📄 许可证 本项目基于 [MIT License](LICENSE) 开源。 ---
**如果这个项目对你有帮助,请给一个 ⭐ Star!** Made with ❤️ for Ascend developers