Merged
修文档中废弃接口及原子操作相关错误描述 #6493
GRJ_XIDUOAdd on Sep 29
修文档中废弃接口及原子操作相关错误描述 #6493
Merged
Total: 13 files changed+28-74
| @@ -89,7 +89,6 @@ As a vectorized programming interface in the Ascend C language extension layer, | |||
| 89 | **Core Features** | 89 | **Core Features** |
| 90 | - **Native C Language Paradigm Compatibility**: Supports the standard C language operator development mode, natively supports array-style memory allocation and pointer-based computing primitives; all interfaces uniformly adopt the snake_case naming convention with the `asc_xxx` prefix, featuring clear semantics and high recognizability, which reduces developers' understanding and access costs. | 90 | - **Native C Language Paradigm Compatibility**: Supports the standard C language operator development mode, natively supports array-style memory allocation and pointer-based computing primitives; all interfaces uniformly adopt the snake_case naming convention with the `asc_xxx` prefix, featuring clear semantics and high recognizability, which reduces developers' understanding and access costs. |
| 91 | - **Systematic SIMD Vectorized Interfaces**: Provides a full-scenario matrix of continuous vector computing interfaces to meet the development needs of most conventional operators. Take the basic vector addition interface as an example: `asc_add(__ubuf__ half* dst, __ubuf__ half* src0, __ubuf__ half* src1, uint32_t count)`, with intuitive interface definition and concise calling logic. | 91 | - **Systematic SIMD Vectorized Interfaces**: Provides a full-scenario matrix of continuous vector computing interfaces to meet the development needs of most conventional operators. Take the basic vector addition interface as an example: `asc_add(__ubuf__ half* dst, __ubuf__ half* src0, __ubuf__ half* src1, uint32_t count)`, with intuitive interface definition and concise calling logic. |
| 92 | -- **Hierarchical Synchronization Mechanism Design**: Balances development efficiency and performance controllability by providing layered synchronization capabilities. For rapid development and function verification scenarios, it has a built-in simplified synchronization management mechanism, and is equipped with integrated computing interfaces with the `_sync` suffix (e.g., `asc_add_sync(...)`). Developers can quickly complete function implementation without explicitly managing synchronization timing. | ||
| 93 | - **Advanced Data Layout Control Capability**: For ultimate performance tuning scenarios, it provides advanced computing interfaces with control parameters such as `repeat`/`stride`, supports flexible configuration of data access stride, repeated calculation modes and memory layout strategies, enabling developers to deeply customize computing logic and fully tap the upper limit of hardware computing power. | 92 | - **Advanced Data Layout Control Capability**: For ultimate performance tuning scenarios, it provides advanced computing interfaces with control parameters such as `repeat`/`stride`, supports flexible configuration of data access stride, repeated calculation modes and memory layout strategies, enabling developers to deeply customize computing logic and fully tap the upper limit of hardware computing power. |
| 94 | 93 | ||
| 95 | **Applicable Scenarios** | 94 | **Applicable Scenarios** |
| @@ -97,7 +96,6 @@ As a vectorized programming interface in the Ascend C language extension layer, | |||
| 97 | - Production-grade high-performance operator development scenarios that require in-depth mining of hardware computing power and ultimate performance tuning. | 96 | - Production-grade high-performance operator development scenarios that require in-depth mining of hardware computing power and ultimate performance tuning. |
| 98 | 97 | ||
| 99 | **Reference Examples** | 98 | **Reference Examples** |
| 100 | -- [SIMD Add Operator Example (Synchronized Integrated Computing Interface)](../../examples/02_simd_c_api/00_introduction/01_add/c_api_sync_add/c_api_add.asc) | ||
| 101 | - For more examples, please refer to the [examples directory](../../examples) | 99 | - For more examples, please refer to the [examples directory](../../examples) |
| 102 | 100 | ||
| 103 | --- | 101 | --- |
| @@ -65,7 +65,7 @@ asc_add(dst, src0, src1, count); | |||
| 65 | 65 | ||
| 66 | #### Data Flow Modes | 66 | #### Data Flow Modes |
| 67 | 67 | ||
| 68 | -C API supports three data flow modes: | 68 | +C API supports the following two data flow modes: |
| 69 | 69 | ||
| 70 | Mode 1: First-n elements computation | 70 | Mode 1: First-n elements computation |
| 71 | 71 | ||
| @@ -89,16 +89,6 @@ asc_add(dst, src0, src1, repeat, | |||
| 89 | - Supports multi-dimensional data. | 89 | - Supports multi-dimensional data. |
| 90 | - Flexible control. | 90 | - Flexible control. |
| 91 | 91 | ||
| 92 | -Mode 3: Synchronous computation | ||
| 93 | - | ||
| 94 | -```cpp | ||
| 95 | -asc_add_sync(dst, src0, src1, count); | ||
| 96 | -``` | ||
| 97 | - | ||
| 98 | -- Automatically synchronizes pipeline. | ||
| 99 | -- Ensures data consistency. | ||
| 100 | -- Used for critical paths. | ||
| 101 | - | ||
| 102 | ### Parameter Conventions | 92 | ### Parameter Conventions |
| 103 | 93 | ||
| 104 | #### Common Parameters | 94 | #### Common Parameters |
| @@ -246,12 +236,12 @@ asc-devkit/ | |||
| 246 | Implement vector multiply-add C API: `dst = src * scalar + dst` | 236 | Implement vector multiply-add C API: `dst = src * scalar + dst` |
| 247 | 237 | ||
| 248 | - Supported data types: half, float. | 238 | - Supported data types: half, float. |
| 249 | -- Supports three invocation modes. | 239 | +- Supports continuous and configuration modes. |
| 250 | - Directly maps to hardware instructions. | 240 | - Directly maps to hardware instructions. |
| 251 | 241 | ||
| 252 | ### Interface Design | 242 | ### Interface Design |
| 253 | 243 | ||
| 254 | -Add in `include/c_api/vector_compute/vector_compute.h`: | 244 | +Declare in `include/c_api/vector_compute/compute/vector_fused.h`: |
| 255 | 245 | ||
| 256 | ```cpp | 246 | ```cpp |
| 257 | // ==========asc_axpy(half/float)========== | 247 | // ==========asc_axpy(half/float)========== |
| @@ -266,11 +256,6 @@ __aicore__ inline void asc_axpy(__ubuf__ half* dst, __ubuf__ half* src, half val | |||
| 266 | 256 | ||
| 267 | __aicore__ inline void asc_axpy(__ubuf__ float* dst, __ubuf__ float* src, float value, uint8_t repeat, | 257 | __aicore__ inline void asc_axpy(__ubuf__ float* dst, __ubuf__ float* src, float value, uint8_t repeat, |
| 268 | uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride); | 258 | uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride); |
| 269 | - | ||
| 270 | -// Synchronous mode | ||
| 271 | -__aicore__ inline void asc_axpy_sync(__ubuf__ half* dst, __ubuf__ half* src, half scalar, uint32_t count); | ||
| 272 | - | ||
| 273 | -__aicore__ inline void asc_axpy_sync(__ubuf__ float* dst, __ubuf__ float* src, float scalar, uint32_t count); | ||
| 274 | ``` | 259 | ``` |
| 275 | 260 | ||
| 276 | ### Implementation Code | 261 | ### Implementation Code |
| @@ -17,7 +17,7 @@ Add, Sub, Mul, DataCopy, SetVectorMask, PipeBarrier | |||
| 17 | **C API (`c_api/`):** snake_case, `asc_` prefix | 17 | **C API (`c_api/`):** snake_case, `asc_` prefix |
| 18 | 18 | ||
| 19 | ```text | 19 | ```text |
| 20 | -asc_add, asc_axpy, asc_axpy_sync | 20 | +asc_add, asc_axpy |
| 21 | ``` | 21 | ``` |
| 22 | 22 | ||
| 23 | **High-level API (`adv_api/`):** PascalCase | 23 | **High-level API (`adv_api/`):** PascalCase |
| @@ -26,12 +26,6 @@ asc_add, asc_axpy, asc_axpy_sync | |||
| 26 | Axpy, Exp, LayerNorm, GroupedMatmul | 26 | Axpy, Exp, LayerNorm, GroupedMatmul |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | -Synchronous versions are named by API style (depending on API type and actual need): C API uses the `_sync` suffix (e.g., `asc_add_sync`). Not all APIs have synchronous variants. | ||
| 30 | - | ||
| 31 | -```text | ||
| 32 | -asc_add_sync, WarpReduceAddSync | ||
| 33 | -``` | ||
| 34 | - | ||
| 35 | ### Macro Naming | 29 | ### Macro Naming |
| 36 | 30 | ||
| 37 | All uppercase letters + underscores. | 31 | All uppercase letters + underscores. |
| @@ -14,11 +14,8 @@ | |||
| 14 | | [DisableDmaAtomic](DisableDmaAtomic.md) | 关闭数据搬运随路原子操作功能。 | | 14 | | [DisableDmaAtomic](DisableDmaAtomic.md) | 关闭数据搬运随路原子操作功能。 | |
| 15 | | [SetAtomicMax(ISASI)](SetAtomicMax_ISASI.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最大值写入GM。 | | 15 | | [SetAtomicMax(ISASI)](SetAtomicMax_ISASI.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最大值写入GM。 | |
| 16 | | [SetAtomicMin(ISASI)](SetAtomicMin_ISASI.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最小值写入GM。 | | 16 | | [SetAtomicMin(ISASI)](SetAtomicMin_ISASI.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最小值写入GM。 | |
| 17 | -| [SetStoreAtomicConfig(ISASI)](SetStoreAtomicConfig_ISASI.md) | 设置数据搬运的原子操作配置。 | | ||
| 18 | -| [GetStoreAtomicConfig(ISASI)](GetStoreAtomicConfig_ISASI.md) | 获取数据搬运的原子操作配置。 | | ||
| 19 | 17 | ||
| 20 | -<!-- npu="950" id1 --> | 18 | +Scalar原子操作接口,能够在指定GM地址上进行单点原子计算操作,涉及的接口请参见[表2](#table2)。对比数据搬运随路原子操作接口,Scalar原子操作接口不会影响后续向GM搬运数据的指令。 |
| 21 | -针对Ascend 950PR&950DT系列产品新增Scalar原子操作接口,能够在指定GM地址上进行单点原子计算操作,涉及的接口请参见[表2](#table2)。对比数据搬运随路原子操作接口,Scalar原子操作接口不会影响后续向GM搬运数据的指令。 | ||
| 22 | 19 | ||
| 23 | 如下图2左侧子图所示,不使用AtomicAdd接口时,多个AI Core同时对同一GM地址执行累加操作会相互覆盖,操作不具备原子性,最终结果不可预期。如右侧子图所示,使用AtomicAdd接口后,各AI Core的累加操作串行化执行,确保每次累加操作的原子性,最终结果符合预期。 | 20 | 如下图2左侧子图所示,不使用AtomicAdd接口时,多个AI Core同时对同一GM地址执行累加操作会相互覆盖,操作不具备原子性,最终结果不可预期。如右侧子图所示,使用AtomicAdd接口后,各AI Core的累加操作串行化执行,确保每次累加操作的原子性,最终结果符合预期。 |
| 24 | 21 | ||
| @@ -34,4 +31,5 @@ | |||
| 34 | | [AtomicMax](AtomicMax.md) | 该接口用于在指定GM地址上进行原子取最大值操作,将`address`指向的GM地址上的旧值(`old_value`)与输入的标量值(`value`)进行比较,将较大值(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | | 31 | | [AtomicMax](AtomicMax.md) | 该接口用于在指定GM地址上进行原子取最大值操作,将`address`指向的GM地址上的旧值(`old_value`)与输入的标量值(`value`)进行比较,将较大值(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | |
| 35 | | [AtomicCas](AtomicCas.md) | 在指定GM地址上进行原子比较操作,读取`address`指向的GM地址上的旧值(`old_value`)与输入标量值`value1`进行比较:如果相等,则将输入标量值`value2`写入GM地址;如果不相等,则GM地址上的值保持不变。返回该地址修改前的值(`old_value`)。 | | 32 | | [AtomicCas](AtomicCas.md) | 在指定GM地址上进行原子比较操作,读取`address`指向的GM地址上的旧值(`old_value`)与输入标量值`value1`进行比较:如果相等,则将输入标量值`value2`写入GM地址;如果不相等,则GM地址上的值保持不变。返回该地址修改前的值(`old_value`)。 | |
| 36 | | [AtomicExch](AtomicExch.md) | 用于在GM内存中执行原子交换操作,读取`address`指向的GM地址上的旧值(`old_value`),并将输入的标量值(`value`)替换旧值存储回同一地址,返回该地址修改前的值(`old_value`)。 | | 33 | | [AtomicExch](AtomicExch.md) | 用于在GM内存中执行原子交换操作,读取`address`指向的GM地址上的旧值(`old_value`),并将输入的标量值(`value`)替换旧值存储回同一地址,返回该地址修改前的值(`old_value`)。 | |
| 37 | -<!-- end id1 --> | 34 | +| [SetStoreAtomicConfig(ISASI)](SetStoreAtomicConfig_ISASI.md) | 设置标量原子操作配置:操作类型(仅支持求和操作)和数据类型。 | |
| 35 | +| [GetStoreAtomicConfig(ISASI)](GetStoreAtomicConfig_ISASI.md) | 获取SetStoreAtomicConfig设置的标量原子操作配置。 | | ||
| @@ -13,11 +13,13 @@ | |||
| 13 | | [asc_set_atomic_max](datamove_atomic/asc_set_atomic_max.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最大值写入GM。 | | 13 | | [asc_set_atomic_max](datamove_atomic/asc_set_atomic_max.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最大值写入GM。 | |
| 14 | | [asc_set_atomic_min](datamove_atomic/asc_set_atomic_min.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最小值写入GM。 | | 14 | | [asc_set_atomic_min](datamove_atomic/asc_set_atomic_min.md) | 设置后续搬运到GM的数据是否执行原子比较:将待拷贝的内容和GM已有内容进行比较,然后将最小值写入GM。 | |
| 15 | | [asc_disable_dma_atomic](datamove_atomic/asc_disable_dma_atomic.md) | 关闭数据搬运随路原子操作功能。 | | 15 | | [asc_disable_dma_atomic](datamove_atomic/asc_disable_dma_atomic.md) | 关闭数据搬运随路原子操作功能。 | |
| 16 | -| [asc_set_store_atomic_config_v1](scalar_atomic/asc_set_store_atomic_config_v1.md) | 设置数据搬运的原子操作配置。 | | ||
| 17 | -| [asc_get_store_atomic_config](scalar_atomic/asc_get_store_atomic_config.md) | 获取数据搬运的原子操作配置。 | | ||
| 18 | 16 | ||
| 19 | -<!-- npu="950" id1 --> | 17 | +Scalar原子操作接口,能够在指定GM地址上进行单点原子计算操作,涉及的接口请参见[表2](#table2)。 |
| 20 | -针对Ascend 950PR&950DT系列产品,新增Scalar原子操作接口,能够在指定GM地址上进行单点原子计算操作,涉及的接口请参见[表2](#table2)。对比数据搬运随路原子操作接口,Scalar原子操作接口不会影响后续向GM搬运数据的指令。 | 18 | + |
| 19 | +标量原子操作与数据搬运随路原子操作相比,两者的差异如下: | ||
| 20 | + | ||
| 21 | +- 数据搬运随路原子操作的对象是搬运的Tensor,需要先调用数据搬运随路原子操作接口开启原子操作,开启后对后续通过MTE单元搬运到GM的整个Tensor生效,会影响后续搬运指令的行为。 | ||
| 22 | +- 标量原子操作的对象是传入的GM地址上的单个元素,无需开启配置,仅对本次调用传入的GM地址上的单个元素生效,不会影响后续搬运指令。 | ||
| 21 | 23 | ||
| 22 | 如下图2左侧子图所示,不使用`asc_atomic_add`接口时,多个AI Core同时对同一GM地址执行累加操作会相互覆盖,操作不具备原子性,最终结果不可预期。如右侧子图所示,使用`asc_atomic_add`接口后,各AI Core的累加操作串行化执行,确保每次累加操作的原子性,最终结果符合预期。 | 24 | 如下图2左侧子图所示,不使用`asc_atomic_add`接口时,多个AI Core同时对同一GM地址执行累加操作会相互覆盖,操作不具备原子性,最终结果不可预期。如右侧子图所示,使用`asc_atomic_add`接口后,各AI Core的累加操作串行化执行,确保每次累加操作的原子性,最终结果符合预期。 |
| 23 | 25 | ||
| @@ -39,5 +41,5 @@ | |||
| 39 | | [asc_atomic_or](scalar_atomic/asc_atomic_or.md) | 对GM中的数据与指定数据执行原子或操作,即将val按位或到address指向的数据元素上。读取address指向的GM地址上的旧值(`old_value`),将旧值与输入标量值val进行按位或运算,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | | 41 | | [asc_atomic_or](scalar_atomic/asc_atomic_or.md) | 对GM中的数据与指定数据执行原子或操作,即将val按位或到address指向的数据元素上。读取address指向的GM地址上的旧值(`old_value`),将旧值与输入标量值val进行按位或运算,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | |
| 40 | | [asc_atomic_sub](scalar_atomic/asc_atomic_sub.md) | 对GM中的数据与指定数据执行原子减操作,即将val从address指向的数据元素上减去。读取address指向的GM地址上的旧值(`old_value`),将旧值减去输入标量值val,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | | 42 | | [asc_atomic_sub](scalar_atomic/asc_atomic_sub.md) | 对GM中的数据与指定数据执行原子减操作,即将val从address指向的数据元素上减去。读取address指向的GM地址上的旧值(`old_value`),将旧值减去输入标量值val,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | |
| 41 | | [asc_atomic_xor](scalar_atomic/asc_atomic_xor.md) | 对GM中的数据与指定数据执行原子异或操作,即将val按位异或到address指向的数据元素上。读取address指向的GM地址上的旧值(`old_value`),将旧值与输入标量值val进行按位异或运算,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | | 43 | | [asc_atomic_xor](scalar_atomic/asc_atomic_xor.md) | 对GM中的数据与指定数据执行原子异或操作,即将val按位异或到address指向的数据元素上。读取address指向的GM地址上的旧值(`old_value`),将旧值与输入标量值val进行按位异或运算,将结果(`new_value`)写回GM地址,返回该地址修改前的值(`old_value`)。 | |
| 42 | - | 44 | +| [asc_set_store_atomic_config_v1](scalar_atomic/asc_set_store_atomic_config_v1.md) | 设置标量原子操作配置:操作类型(仅支持求和操作)和数据类型。 | |
| 43 | -<!-- end id1 --> | 45 | +| [asc_get_store_atomic_config](scalar_atomic/asc_get_store_atomic_config.md) | 获取asc_set_store_atomic_config_v1设置的标量原子操作配置。 | |
| @@ -95,7 +95,6 @@ graph TD | |||
| 95 | 95 | ||
| 96 | - **原生C语言范式兼容**:支持标准C语言算子开发模式,原生支持数组式内存分配与指针式计算原语;全量接口统一采用`asc_xxx`前缀的snake_case命名规范,语义明确、辨识度高,降低开发者理解与接入成本。 | 96 | - **原生C语言范式兼容**:支持标准C语言算子开发模式,原生支持数组式内存分配与指针式计算原语;全量接口统一采用`asc_xxx`前缀的snake_case命名规范,语义明确、辨识度高,降低开发者理解与接入成本。 |
| 97 | - **体系化SIMD向量化接口**:提供覆盖全场景的连续矢量计算接口矩阵,满足绝大多数常规算子的开发需求。以基础矢量加法接口为例:`asc_add(__ubuf__ half* dst, __ubuf__ half* src0, __ubuf__ half* src1, uint32_t count)`,接口定义直观,调用逻辑简洁。 | 97 | - **体系化SIMD向量化接口**:提供覆盖全场景的连续矢量计算接口矩阵,满足绝大多数常规算子的开发需求。以基础矢量加法接口为例:`asc_add(__ubuf__ half* dst, __ubuf__ half* src0, __ubuf__ half* src1, uint32_t count)`,接口定义直观,调用逻辑简洁。 |
| 98 | -- **分级同步机制设计**:兼顾开发效率与性能可控性,提供分层同步能力。面向快速开发与功能验证场景,内置简化同步管理机制,配套提供`_sync`后缀的一体化计算接口(如`asc_add_sync(...)`),开发者无需显式管控同步时序,即可快速完成功能落地。 | ||
| 99 | - **高级数据排布管控能力**:面向极致性能调优场景,提供携带`repeat`/`stride`等控制参数的高级计算接口,支持灵活配置数据访问步长、重复计算模式与内存排布策略,支撑开发者深度定制计算逻辑,充分挖掘硬件算力上限。 | 98 | - **高级数据排布管控能力**:面向极致性能调优场景,提供携带`repeat`/`stride`等控制参数的高级计算接口,支持灵活配置数据访问步长、重复计算模式与内存排布策略,支撑开发者深度定制计算逻辑,充分挖掘硬件算力上限。 |
| 100 | 99 | ||
| 101 | **适用场景** | 100 | **适用场景** |
| @@ -105,7 +104,6 @@ graph TD | |||
| 105 | 104 | ||
| 106 | **参考示例** | 105 | **参考示例** |
| 107 | 106 | ||
| 108 | -- [SIMD Add算子示例(同步一体化计算接口)](../../examples/02_simd_c_api/00_introduction/01_add/c_api_sync_add/c_api_add.asc) | ||
| 109 | - 更多示例详见[examples目录](../../examples) | 107 | - 更多示例详见[examples目录](../../examples) |
| 110 | 108 | ||
| 111 | ### Tensor API:带Layout语义的C++底层编程接口(全自主资源管控) | 109 | ### Tensor API:带Layout语义的C++底层编程接口(全自主资源管控) |
| @@ -65,7 +65,7 @@ asc_add(dst, src0, src1, count); | |||
| 65 | 65 | ||
| 66 | #### 数据流模式 | 66 | #### 数据流模式 |
| 67 | 67 | ||
| 68 | -C API支持三种数据流模式: | 68 | +C API支持以下两种数据流模式: |
| 69 | 69 | ||
| 70 | 模式1:前n个数据计算 | 70 | 模式1:前n个数据计算 |
| 71 | 71 | ||
| @@ -89,16 +89,6 @@ asc_add(dst, src0, src1, repeat, | |||
| 89 | - 支持多维数据 | 89 | - 支持多维数据 |
| 90 | - 灵活控制 | 90 | - 灵活控制 |
| 91 | 91 | ||
| 92 | -模式3:同步计算 | ||
| 93 | - | ||
| 94 | -```cpp | ||
| 95 | -asc_add_sync(dst, src0, src1, count); | ||
| 96 | -``` | ||
| 97 | - | ||
| 98 | -- 自动同步流水线 | ||
| 99 | -- 保证数据一致性 | ||
| 100 | -- 用于关键路径 | ||
| 101 | - | ||
| 102 | ### 参数约定 | 92 | ### 参数约定 |
| 103 | 93 | ||
| 104 | #### 通用参数 | 94 | #### 通用参数 |
| @@ -246,12 +236,12 @@ asc-devkit/ | |||
| 246 | 实现矢量乘加C API:`dst = src * scalar + dst` | 236 | 实现矢量乘加C API:`dst = src * scalar + dst` |
| 247 | 237 | ||
| 248 | - 支持数据类型:half, float | 238 | - 支持数据类型:half, float |
| 249 | -- 支持三种调用模式 | 239 | +- 支持连续模式和配置模式 |
| 250 | - 直接映射硬件指令 | 240 | - 直接映射硬件指令 |
| 251 | 241 | ||
| 252 | ### 接口设计 | 242 | ### 接口设计 |
| 253 | 243 | ||
| 254 | -在 `include/c_api/vector_compute/vector_compute.h` 中添加: | 244 | +在 `include/c_api/vector_compute/compute/vector_fused.h` 中声明: |
| 255 | 245 | ||
| 256 | ```cpp | 246 | ```cpp |
| 257 | // ==========asc_axpy(half/float)========== | 247 | // ==========asc_axpy(half/float)========== |
| @@ -266,11 +256,6 @@ __aicore__ inline void asc_axpy(__ubuf__ half* dst, __ubuf__ half* src, half val | |||
| 266 | 256 | ||
| 267 | __aicore__ inline void asc_axpy(__ubuf__ float* dst, __ubuf__ float* src, float value, uint8_t repeat, | 257 | __aicore__ inline void asc_axpy(__ubuf__ float* dst, __ubuf__ float* src, float value, uint8_t repeat, |
| 268 | uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride); | 258 | uint16_t dst_block_stride, uint16_t src_block_stride, uint16_t dst_repeat_stride, uint16_t src_repeat_stride); |
| 269 | - | ||
| 270 | -// 同步模式 | ||
| 271 | -__aicore__ inline void asc_axpy_sync(__ubuf__ half* dst, __ubuf__ half* src, half scalar, uint32_t count); | ||
| 272 | - | ||
| 273 | -__aicore__ inline void asc_axpy_sync(__ubuf__ float* dst, __ubuf__ float* src, float scalar, uint32_t count); | ||
| 274 | ``` | 259 | ``` |
| 275 | 260 | ||
| 276 | ### 实现代码 | 261 | ### 实现代码 |
| @@ -17,7 +17,7 @@ Add, Sub, Mul, DataCopy, SetVectorMask, PipeBarrier | |||
| 17 | **C API(`c_api/`):** snake_case,`asc_` 前缀 | 17 | **C API(`c_api/`):** snake_case,`asc_` 前缀 |
| 18 | 18 | ||
| 19 | ```text | 19 | ```text |
| 20 | -asc_add, asc_axpy, asc_axpy_sync | 20 | +asc_add, asc_axpy |
| 21 | ``` | 21 | ``` |
| 22 | 22 | ||
| 23 | **高阶API(`adv_api/`):** 大驼峰(PascalCase) | 23 | **高阶API(`adv_api/`):** 大驼峰(PascalCase) |
| @@ -26,12 +26,6 @@ asc_add, asc_axpy, asc_axpy_sync | |||
| 26 | Axpy, Exp, LayerNorm, GroupedMatmul | 26 | Axpy, Exp, LayerNorm, GroupedMatmul |
| 27 | ``` | 27 | ``` |
| 28 | 28 | ||
| 29 | -同步版本按API风格命名(视API类型和实际需求而定):C API使用 `_sync` 后缀(如 `asc_add_sync`)。并非所有API都有同步变体。 | ||
| 30 | - | ||
| 31 | -```text | ||
| 32 | -asc_add_sync, WarpReduceAddSync | ||
| 33 | -``` | ||
| 34 | - | ||
| 35 | ### 宏命名 | 29 | ### 宏命名 |
| 36 | 30 | ||
| 37 | 全大写字母+下划线。 | 31 | 全大写字母+下划线。 |
| @@ -522,7 +522,7 @@ Reg矢量计算接口直接操作矢量数据寄存器或掩码寄存器,通 | |||
| 522 | vector_float src0_reg; | 522 | vector_float src0_reg; |
| 523 | vector_float src1_reg; | 523 | vector_float src1_reg; |
| 524 | vector_float dst_reg; | 524 | vector_float dst_reg; |
| 525 | -vector_bool mask = asc_create_mask_b32(MASK_PATTERN_ALL); | 525 | +vector_bool mask = asc_create_mask_b32(PAT_ALL); |
| 526 | 526 | ||
| 527 | // 矢量加法 | 527 | // 矢量加法 |
| 528 | asc_add(dst_reg, src0_reg, src1_reg, mask); | 528 | asc_add(dst_reg, src0_reg, src1_reg, mask); |
| @@ -543,10 +543,10 @@ asc_div(dst_reg, src0_reg, src1_reg, mask); | |||
| 543 | float scalar_value = 2.0f; | 543 | float scalar_value = 2.0f; |
| 544 | 544 | ||
| 545 | // 矢量加标量 | 545 | // 矢量加标量 |
| 546 | -asc_adds(dst_reg, src_reg, scalar_value, mask); | 546 | +asc_add_scalar(dst_reg, src0_reg, scalar_value, mask); |
| 547 | 547 | ||
| 548 | // 矢量乘标量 | 548 | // 矢量乘标量 |
| 549 | -asc_muls(dst_reg, src_reg, scalar_value, mask); | 549 | +asc_mul_scalar(dst_reg, src0_reg, scalar_value, mask); |
| 550 | ``` | 550 | ``` |
| 551 | 551 | ||
| 552 | #### 掩码寄存器计算 | 552 | #### 掩码寄存器计算 |
| @@ -11,4 +11,4 @@ | |||
| 11 | |--------------------------------------| ------------------------------------------------- | --- | | 11 | |--------------------------------------| ------------------------------------------------- | --- | |
| 12 | | [data_movement_with_atomic_operations](./data_movement_with_atomic_operations) | 本样例基于SetAtomicAdd和SetAtomicMax原子操作接口,介绍数据从VECOUT向GM搬运时,原子累加和原子最大值比较的实现流程,支持多核读取相同或不同输入的场景。 | Ascend 950PR/Ascend 950DT<br>Atlas A3 训练系列产品/Atlas A3 推理系列产品<br>Atlas A2 训练系列产品/Atlas A2 推理系列产品 | | 12 | | [data_movement_with_atomic_operations](./data_movement_with_atomic_operations) | 本样例基于SetAtomicAdd和SetAtomicMax原子操作接口,介绍数据从VECOUT向GM搬运时,原子累加和原子最大值比较的实现流程,支持多核读取相同或不同输入的场景。 | Ascend 950PR/Ascend 950DT<br>Atlas A3 训练系列产品/Atlas A3 推理系列产品<br>Atlas A2 训练系列产品/Atlas A2 推理系列产品 | |
| 13 | | [scalar_atomic_operations](./scalar_atomic_operations) | 本样例基于AtomicAdd和AtomicCas接口,介绍在GM地址上进行标量原子加和原子比较交换的实现流程,支持多核并行更新单个内存地址。 | Ascend 950PR/Ascend 950DT | | 13 | | [scalar_atomic_operations](./scalar_atomic_operations) | 本样例基于AtomicAdd和AtomicCas接口,介绍在GM地址上进行标量原子加和原子比较交换的实现流程,支持多核并行更新单个内存地址。 | Ascend 950PR/Ascend 950DT | |
| 14 | -| [set_atomic_deterministic_computation](./set_atomic_deterministic_computation) | 本样例首先介绍在数据搬运随路原子操作的场景下做确定性计算的必要性和具体实现方案,随后分别介绍在单个AIV核、多AIV核和多AIC核场景下如何运用上述方案。 | Atlas A3 训练系列产品/Atlas A3 推理系列产品<br>Atlas A2 训练系列产品/Atlas A2 推理系列产品 | | 14 | +| [set_atomic_deterministic_computation](./set_atomic_deterministic_computation) | 本样例首先介绍在数据搬运随路原子操作的场景下做确定性计算的必要性和具体实现方案,随后分别介绍在单个AIV核、多AIV核和多AIC核场景下如何运用上述方案。 | Ascend 950PR/Ascend 950DT<br>Atlas A3 训练系列产品/Atlas A3 推理系列产品<br>Atlas A2 训练系列产品/Atlas A2 推理系列产品 | |
| @@ -10,4 +10,4 @@ This directory contains API samples related to atomic operations. The samples ar | |||
| 10 | |--------------------------------------| ------------------------------------------------- | --- | | 10 | |--------------------------------------| ------------------------------------------------- | --- | |
| 11 | | [data_movement_with_atomic_operations](./data_movement_with_atomic_operations) | This sample demonstrates the implementation flow of atomic accumulation and atomic maximum comparison when moving data from VECOUT to GM, based on the SetAtomicAdd and SetAtomicMax atomic operation interfaces. It supports scenarios where multiple cores read the same or different inputs. | Ascend 950PR/Ascend 950DT<br>Atlas A3 Training Series Products/Atlas A3 Inference Series Products<br>Atlas A2 Training Series Products/Atlas A2 Inference Series Products | | 11 | | [data_movement_with_atomic_operations](./data_movement_with_atomic_operations) | This sample demonstrates the implementation flow of atomic accumulation and atomic maximum comparison when moving data from VECOUT to GM, based on the SetAtomicAdd and SetAtomicMax atomic operation interfaces. It supports scenarios where multiple cores read the same or different inputs. | Ascend 950PR/Ascend 950DT<br>Atlas A3 Training Series Products/Atlas A3 Inference Series Products<br>Atlas A2 Training Series Products/Atlas A2 Inference Series Products | |
| 12 | | [scalar_atomic_operations](./scalar_atomic_operations) | This sample demonstrates the implementation flow of scalar atomic addition and atomic compare-and-swap on GM addresses, based on the AtomicAdd and AtomicCas interfaces. It supports parallel updates of a single memory address by multiple cores. | Ascend 950PR/Ascend 950DT | | 12 | | [scalar_atomic_operations](./scalar_atomic_operations) | This sample demonstrates the implementation flow of scalar atomic addition and atomic compare-and-swap on GM addresses, based on the AtomicAdd and AtomicCas interfaces. It supports parallel updates of a single memory address by multiple cores. | Ascend 950PR/Ascend 950DT | |
| 13 | -| [set_atomic_deterministic_computation](./set_atomic_deterministic_computation) | This sample first introduces the necessity and specific implementation approach for deterministic computation in scenarios involving data movement with accompanying atomic operations. It then describes how to apply this approach in single-AIV core, multi-AIV core, and multi-AIC core scenarios. | Atlas A3 Training Series Products/Atlas A3 Inference Series Products<br>Atlas A2 Training Series Products/Atlas A2 Inference Series Products | | 13 | +| [set_atomic_deterministic_computation](./set_atomic_deterministic_computation) | This sample first introduces the necessity and specific implementation approach for deterministic computation in scenarios involving data movement with accompanying atomic operations. It then describes how to apply this approach in single-AIV core, multi-AIV core, and multi-AIC core scenarios. | Ascend 950PR/Ascend 950DT<br>Atlas A3 Training Series Products/Atlas A3 Inference Series Products<br>Atlas A2 Training Series Products/Atlas A2 Inference Series Products | |
| @@ -78,8 +78,8 @@ | |||
| 78 | 78 | ||
| 79 | - 输入:A [128, 128] half类型,ND格式;B [128, 256] half类型,ND格式;量化参数 [256] uint64_t类型 | 79 | - 输入:A [128, 128] half类型,ND格式;B [128, 256] half类型,ND格式;量化参数 [256] uint64_t类型 |
| 80 | - 输出:C [128, 256] int8_t类型,ND格式 | 80 | - 输出:C [128, 256] int8_t类型,ND格式 |
| 81 | -- 实现:使用`asc_set_gm2l1_nz_para`配置ND2NZ参数,再使用`asc_copy_gm2l1_nd2nz`将输入数据从GM搬运到L1,执行矩阵乘计算;使用`asc_copy_gm2l1`和`asc_copy_l12fb`将量化参数从GM经L1搬运到Fixpipe Buffer;调用`asc_set_l0c2gm_config`配置参数地址,并通过`asc_copy_l0c2gm`的`VQF322B8_PRE`模式进行Vector量化输出 | 81 | +- 实现:使用`asc_set_gm2l1_nz_para`配置ND2NZ参数,再使用`asc_copy_gm2l1_nd2nz`将输入数据从GM搬运到L1,执行矩阵乘计算;使用`asc_copy_gm2l1`和`asc_copy_l12fb`将量化参数从GM经L1搬运到Fixpipe Buffer;调用`asc_set_l0c_copy_config`配置参数地址,并通过`asc_copy_l0c2gm`的`VQF322B8_PRE`模式进行Vector量化输出 |
| 82 | -- 说明:矩阵乘计算结果为float类型,随后通过Vector量化转换为int8_t类型;C矩阵的每一列使用一个量化参数。`asc_set_l0c2gm_config`通过`quant_pre`配置Fixpipe矢量量化参数地址,该参数以128B为地址单位,因此量化参数文件需按128B向上对齐,不足部分补0。本样例的`[256] uint64_t`参数共2048B,已满足该要求。量化参数从L1搬运至Fixpipe Buffer时,需要搬运2048B数据,数据搬运单位为64B,对应`asc_copy_l12fb`的`len_burst`配置为32。 | 82 | +- 说明:矩阵乘计算结果为float类型,随后通过Vector量化转换为int8_t类型;C矩阵的每一列使用一个量化参数。`asc_set_l0c_copy_config`通过`quant_pre_addr`配置Fixpipe矢量量化参数地址,该参数以128B为地址单位,因此量化参数文件需按128B向上对齐,不足部分补0。本样例的`[256] uint64_t`参数共2048B,已满足该要求。量化参数从L1搬运至Fixpipe Buffer时,需要搬运2048B数据,数据搬运单位为64B,对应`asc_copy_l12fb`的`len_burst`配置为32。 |
| 83 | 83 | ||
| 84 | ## 编译运行 | 84 | ## 编译运行 |
| 85 | 85 | ||
| @@ -78,8 +78,8 @@ All device-side movement and compute use asynchronous Ascend C C API calls. `asc | |||
| 78 | 78 | ||
| 79 | - Input: A [128, 128] in `half` ND format; B [128, 256] in `half` ND format; quantization parameters [256] in `uint64_t` | 79 | - Input: A [128, 128] in `half` ND format; B [128, 256] in `half` ND format; quantization parameters [256] in `uint64_t` |
| 80 | - Output: C [128, 256] in `int8_t` ND format | 80 | - Output: C [128, 256] in `int8_t` ND format |
| 81 | -- Implementation: Configure ND2NZ parameters with `asc_set_gm2l1_nz_para`, then use `asc_copy_gm2l1_nd2nz` to move input data from GM to L1 and perform matrix multiplications; use `asc_copy_gm2l1` and `asc_copy_l12fb` to move quantization parameters from GM through L1 to Fixpipe Buffer; configure their address with `asc_set_l0c2gm_config`, then use `asc_copy_l0c2gm` with `VQF322B8_PRE` for vector-quantized output | 81 | +- Implementation: Configure ND2NZ parameters with `asc_set_gm2l1_nz_para`, then use `asc_copy_gm2l1_nd2nz` to move input data from GM to L1 and perform matrix multiplications; use `asc_copy_gm2l1` and `asc_copy_l12fb` to move quantization parameters from GM through L1 to Fixpipe Buffer; configure their address with `asc_set_l0c_copy_config`, then use `asc_copy_l0c2gm` with `VQF322B8_PRE` for vector-quantized output |
| 82 | -- Description: The `float` matrix multiplication result is vector-quantized to `int8_t`; each C matrix column uses one quantization parameter. `asc_set_l0c2gm_config` configures the Fixpipe vector-quantization parameter address through `quant_pre`, which uses 128B address units. The parameter file must therefore be rounded up to 128B, with any padding zero-filled. In this example, the `[256] uint64_t` parameters occupy 2048B and already meet this requirement. Moving these parameters from L1 to Fixpipe Buffer transfers 2048B of data in 64B data blocks, so `len_burst` in `asc_copy_l12fb` is set to 32. | 82 | +- Description: The `float` matrix multiplication result is vector-quantized to `int8_t`; each C matrix column uses one quantization parameter. `asc_set_l0c_copy_config` configures the Fixpipe vector-quantization parameter address through `quant_pre_addr`, which uses 128B address units. The parameter file must therefore be rounded up to 128B, with any padding zero-filled. In this example, the `[256] uint64_t` parameters occupy 2048B and already meet this requirement. Moving these parameters from L1 to Fixpipe Buffer transfers 2048B of data in 64B data blocks, so `len_burst` in `asc_copy_l12fb` is set to 32. |
| 83 | 83 | ||
| 84 | ## Build and Run | 84 | ## Build and Run |
| 85 | 85 | ||