当前位置:网站首页>【CANN文档速递05期】一文让您了解什么是算子
【CANN文档速递05期】一文让您了解什么是算子
2022-06-24 18:57:00 【华为云】

什么是算子
深度学习算法由一个个计算单元组成,我们称这些计算单元为算子(Operator,简称OP)。在网络模型中,算子对应层中的计算逻辑,例如:卷积层(Convolution Layer)是一个算子;全连接层(Fully-connected Layer, FC layer)中的权值求和过程,是一个算子。
再例如:tanh、ReLU等,为在网络模型中被用做激活函数的算子。

算子的名称(Name)与类型(Type)
- 算子的名称:标识网络中的某个算子,同一网络中算子的名称需要保持唯一。
- 算子的类型:网络中每个算子根据算子类型进行实现逻辑的匹配,在一个网络中同一类型的算子可能存在多个。
如下图所示,Conv1、Pool1、Conv2都是此网络中的算子名称,其中Conv1与Conv2算子的类型都为Convolution,表示分别做一次卷积计算。

张量(Tensor)
- 张量是算子计算数据的容器,包括输入数据与输出数据。
- 张量描述符(TensorDesc)是对输入数据与输出数据的描述,主要包含如下属性:

下面我们详细介绍下张量描述符中的形状和数据排布格式。
形状(Shape)
张量的形状,比如形状(3,4)表示第一维有3个元素,第二维有4个元素,是一个3行4列的矩阵数组。在形状中有多少个数字,就代表这个张量有多少维。形状的第一个元素要看张量最外层的中括号中有几个元素,形状的第二个元素要看张量中从左边开始数第二个中括号中有几个元素,依此类推。例如:

下面我们看一下形状的物理含义,假设shape=(4, 20, 20, 3)。
假设有4张照片,即shape里4的含义,每张照片的宽和高都是20,也就是20*20=400个像素,每个像素点都由红/绿/蓝3色组成,即shape里面3的含义,这就是shape=(4, 20, 20, 3)的物理含义。

数据排布格式
在深度学习领域,多维数据通过多维数组存储,比如卷积神经网络的特征图(Feature Map)通常用四维数组保存,即4D格式:
- N:Batch数量,例如图像的数目。
- H:Height,特征图高度,即垂直高度方向的像素个数。
- W:Width,特征图宽度,即水平宽度方向的像素个数。
- C:Channels,特征图通道,例如彩色RGB图像的Channels为3。
由于数据只能线性存储,因此这四个维度有对应的顺序。不同深度学习框架会按照不同的顺序存储特征图数据,比如Caffe,排列顺序为[Batch, Channels, Height, Width],即NCHW。TensorFlow中,排列顺序为[Batch, Height, Width, Channels],即NHWC。
以一张格式为RGB的图片为例,NCHW中,C排列在外层,实际存储的是“RRRRRRGGGGGGBBBBBB”,即同一通道的所有像素值顺序存储在一起;而NHWC中C排列在最内层,实际存储的则是“RGBRGBRGBRGBRGBRGB”,即不同通道的同一位置的像素值顺序存储在一起。

尽管存储的数据相同,但不同的存储顺序会导致数据的访问特性不一致,因此即便进行同样的运算,相应的计算性能也会不同。
在昇腾AI处理器中,为了提高数据的访问效率,张量数据采用NC1HWC0的五维格式。其中C0与微架构强相关,等于AI Core中矩阵计算单元的大小,这部分数据需要连续存储;C1是将C维度按照C0进行拆分后的数目,即C1=C/C0。如果不整除,最后一份数据需要补齐以对齐C0。
更多介绍
了解更详细的内容,可以登录昇腾社区https://www.hiascend.com/,阅读相关文档:

昇腾CANN文档中心致力于为开发者提供更优质的内容和更便捷的开发体验,助力CANN开发者共建AI生态。任何意见和建议都可以在昇腾社区反馈,您的每一份关注都是我们前进的动力。
边栏推荐
- Install the custom module into the system and use find in the independent project_ Package found
- Information theory of popular science Shannon
- Programmers spend most of their time not writing code, but...
- 请教一个问题。adbhi支持保留一个ID最新100条数据库,类似这样的操作吗
- BSS应用程序云原生部署的8大挑战
- starring开发HttpJson接入点+数据库
- How to select the ECS type and what to consider?
- [go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
- Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi
- Fabric ledger data block structure analysis (I): how to analyze the smart contract transaction data in the ledger
猜你喜欢

UART communication (STM32F103 library function)

工作6年,月薪3W,1名PM的奋斗史

Some small requirements for SQL Engine for domestic database manufacturers

Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial

PHP OSS file reads and writes files, and workman generates temporary files and outputs them to the browser for download

Vs2017 add header file path method

R语言corrplot相关热图美化实例分析

Power efficiency test

Application practice | massive data, second level analysis! Flink+doris build a real-time data warehouse scheme

【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
随机推荐
How to use JWT authentication in thinkphp6
The cdc+mysql connector joins the date and time field from the dimension table by +8:00. Could you tell me which one is hosted by Alibaba cloud
应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案
SaltStack State状态文件配置实例
Vs2017 add header file path method
Starring V6 platform development take out point process
Internet of things? Come and see Arduino on the cloud
目前是不是只cdc 监控mysql 可以拿到新增列的数据 sqlserver不行是吧
Database index can improve query efficiency. Ask what will improve, what is the difference between inapplicable index and index use, and what will happen.
全链路业务追踪落地实践方案
Using dynamic time warping (DTW) to solve the similarity measurement of time series and the similarity identification analysis of pollution concentration in upstream and downstream rivers
starring V6平台开发接出点流程
Starring develops httpjson access point + Database
工作6年,月薪3W,1名PM的奋斗史
Zadig + cave Iast: let safety dissolve in continuous delivery
Vs2017 setting function Chinese Notes
three. Basic framework created by JS
Openstack actual installation and deployment tutorial, openstack installation tutorial
Clustered index (clustered index), nonclustered index (nonclustered index)
Steering gear control (stm32f103c8t6)