文件最后提交记录最后更新时间
优化transpose等样例代码及README描述 Co-authored-by: gcw_atM8lhjZ<chenhangxin@huawei.com> # message auto-generated for no-merge-commit merge: !223 merge master into master 优化transpose等样例代码及README描述 Created-by: gcw_atM8lhjZ Commit-by: gcw_atM8lhjZ Merged-by: cann-robot Description: ## 描述 优化transpose等样例代码及README描述 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 样例本地自验证 测试样例: example\00_introduction\01_add\basic_api_memory_allocator_add example\03_libraries\09_transpose 测试结果: test pass! ## 文档更新 更新example\00_introduction、example\03_libraries中的README ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/asc-devkit!2233 个月前
优化transpose等样例代码及README描述 Co-authored-by: gcw_atM8lhjZ<chenhangxin@huawei.com> # message auto-generated for no-merge-commit merge: !223 merge master into master 优化transpose等样例代码及README描述 Created-by: gcw_atM8lhjZ Commit-by: gcw_atM8lhjZ Merged-by: cann-robot Description: ## 描述 优化transpose等样例代码及README描述 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 样例本地自验证 测试样例: example\00_introduction\01_add\basic_api_memory_allocator_add example\03_libraries\09_transpose 测试结果: test pass! ## 文档更新 更新example\00_introduction、example\03_libraries中的README ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/asc-devkit!2233 个月前
updated the readme link Co-authored-by: gcw_atM8lhjZ<chenhangxin@huawei.com> # message auto-generated for no-merge-commit merge: !301 merge master into master updated the readme link Created-by: gcw_atM8lhjZ Commit-by: gcw_atM8lhjZ Merged-by: cann-robot Description: ## 描述 优化example中README的描述,更新链接 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 不涉及 ## 文档更新 examples/00_introduction/00_helloworld/hello_world_aicpu/README.md examples/00_introduction/00_helloworld/hello_world_npu/README.md examples/00_introduction/03_matmulleakyrelu/matmul_leakyrelu/README.md examples/00_introduction/04_simple_operator/add_dynamic/README.md examples/00_introduction/04_simple_operator/broadcast/README.md examples/00_introduction/04_simple_operator/sub/README.md examples/02_features/00_framework_launch/README.md examples/02_features/04_micro_api/move_mask_reg/README.md examples/02_features/04_micro_api/move_successive_align/README.md examples/02_features/04_micro_api/move_successive_unalign/README.md examples/02_features/04_micro_api/move_unsuccessive_align/README.md examples/02_features/04_micro_api/read_write_sync/README.md examples/02_features/04_micro_api/vector_add/README.md examples/02_features/04_micro_api/write_write_sync/README.md examples/02_features/07_data_movement/data_copy_ub2l1/README.md examples/02_features/07_data_movement/data_copy_ub2l1_kfc/README.md examples/02_features/08_tiling/README.md examples/02_features/09_unalign/abs_duplicate/README.md examples/02_features/09_unalign/abs_gather_mask/README.md examples/02_features/09_unalign/reduce_min/README.md examples/02_features/09_unalign/whole_reduce_sum/README.md examples/03_libraries/02_activation/README.md examples/03_libraries/05_reduce/reduce_custom/README.md examples/04_best_practices/01_bank_conflict/01_bank_conflict_950/README.md examples/04_best_practices/01_bank_conflict/bank_conflict/README.md examples/04_best_practices/10_compatibility_cases/data_copy_l1togm_910B/README.md examples/04_best_practices/10_compatibility_cases/data_copy_l1togm_950/README.md examples/04_best_practices/10_compatibility_cases/init_const_value_910B/README.md examples/04_best_practices/10_compatibility_cases/init_const_value_950/README.md examples/04_best_practices/10_compatibility_cases/matmul_s4_910B/README.md examples/04_best_practices/10_compatibility_cases/matmul_s4_950/README.md examples/04_best_practices/10_compatibility_cases/set_loaddata_boundary_910B/README.md examples/04_best_practices/10_compatibility_cases/set_loaddata_boundary_950/README.md examples/04_best_practices/12_high_performance_vf/optimize_vf_continious_align/README.md examples/04_best_practices/12_high_performance_vf/optimize_vf_dual_instr/README.md examples/04_best_practices/12_high_performance_vf/optimize_vf_fusion/README.md examples/04_best_practices/12_high_performance_vf/optimize_vf_loop/README.md examples/04_best_practices/13_optimize_datacopy/optimize_datacopy_loop_mode/README.md examples/04_best_practices/13_optimize_datacopy/optimize_datacopy_nddma/README.md examples/04_best_practices/13_optimize_datacopy/optimize_reduce_invalid_datacopy/README.md ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 其他,请描述: See merge request: cann/asc-devkit!3013 个月前
优化transpose等样例代码及README描述 Co-authored-by: gcw_atM8lhjZ<chenhangxin@huawei.com> # message auto-generated for no-merge-commit merge: !223 merge master into master 优化transpose等样例代码及README描述 Created-by: gcw_atM8lhjZ Commit-by: gcw_atM8lhjZ Merged-by: cann-robot Description: ## 描述 优化transpose等样例代码及README描述 ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 样例本地自验证 测试样例: example\00_introduction\01_add\basic_api_memory_allocator_add example\03_libraries\09_transpose 测试结果: test pass! ## 文档更新 更新example\00_introduction、example\03_libraries中的README ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/asc-devkit!2233 个月前
Replace blockDim with numBlocks Co-authored-by: 王旭<wangxu243@huawei.com> # message auto-generated for no-merge-commit merge: !237 merge master into master Replace blockDim with numBlocks Created-by: wx369 Commit-by: 王旭 Merged-by: cann-robot Description: ## 描述 修正blockDim命名,改为numBlocks ## 关联的Issue 不涉及 ## 测试 通过了样例的编译运行 ## 文档更新 不涉及 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/asc-devkit!2373 个月前
README.md

使用Tiling策略实现VectorAdd算子样例

概述

本样例实现了一个支持多种数据类型的向量加法算子,其核心在于采用精细的多核并行数据切分(Tiling)策略,通过17个参数动态管理任务分配,处理核间负载不均及尾核尾块场景,以实现高效能计算。

支持的产品

  • Atlas A3 训练系列产品/Atlas A3 推理系列产品
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品

目录结构介绍

├── 08_tiling
│   ├── scripts
│   │   ├── gen_data.py          // 输入数据和真值数据生成脚本
│   │   └── verify_result.py     // 验证输出数据和真值数据是否一致的验证脚本
│   ├── CMakeLists.txt           // 编译工程文件
│   ├── data_utils.h             // 数据读入写出函数
│   └── tiling_strategy.asc      // Ascend C算子实现 & 调用样例

算子描述

  • 算子功能:
    Add算子实现了两个数据相加,返回相加结果的功能。对应的数学表达式为:

    z = x + y
    
  • 算子规格:

    算子类型(OpType)Add
    算子输入nameshapedata typeformat
    x(32, 1024) / (8, 1023) / (32, 1023) / (17, 1023) bfloat16_t/int8_t/float/half/int16_t/int32_tND
    y(32, 1024) / (8, 1023) / (32, 1023) / (17, 1023)bfloat16_t/int8_t/float/half/int16_t/int32_tND
    算子输出z(32, 1024) / (8, 1023) / (32, 1023) / (17, 1023)bfloat16_t/int8_t/float/half/int16_t/int32_tND
    核函数名tiling_strategy_custom
  • 算子实现:
    Ascend C提供的矢量计算接口的操作元素都为LocalTensor,输入数据需要先计算出不同核上计算的数据相对首地址的偏移并搬运进片上存储。如果涉及到Add算子不支持的数据类型,则需要申请额外的tmpBufeer,并在计算前使用Cast算子进行类型转换,然后使用计算接口完成两个输入参数相加,得到最终结果,再搬出到外部存储上。

    Add算子的实现流程分为3个基本任务:CopyIn,Compute,CopyOut。CopyIn任务负责将Global Memory上的输入Tensor xGm和yGm搬运到Local Memory,分别存储在xLocal、yLocal,Compute任务负责对xLocal、yLocal执行加法操作,计算结果存储在zLocal中,CopyOut任务负责将输出数据从zLocal搬运至Global Memory上的输出Tensor zGm中。

    • Tiling实现
      TilingData参数设计,TilingData参数本质上是和并行数据切分相关的参数。

      本样例尝试将输入数据均分在给定数目的核上计算,如不能均分,则计算整核和尾核的个数,整核和尾核分别处理不同数据量的数据。定义UB_BLOCK_NUM最为最大可用的UB数据块,对应UB的大小为UB_BLOCK_NUM * 32 Bytes。 并以UB_BLOCK_NUM为粒度进行tiling切分。算子中使用了17个tiling参数:

      • totalLength、dataType为输入数据的总长度和数据类型;
      • blockLength、tileNum、 tileLength、lastTileLength为核均分场景下每个核上的计算量、tiling切分个数以及整块和尾块长度;
      • former(tail)Num、former(tail)Length、former(tail)TileNum、former(tail)TileLength、former(tail)LastTileLength为核不均分的场景下整核和尾核相关的切分数据,与核均分场景下对应;
      • isEvenCore用来判断当前是否为核均分场景。
    • 调用实现
      使用内核调用符<<<>>>调用核函数。

编译运行

在本样例根目录下执行如下步骤,编译并执行算子。

  • 配置环境变量
    请根据当前环境上CANN开发套件包的安装方式,选择对应配置环境变量的命令。

    • 默认路径,root用户安装CANN软件包

      source /usr/local/Ascend/cann/set_env.sh
      
    • 默认路径,非root用户安装CANN软件包

      source $HOME/Ascend/cann/set_env.sh
      
    • 指定路径install_path,安装CANN软件包

      source ${install_path}/cann/set_env.sh
      
  • 样例执行

    mkdir -p build && cd build;   # 创建并进入build目录
    cmake ..;make -j;             # 编译工程
    python3 ../scripts/gen_data.py   # 生成测试输入数据
    ./demo                        # 执行编译生成的可执行程序,执行样例
    python3 ../scripts/verify_result.py output/output.bin output/golden.bin   # 验证输出结果是否正确,确认算法逻辑正确
    

    执行结果如下,说明精度对比成功。

    test pass!