news 2026/7/11 17:26:30

CANN技能库Scope方言文档

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
CANN技能库Scope方言文档

Scope 方言

【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体,本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skills

1. 概述

Scope 方言提供区域作用域抽象,用于将操作分组到逻辑作用域中。Scope 操作可携带计算核心类型(如 CUBE/VECTOR)等属性,并支持 inline 和 outline 两种变换策略。

  • 方言名称scope
  • C++ 命名空间::mlir::scope

源码参考:ScopeOps.td、Passes.td

2. 操作定义

2.1 scope.scope

功能

表示一个区域作用域,内部操作作为一个整体执行。可携带属性(如tcore_type)标记计算核心类型。

操作签名
操作数/结果类型说明
no_inlineUnitAttr标记该作用域不可内联
resultsVariadic<AnyType>作用域返回值
$regionSizedRegion<1>作用域区域
Traits
  • RegionBranchOpInterface
  • NoRegionArguments
  • SingleBlockImplicitTerminator<"scope::ReturnOp">
  • SingleBlock
  • RecursiveMemoryEffects
MLIR 示例
scope.scope : () -> () { scope.return } {tcore_type = #hivm.tcore_type<CUBE>} scope.scope : () -> () { scope.return }

带有no_inline属性的作用域不会被inline-scopePass 内联:

scope.scope : () -> () { scope.return } {no_inline}

2.2 scope.return

功能

作为scope.scope区域的终止操作,返回作用域的计算结果。

操作签名
操作数类型说明
resultsVariadic<AnyType>返回值
Traits
  • HasParent<"ScopeOp">
  • Pure
  • ReturnLike
  • Terminator
MLIR 示例
scope.return scope.return %val1, %val2 : f32, i64

3. 变换 Pass

3.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_type<CUBE>} scope.scope : () -> () { ... scope.return } {tcore_type = #hivm.tcore_type<VECTOR>} return } }

输出:

module { func.func @test_scope_0() attributes {tcore_type = #hivm.tcore_type<CUBE>} { ... return } func.func @test_scope_1() attributes {tcore_type = #hivm.tcore_type<VECTOR>} { ... 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 核心上执行
  • VF(Vector Function)划分:将计算图划分为多个 Scope,每个 Scope 对应一个向量化函数
  • 编译流程控制no_inline属性确保某些作用域在编译流程中保持独立

【免费下载链接】cannbot-skillsCANNBot 是面向 CANN 开发的用于提升开发效率的系列智能体,本仓库为其提供可复用的 Skills 模块。项目地址: https://gitcode.com/cann/cannbot-skills

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

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/11 17:24:25

GEO优化:推荐量暴涨,咨询量归零,什么原因导致的?

你是否也遇到过这样的情况&#xff1a;在AI大模型中的品牌推荐量大幅攀升&#xff0c;但实际咨询量却纹丝不动&#xff0c;甚至归零&#xff1f;在生成式引擎优化&#xff08;GEO&#xff09;已成为企业获取流量的关键战场的当下&#xff0c;这种“叫好不叫座”的怪象正困扰着无…

作者头像 李华
网站建设 2026/7/11 17:22:00

I2L-MeshNet性能优化技巧:如何将MPJPE误差降低到55.83mm

I2L-MeshNet性能优化技巧&#xff1a;如何将MPJPE误差降低到55.83mm 【免费下载链接】I2L-MeshNet_RELEASE Official PyTorch implementation of "I2L-MeshNet: Image-to-Lixel Prediction Network for Accurate 3D Human Pose and Mesh Estimation from a Single RGB Ima…

作者头像 李华
网站建设 2026/7/11 17:20:12

CANN Runtime编码规范

编码规范 【免费下载链接】runtime 本项目提供CANN运行时组件和维测功能组件。 项目地址: https://gitcode.com/cann/runtime 本文档定义 Runtime 仓代码实现时应遵守的统一编码规范。 文档结构&#xff1a; 一、通用 C/C 编码规范 适用于 Runtime 仓的所有 C/C 代码&…

作者头像 李华
网站建设 2026/7/11 17:19:42

CANN/runtime测试框架指南

测试框架指南 【免费下载链接】runtime 本项目提供CANN运行时组件和维测功能组件。 项目地址: https://gitcode.com/cann/runtime 返回 Runtime DT用例开发总纲 Runtime 仓测试主要基于 gtest&#xff0c;结合 gmock、mockcpp、公共桩和模块内 stub/data 组织用例。本文介…

作者头像 李华