将当前读/写位置前移 - 2023.2 简体中文

AI 引擎内核与计算图编程指南 (UG1079)

Document ID
UG1079
Release Date
2023-12-04
Version
2023.2 简体中文

在如下描述中,input_buffer<TYPE> 表示任意允许的输入缓冲器端口数据类型。同样,output_buffer<TYPE> 表示任意允许的输出缓冲器端口数据类型。

表 1. 将当前读/写位置前移
用途 输入缓冲器端口类型 输出缓冲器端口类型
用于前移当前读/写位置 选项 1 是使用迭代器:
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pIn  = aie::begin(in);
TYPE data = *pIn++;
...

选项 2 是使用 data() API:
void simple_1(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
const TYPE* pIn=in.data();
TYPE data = pIn[index++];
...
选项 1 是使用迭代器:
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pOut= aie::begin(out);
TYPE data;
*pOut++ = data;
...
选项 2 是使用 data() API:
void simple_1(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
const TYPE* pOut =(TYPE*)out.data();
pOut[index++] = data;
...
用于前移当前读/写位置,前移的值为底层缓冲器端口类型的 4 倍。
#define VECTOR_SIZE 4
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pIn = aie::begin_vector<VECTOR_SIZE>(in);
v4TYPE data = *pIn++;
...
#define VECTOR_SIZE 4
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pOut  = aie::begin_vector<VECTOR_SIZE>(out);
v4TYPE data;
*pOut++ = data;
...
用于前移当前读/写位置,前移的值为底层缓冲器端口类型的 8 倍。
#define VECTOR_SIZE 8
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pIn = aie::begin_vector<VECTOR_SIZE>(in);
v8TYPE data = *pIn++;
...
#define VECTOR_SIZE 8
void simple(input_buffer<TYPE> & in, output_buffer<TYPE> & out)
{
auto pOut  = aie::begin_vector<VECTOR_SIZE>(out);
v8TYPE data;
*pOut++ = data;
...