Scope 方言【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skills1. 概述Scope 方言提供区域作用域抽象用于将操作分组到逻辑作用域中。Scope 操作可携带计算核心类型如 CUBE/VECTOR等属性并支持 inline 和 outline 两种变换策略。方言名称scopeC 命名空间::mlir::scope源码参考ScopeOps.td、Passes.td2. 操作定义2.1 scope.scope功能表示一个区域作用域内部操作作为一个整体执行。可携带属性如tcore_type标记计算核心类型。操作签名操作数/结果类型说明no_inlineUnitAttr标记该作用域不可内联resultsVariadicAnyType作用域返回值$regionSizedRegion1作用域区域TraitsRegionBranchOpInterfaceNoRegionArgumentsSingleBlockImplicitTerminatorscope::ReturnOpSingleBlockRecursiveMemoryEffectsMLIR 示例scope.scope : () - () { scope.return } {tcore_type #hivm.tcore_typeCUBE} scope.scope : () - () { scope.return }带有no_inline属性的作用域不会被inline-scopePass 内联scope.scope : () - () { scope.return } {no_inline}2.2 scope.return功能作为scope.scope区域的终止操作返回作用域的计算结果。操作签名操作数类型说明resultsVariadicAnyType返回值TraitsHasParentScopeOpPureReturnLikeTerminatorMLIR 示例scope.return scope.return %val1, %val2 : f32, i643. 变换 Pass3.1 outline-scope属性值Pass 名称outline-scope作用域ModuleOp构造函数mlir::scope::createOutlineScopePass()依赖方言mlir::func::FuncDialect功能将scope.scope转换为独立的func.func并将作用域属性如tcore_type转移到新函数上。变换示例输入module { func.func test() { scope.scope : () - () { ... scope.return } {tcore_type #hivm.tcore_typeCUBE} scope.scope : () - () { ... scope.return } {tcore_type #hivm.tcore_typeVECTOR} return } }输出module { func.func test_scope_0() attributes {tcore_type #hivm.tcore_typeCUBE} { ... return } func.func test_scope_1() attributes {tcore_type #hivm.tcore_typeVECTOR} { ... return } func.func test() { call test_scope_scope_scope_0() : () - () call test_scope_scope_scope_1() : () - () return } }3.2 inline-scope属性值Pass 名称inline-scope作用域ModuleOp构造函数mlir::scope::createInlineScopePass()选项选项类型默认值说明force-inlineboolfalse强制内联忽略no_inline属性功能将scope.scope区域内的操作提升到父区域除非作用域标记了no_inline属性。变换示例输入func.func test() { scope.scope : () - () { ... scope.return } {no_inline} scope.scope : () - () { inlinable_operations scope.return } return }输出func.func test() { scope.scope : () - () { ... scope.return } {no_inline} inlinable_operations return }4. 典型使用场景计算核心类型标注通过tcore_type属性标记作用域在 CUBE 或 VECTOR 核心上执行VFVector Function划分将计算图划分为多个 Scope每个 Scope 对应一个向量化函数编译流程控制no_inline属性确保某些作用域在编译流程中保持独立【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skills创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考