在之前的博客中,介绍了一种使用脉动阵列计算矩阵乘法的方法,在那篇博客中,脉动阵列的主要特点是:数据从左向右流动,而权重则从上向下流动。而在谷歌第一代的TPU中,其脉动阵列却并非是这种形式的。 在谷歌的TPU中,权重是预先存储在
P
x
∗
P
y
P_x*P_y
Px∗Py个PE上的,并且整个计算过程权重都保持不动,即weight stationary,而数据自左向右流动,同时,每个PE单元的部分和则自上而下流动,下面是一个具体的计算过程演示: c++模拟代码:
#include
#include
#include
#include
#define M 4
#define N 4
using namespace std;
typedef int dtype;
struct PE{
dtype weight;
dtype feature;
dtype psum;
};
class Systolic{
public:
PE pe_arr[M][N];
public:
void Init(){ //初始化,psum置0
for(int i=0;i
关注
打赏