Block Epilogue Empty【免费下载链接】ops-tensorops-tensor 是 CANN Compute Architecture for Neural Networks算子库中提供张量类计算的基础算子库采用模块化设计支持灵活的算子开发和管理。项目地址: https://gitcode.com/cann/ops-tensor代码位置功能说明空后处理组件用于不支持后处理操作的矩阵乘 Kernel。作为BlockEpilogue的默认实现满足 Kernel 模板参数要求但不执行任何实际计算。继承自Block Epilogue 基础框架特殊约束用途限制仅用于不支持后处理的 Kernel作为模板参数占位。Kernel 兼容性仅支持 Basic Kernelusing BlockEpilogue Blaze::Gemm::Block::BlockEpilogueEmpty; using MatmulKernel Blaze::Gemm::Kernel::KernelMatmulBasic ProblemShape, BlockMmad, BlockEpilogue, BlockScheduler;不支持 StreamK KernelStreamK Kernel 需要BlockEpilogueStreamK。无实际计算所有成员函数均为空实现不执行任何操作Run()直接返回operator()直接返回或调用Run()空参数兼容提供多种调用接口以匹配 Kernel 模板要求但参数均无实际用途。特殊数据结构Argumentsstruct Arguments { Arguments() default; };说明空参数结构体无任何成员。Paramsstruct Params { Params() default; };说明空参数结构体无任何成员。特殊成员方法构造函数__aicore__ inline BlockEpilogueEmpty()功能构造 BlockEpilogueEmpty 对象空实现。Run函数__aicore__ inline void Run() { return; // 直接返回不执行任何操作 }功能执行后处理操作空实现。operator函数参数版本__aicore__ inline void operator()(Arguments const params) { Run(); // 调用空的 Run() }功能执行后处理操作参数版本。 说明参数params无实际用途仅满足接口要求。operator函数Block版本__aicore__ inline void operator()( BlockShape const blockShape, BlockCoord const blockCoord, int64_t dstStartOffset 0, int64_t srcStartOffset 0) { return; // 直接返回不执行任何操作 }功能执行后处理操作Block 坐标版本。 说明所有参数均无实际用途仅满足接口要求。调用示例在 Kernel 模板中使用// 定义 BlockEpilogue using BlockEpilogue Blaze::Gemm::Block::BlockEpilogueEmpty; // 组装 Kernel using MatmulKernel Blaze::Gemm::Kernel::KernelMatmulBasic ProblemShape, BlockMmad, BlockEpilogue, BlockScheduler;实例化与调用可选BlockEpilogue epilogue; // 以下调用均无实际效果 epilogue.Run(); epilogue({}); epilogue(blockShape, blockCoord, 0, 0);设计说明为什么需要 BlockEpilogueEmpty模板参数要求KernelMatmulBasic模板需要BlockEpilogue参数接口一致性保持与其他 Epilogue 组件如 StreamK相同的接口扩展性未来可替换为实际的后处理组件如 ReLU、Add 等零开销空实现不会引入额外计算开销性能影响影响项说明编译时间无影响空类编译开销极小运行时间无影响空函数直接返回内存占用无影响无成员变量流水线无影响不参与计算流程与 BlockEpilogueStreamK 的关系BlockEpilogueEmpty ← 当前实现空用于 Basic Kernel ↓ BlockEpilogueStreamK ← 实际实现用于 StreamK Kernel ├── workspace 汇聚K 轴切分累加 ├── 类型转换float → half/bf16 └── ReLU 激活可选扩展建议如需添加后处理功能可参考以下设计模式// 自定义 Epilogue 示例伪代码 class BlockEpilogueRelu { public: struct Arguments { float threshold; // ReLU 参数 }; __aicore__ inline void Init(Arguments const args) { threshold_ args.threshold; } __aicore__ inline void Run() { AscendC::Relu(outputTensor, inputTensor, threshold_); } __aicore__ inline void operator()(Arguments const args) { Init(args); Run(); } private: float threshold_; AscendC::GlobalTensorfloat outputTensor_; AscendC::GlobalTensorfloat inputTensor_; };适用场景Basic Kernel不需要后处理的简单矩阵乘场景无 workspace不需要存储中间结果单核计算仅需 AIC 计算无需 AIV 参与原型开发快速验证 Kernel 框架后续可替换为实际实现【免费下载链接】ops-tensorops-tensor 是 CANN Compute Architecture for Neural Networks算子库中提供张量类计算的基础算子库采用模块化设计支持灵活的算子开发和管理。项目地址: https://gitcode.com/cann/ops-tensor创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考