当前位置: 首页 > news >正文

CANN/pto-isa通信正确性验证方法

正确性验证方法

【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isa

Golden 数据生成

Python Golden 生成脚本模板

#!/usr/bin/python3 import os import numpy as np np.random.seed(42) def gen_reduce_scatter_golden(nranks, M, N, dtype=np.float16): """生成 ReduceScatter 的 golden 数据""" inputs = [] for r in range(nranks): data = np.random.randn(M, N).astype(dtype) data.tofile(f"rank{r}_input.bin") inputs.append(data) summed = np.sum(inputs, axis=0) for r in range(nranks): golden = np.zeros_like(summed) # 按 tiling 策略填充 rank r 应该持有的结果 golden.tofile(f"rank{r}_golden.bin") def gen_allgather_golden(nranks, M, N, dtype=np.float16): """生成 AllGather 的 golden 数据:每个 rank 持有完整的 summed 结果""" inputs = [] for r in range(nranks): data = np.fromfile(f"rank{r}_input.bin", dtype=dtype).reshape(M, N) inputs.append(data) golden = np.sum(inputs, axis=0) for r in range(nranks): golden.tofile(f"rank{r}_allreduce_golden.bin") if __name__ == "__main__": nranks = 8 M, N = 5416, 1408 gen_reduce_scatter_golden(nranks, M, N) gen_allgather_golden(nranks, M, N)

Golden 数据组织

testdata/ ├── rank0_input.bin ├── rank1_input.bin ├── ... ├── rank0_golden.bin ├── rank1_golden.bin ├── ... └── config.json

数据类型映射

Python numpyC++ 类型ACL 类型
np.float16halfaclFloat16
np.float32floatfloat
np.int32int32_tint32_t
np.int16int16_tint16_t

验证函数模板

template <typename T> bool VerifyResult(const T *actual, const T *expected, size_t count, float atol = 1.0f, float rtol = 0.01f) { int error_count = 0; int max_errors = 10; float max_diff = 0.0f; for (size_t i = 0; i < count; ++i) { float a = static_cast<float>(actual[i]); float e = static_cast<float>(expected[i]); float diff = std::abs(a - e); float threshold = atol + rtol * std::abs(e); if (diff > threshold) { if (error_count < max_errors) { printf(" Mismatch at [%zu]: actual=%f, expected=%f, diff=%f, threshold=%f\n", i, a, e, diff, threshold); } error_count++; max_diff = std::max(max_diff, diff); } } if (error_count > 0) { printf(" Total errors: %d / %zu (max_diff=%f)\n", error_count, count, max_diff); } return error_count == 0; }

精度标准

数据类型推荐 atol推荐 rtol说明
float (FP32)1e-51e-4高精度
half (FP16)1.00.01AtomicAdd 累积误差较大
int32 / int1600精确匹配

FP16 AtomicAdd 精度注意

  • 多 rank AtomicAdd 累积会引入浮点误差
  • rank 数越多,累积误差越大
  • 建议 FP16 使用atol=1.0, rtol=0.01或更宽松的阈值

分阶段验证

对于多阶段算子(如 RS + Barrier + AG),建议分阶段验证:

// 阶段 1 验证:RS 完成后,检查 reduced_output RunReduceScatterOnly(...); aclrtSynchronizeStream(stream); bool rs_pass = VerifyReduceScatter(reduced_output, rs_golden); // 阶段 2 验证:完整 AllReduce 后,检查最终结果 RunFullAllReduce(...); aclrtSynchronizeStream(stream); bool ar_pass = VerifyAllReduce(reduced_output, ar_golden);

main.cpp 模板(多 rank 测试)

#include "acl/acl.h" #include "comm_mpi.h" #include "hccl_context.h" #include <cstdio> extern void launchTPutTest(uint8_t *local, uint8_t *remote, void *stream); int main(int argc, char **argv) { MPI_Init(&argc, &argv); int rank, nranks; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &nranks); aclInit(nullptr); aclrtSetDevice(rank); aclrtStream stream; aclrtCreateStream(&stream); HcclRootInfo rootInfo; if (rank == 0) HcclGetRootInfo(&rootInfo); MPI_Bcast(&rootInfo, sizeof(rootInfo), MPI_BYTE, 0, MPI_COMM_WORLD); HcclComm comm; HcclCommInitRootInfo(nranks, &rootInfo, rank, &comm); size_t dataSize = ROWS * COLS * sizeof(half); uint8_t *localBuf, *remoteBuf; // ... 获取通信窗口地址 ... std::vector<half> hostData(ROWS * COLS); for (int i = 0; i < ROWS * COLS; i++) hostData[i] = (half)(rank * 1000 + i); aclrtMemcpy(localBuf, dataSize, hostData.data(), dataSize, ACL_MEMCPY_HOST_TO_DEVICE); MPI_Barrier(MPI_COMM_WORLD); launchTPutTest(localBuf, remoteBuf, stream); aclrtSynchronizeStream(stream); MPI_Barrier(MPI_COMM_WORLD); std::vector<half> result(ROWS * COLS); aclrtMemcpy(result.data(), dataSize, localBuf, dataSize, ACL_MEMCPY_DEVICE_TO_HOST); bool pass = true; for (int i = 0; i < ROWS * COLS; i++) { half expected = /* 根据通信语义计算 */; if (abs((float)result[i] - (float)expected) > 1e-3) { printf("FAIL: rank %d, idx %d, got %f, expected %f\n", rank, i, (float)result[i], (float)expected); pass = false; break; } } printf("Rank %d: %s\n", rank, pass ? "PASS" : "FAIL"); HcclCommDestroy(comm); aclrtDestroyStream(stream); aclrtResetDevice(rank); aclFinalize(); MPI_Finalize(); return pass ? 0 : 1; }

【免费下载链接】pto-isaParallel Tile Operation (PTO) is a virtual instruction set architecture designed by Ascend CANN, focusing on tile-level operations. This repository offers high-performance, cross-platform tile operations across Ascend platforms.项目地址: https://gitcode.com/cann/pto-isa

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

http://www.jsqmd.com/news/787526/

相关文章:

  • 终极指南:如何用TranslucentTB打造个性化透明任务栏
  • Sverklo:为AI编程助手注入代码结构智能,实现精准搜索与安全重构
  • AI气象与海浪预测:从数据驱动原理到LSTM/Transformer模型实践
  • 从认知科学到AI工程:构建可评估的“意识指标”框架
  • 从零构建智能代码解释器:LLM与沙箱的工程实践
  • Breeze Hinted光标主题:解决Linux高分屏光标模糊的Hinting优化方案
  • 2026年评价高的珍珠棉拖盘/珍珠棉袋/天津珍珠棉盒子优质供应商推荐 - 行业平台推荐
  • AI工具高效筛选指南:从Awesome列表到个人知识库构建
  • 一键导出竞价表格,凌风工具箱助力 Temu 高效抢流量
  • Arduino物理开关模拟鼠标点击:从硬件连接到代码实现的完整指南
  • AI+区块链+DAO:构建去中心化社会协作网络应对性勒索危机
  • 隐私优先的本地化个人基因组分析工具:从数据到洞察的完整指南
  • Cursor AI 编码助手规则集配置指南:从代码规范到项目定制
  • 预测锦标赛:解码AGI发展的集体智慧与风险评估
  • PMP管理大数据学习建议
  • 在Node.js服务中集成Taotoken实现多模型智能对话功能
  • 二手房老房装修就找武汉尺子世家装饰工程有限公司(内含2026年最新联系电话及网址) - 速递信息
  • Crawlio Browser Agent:智能浏览器爬虫实战,高效应对动态网页与反爬
  • 2026年四川全省热轧H型钢优质经销商选择指南——全川供货、工程专用、一站式采购 - 四川盛世钢联营销中心
  • ASIC功能验证:基于规范的方法与Specman实战
  • 【汽车芯片功能安全分析与故障注入实践 08】Diagnostic Coverage 是怎么算出来的?
  • RNN在嵌入式非线性模型预测控制中的创新应用
  • 生成式AI艺术审美:从技术原理到人机协作的评判框架
  • 基于SpringBoot+Vue的编程训练系统管理系统设计与实现【Java+MySQL+MyBatis完整源码】
  • CANN/ops-nn 安全声明
  • CogmemAi-MCP:为AI编程助手构建持久化智能记忆系统
  • 嵌入式测试学习第 5 天:电阻分类、色环电阻读数、贴片电阻
  • ARM CoreSight调试架构与寄存器模型详解
  • 离线优先的Markdown编辑器:inkdown如何实现极致专注写作
  • G-Helper华硕笔记本终极控制指南:5分钟掌握性能优化与电池保护技巧