FC2カウンター FPGAの部屋 Vivado HLSでのAXI4-Stream のテンプレートを作成する1
fc2ブログ

FPGAやCPLDの話題やFPGA用のツールの話題などです。 マニアックです。 日記も書きます。

FPGAの部屋

FPGAの部屋の有用と思われるコンテンツのまとめサイトを作りました。Xilinx ISEの初心者の方には、FPGAリテラシーおよびチュートリアルのページをお勧めいたします。

Vivado HLSでのAXI4-Stream のテンプレートを作成する1

これから作る畳み込みニューラルネットワークについての目標2”で構想したAXI4-Stream で接続する畳み込みニューラルネットワークを作成するためには、ストリームのデータ幅を拡張する必要がある。そのため、Vivado HLSでAXI4-Stream のデータ幅を拡張するテンプレートを作成してC コードの合成を行ってみよう。

Vivado HLS 2017.4 で stream_test プロジェクトを作成した。
stream_test_1_180211.png

stream_test.h を示す。

// stream_test.h
// 2018/02/11 by marsee
//

#ifndef __STREAM_TEST_H__
#define __STREAM_TEST_H__
#include <ap_fixed.h>

template<int W, int I, int N, int U, int TI, int TD>
    struct ap_fixed_axis{
        ap_fixed<W, I, AP_TRN, AP_WRAP> data[N];
        ap_uint<(W+7)/8> keep;
        ap_uint<(W+7)/8> strb;
        ap_uint<U>       user;
        ap_uint<1>       last;
        ap_uint<TI>      id;
        ap_uint<TD>      dest;
    };

template<int W, int I, int N, int U, int TI, int TD>
    struct ap_ufixed_axis{
        ap_ufixed<W, I, AP_TRN, AP_WRAP> data[N];
        ap_uint<(W+7)/8> keep;
        ap_uint<(W+7)/8> strb;
        ap_uint<U>       user;
        ap_uint<1>       last;
        ap_uint<TI>      id;
        ap_uint<TD>      dest;
    };

#endif


データの配列 data[N] を定義して、畳み込みフィルタ数分のデータ幅のストリームを行うつもりだ。データの配列は任意精度固定小数点データ型とした。

stream_test.cpp を示す。

// stream_test.cpp
// 2018/02/11 by marsee
//

#include <ap_int.h>
#include <hls_stream.h>
#include <ap_axi_sdata.h>
#include <hls_video.h>

#include "stream_test.h"

int stream_test(hls::stream<ap_fixed_axis<16,6,2,1,1,1> >& ins,
        hls::stream<ap_fixed_axis<16,6,2,1,1,1> >& outs){
#pragma HLS INTERFACE axis register both port=outs
#pragma HLS INTERFACE axis register both port=ins
#pragma HLS INTERFACE s_axilite port=return
    ap_fixed_axis<16,6,2,1,1,1> ins_t;
    ap_fixed_axis<16,6,2,1,1,1> outs_t;

    for(int y=0; y<10; y++){
        for(int x=0; x<56; x++){
            ins >> ins_t;
            outs_t.data[0] = ins_t.data[0] * (ap_fixed<166, AP_TRN, AP_WRAP>)2.0;
            outs_t.data[1] = ins_t.data[1] * (ap_fixed<166, AP_TRN, AP_WRAP>)3.0;

            outs_t.user = 1;
            outs_t.last = 0;

            outs << outs_t;
        }
    }

    return(0);
}



これで、C コードの合成を行ったところエラーが発生した。
stream_test_2_180211.png

ERROR: [XFORM 203-103] Cannot partition array 'ins.V.data.V' (stream_test/stream_test.cpp:12): different array partition directive on the same group of AXI-Stream ports.
ERROR: [HLS 200-70] Pre-synthesis failed.
command 'ap_source' returned error code
    while executing
"source C:/Users/Masaaki/Documents/VIvado_HLS/ZYBO_Z7-20/test/stream_test/solution1/csynth.tcl"
    invoked from within
"hls::main C:/Users/Masaaki/Documents/VIvado_HLS/ZYBO_Z7-20/test/stream_test/solution1/csynth.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel 1 hls::main {*}$args"
    (procedure "hls_proc" line 5)
    invoked from within
"hls_proc $argv"
Finished C synthesis.


原因を検索してみると、Xilinx フォーラムの”AXI-Stream interface with data array side-channel does not build”が見つかった。
それによると配列じゃなくてフラットに 1 次元で書けということだ。

任意精度固定小数点データ型なので、どうやって 1 次元で書くかという問題はあるが、やり方はあると思う。次はそれを探っていこう。
  1. 2018年02月11日 08:57 |
  2. Vivado HLS
  3. | トラックバック:0
  4. | コメント:0

コメント

コメントの投稿


管理者にだけ表示を許可する

トラックバック URL
https://marsee101.blog.fc2.com/tb.php/4075-ee4ab11f
この記事にトラックバックする(FC2ブログユーザー)