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

CANN/catlass优化矩阵乘法示例

OptimizedMatmul Example Readme

【免费下载链接】catlass本项目是CANN的算子模板库,提供NPU上高性能矩阵乘及其相关融合类算子模板样例。项目地址: https://gitcode.com/cann/catlass

Code Organization

├── 06_optimized_matmul │ ├── CMakeLists.txt # CMake build file │ ├── README.md │ └── optimized_matmul.cpp # Main file

Function

This example demonstrates optimized matrix multiplication. Compared to the00_basic_matmulexample , this implementation replaces the dispatch policy withMmadAtlasA2Preloadand introduces padding preprocessing for the input matrices to improve data transfer performance.

Example

  • After obtaining the code, compile the operator executable file. For details, see Template Library Quick Start.
  • Execute the operator.
# Compile a specified test case. bash scripts/build.sh 06_optimized_matmul cd output/bin # Executable file name | Matrix M-axis | N-axis | K-axis | Device ID # The device ID is optional. The default value is 0. ./06_optimized_matmul 256 512 1024 0

If the following result is displayed, precision verification is successful.

Compare success.

Remarks

In this example, the default padding action usesPADDING_NZ. You can switch this toPADDING_BLOCK_NDto evaluate alternative performance profiles.

  • PADDING_NZThe code configuration is as follows:
constexpr PaddingTag paddingTagA = (std::is_same_v<LayoutA, layout::zN> || std::is_same_v<LayoutA, layout::nZ>) ? PaddingTag::NO_PADDING : PaddingTag::PADDING_NZ; constexpr PaddingTag paddingTagB = (std::is_same_v<LayoutB, layout::zN> || std::is_same_v<LayoutB, layout::nZ>) ? PaddingTag::NO_PADDING : PaddingTag::PADDING_NZ;

TheCOMPUTE_LENGTHallocated in the UB under thePADDING_NZpolicy is 48 KB:

static const uint32_t COMPUTE_LENGTH_A = 48 * 1024 / sizeof(ElementA); static const uint32_t COMPUTE_LENGTH_B = 48 * 1024 / sizeof(ElementB);
  • PADDING_BLOCK_NDThe modifications required to enablePADDING_BLOCK_NDare shown below. When the input matrix is not in NZ format, this policy aligns and pads the matrix according toL1TileShape:
constexpr PaddingTag paddingTagA = (std::is_same_v<LayoutA, layout::zN> || std::is_same_v<LayoutA, layout::nZ>) ? PaddingTag::NO_PADDING - : PaddingTag::PADDING_NZ; + : PaddingTag::PADDING_BLOCK_ND; constexpr PaddingTag paddingTagB = (std::is_same_v<LayoutB, layout::zN> || std::is_same_v<LayoutB, layout::nZ>) ? PaddingTag::NO_PADDING - : PaddingTag::PADDING_NZ; + : PaddingTag::PADDING_BLOCK_ND;

TheCOMPUTE_LENGTHallocated in the UB scales up to 96 KB under thePADDING_BLOCK_NDpolicy:

-static const uint32_t COMPUTE_LENGTH_A = 48 * 1024 / sizeof(ElementA); -static const uint32_t COMPUTE_LENGTH_B = 48 * 1024 / sizeof(ElementB); +static const uint32_t COMPUTE_LENGTH_A = 96 * 1024 / sizeof(ElementA); +static const uint32_t COMPUTE_LENGTH_B = 96 * 1024 / sizeof(ElementB);

【免费下载链接】catlass本项目是CANN的算子模板库,提供NPU上高性能矩阵乘及其相关融合类算子模板样例。项目地址: https://gitcode.com/cann/catlass

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

http://www.gsyq.cn/news/1583120.html

相关文章:

  • JoyAI-Image-Edit-Plus-Diffusers核心功能解析:Diffusers库的增强版图像编辑神器
  • Ngx-restangular 测试策略:单元测试和集成测试完整指南
  • 如何用Gemma-4-26B-A4B-StyleTune提升创作质量?新手必看的AI写作指南 [特殊字符]
  • Bernini-R-GGUF-ComfyUI安装教程:5分钟快速部署AI视频生成环境
  • FreeOpcUa在实际项目中的应用案例:工业自动化系统的集成经验
  • Agora-Flutter-SDK高级功能实战:美颜、虚拟背景与空间音频实现
  • The Lightmapper对比分析:与其他Blender光照贴图插件的优劣比较
  • XRCarouselView源码解析:理解iOS轮播控件的核心实现原理
  • 10个CatSniffer实用技巧:从基础嗅探到高级攻击的完整教程
  • Continuum部署指南:从GitHub Releases到Discoverium的应用分发
  • sniffer源码解析:Go语言实现高性能网络流量捕获的关键技术
  • JoyAI-VL-Interaction-Preview技术架构深度解析:8B规模视觉优先模型的设计哲学
  • Haskell测试框架hspec:为什么它是现代Haskell开发的必备工具?[特殊字符]
  • TensorFlow Data Validation 与Apache Beam集成:大规模数据验证的完整解决方案
  • 提升laravel-money性能:处理大量货币数据的优化技巧
  • Pinia状态管理在vite-vue3-chrome-extension-v3中的终极指南:5个技巧让组件通信不再头疼
  • HalfStyle插件扩展开发指南:构建自定义字符分割插件
  • Easy-PHP:从零构建高性能轻量级PHP框架的完整指南 [特殊字符]
  • 如何快速上手cssplot:从安装到创建第一个柱状图的完整指南
  • CANN/catlass GEMM内核开发详解
  • Javinizer元数据聚合策略:多源数据合并与优先级设置技巧
  • 3大实战技巧:深度掌握TRL模型微调的核心价值
  • 3步搞定OrcaSlicer安装配置:新手快速上手3D打印切片终极指南
  • 开发者必看:Sing-Guard-2b API接口详解与集成示例
  • Super Productivity容器化部署实战:构建企业级时间管理系统的技术架构解析
  • 950基础矩阵乘法TLA示例
  • CANN/runtime:资源限制内核执行示例
  • laravel-money宏与混入功能:如何优雅扩展货币处理能力?
  • Awesome Claude Skills:构建AI工作流的终极指南与完整实践
  • GroupViT模型训练全指南:从环境配置到COCO数据集评估,新手也能轻松掌握