SSブログ

Vivado HLS を使ってみた(その5) [FPGA]

試しに精度の計算をコンパイラ任せにしてみます。ap_fixedではなくintで書き直します。
#define fw    12
#define frc    4096    /*    pow(2, fw)    */
#define dat    256        /*    pow(2, dw)    */

YCbCr rgb2ycbcr(RGB s)
{

    YCbCr    d;

    const int    cY [3] = { 0.2126f*frc,  0.7152f*frc,  0.0722f*frc };
    const int    cCb[3] = {-0.1146f*frc, -0.3854f*frc,  0.5000f*frc };
    const int    cCr[3] = { 0.5000f*frc, -0.4542f*frc, -0.0458f*frc };
    const int    op5    = 0.5f * dat * frc;
    const int    llim   = 0;
    const int    ulim   = dat-1;

    int    R,G,B;
    int    Y,Cb,Cr;

    R = s.R;
    G = s.G;
    B = s.B;

    Y  = (cY [0] * R + cY [1] * G + cY [2] * B      ) /frc;
    Cb = (cCb[0] * R + cCb[1] * G + cCb[2] * B + op5) /frc;
    Cr = (cCr[0] * R + cCr[1] * G + cCr[2] * B + op5) /frc;

    if (Y  < llim) Y  = llim;    if (ulim < Y ) Y  = ulim;
    if (Cb < llim) Cb = llim;    if (ulim < Cb) Cb = ulim;
    if (Cr < llim) Cr = llim;    if (ulim < Cr) Cr = ulim;

    d.Y  = Y ;
    d.Cb = Cb;
    d.Cr = Cr;

    return d;
}
より簡単に。
レポートファイル。
================================================================
== Vivado HLS Report for 'rgb2ycbcr'
================================================================
* Date:

* Version:        2013.1
* Project:        rgb2ycbcr
* Solution:       solution1
* Product family: zynq zynq_fpv6 
* Target device:  xc7z020clg484-1


================================================================
== Performance Estimates
================================================================
+ Timing (ns): 
    * Summary: 
    +---------+--------+----------+------------+
    |  Clock  | Target | Estimated| Uncertainty|
    +---------+--------+----------+------------+
    |default  |  100.00|     23.29|       12.50|
    +---------+--------+----------+------------+

+ Latency (clock cycles): 
    * Summary: 
    +-----+-----+-----+-----+---------+
    |  Latency  |  Interval | Pipeline|
    | min | max | min | max |   Type  |
    +-----+-----+-----+-----+---------+
    |    0|    0|    1|    1|   none  |
    +-----+-----+-----+-----+---------+

    + Detail: 
        * Instance: 
        N/A

        * Loop: 
        N/A



================================================================
== Utilization Estimates
================================================================
* Summary: 
+-----------------+---------+-------+--------+-------+
|       Name      | BRAM_18K| DSP48E|   FF   |  LUT  |
+-----------------+---------+-------+--------+-------+
|Expression       |        -|      7|       0|    235|
|FIFO             |        -|      -|       -|      -|
|Instance         |        -|      -|       -|      -|
|Memory           |        -|      -|       -|      -|
|Multiplexer      |        -|      -|       -|      -|
|Register         |        -|      -|       -|      -|
|ShiftMemory      |        -|      -|       -|      -|
+-----------------+---------+-------+--------+-------+
|Total            |        0|      7|       0|    235|
+-----------------+---------+-------+--------+-------+
|Available        |      280|    220|  106400|  53200|
+-----------------+---------+-------+--------+-------+
|Utilization (%)  |        0|      3|       0|   ~0  |
+-----------------+---------+-------+--------+-------+

+ Detail: 
    * Instance: 
    N/A

    * Memory: 
    N/A

    * FIFO: 
    N/A

    * Shift register: 
    N/A

    * Expression: 
    +-----------------------+----------+-------+---+----+------------+------------+
    |     Variable Name     | Operation| DSP48E| FF| LUT| Bitwidth P0| Bitwidth P1|
    +-----------------------+----------+-------+---+----+------------+------------+
    |tmp_11_cast_fu_281_p2  |     *    |      1|  0|   0|           8|          12|
    |tmp_1_fu_136_p2        |     *    |      1|  0|   0|           8|          12|
    |tmp_2_fu_142_p2        |     *    |      1|  0|   0|           8|           9|
    |tmp_6_fu_179_p2        |     *    |      1|  0|   0|           8|          10|
    |tmp_7_cast_fu_189_p2   |     *    |      1|  0|   0|           8|          12|
    |tmp_7_fu_287_p2        |     *    |      1|  0|   0|           8|           9|
    |tmp_fu_126_p2          |     *    |      1|  0|   0|           8|          10|
    |tmp1_fu_152_p2         |     +    |      0|  0|  19|          19|          19|
    |tmp_10_fu_321_p2       |     +    |      0|  0|  21|          21|          21|
    |tmp_5_fu_219_p2        |     +    |      0|  0|  21|          21|          21|
    |p_neg1_fu_335_p2       |     -    |      0|  0|  21|           1|          21|
    |p_neg5_fu_233_p2       |     -    |      0|  0|  21|           1|          21|
    |p_neg_t1_fu_355_p2     |     -    |      0|  0|  10|           1|          10|
    |p_neg_t7_fu_253_p2     |     -    |      0|  0|  10|           1|          10|
    |Cb_fu_389_p3           |  Select  |      0|  0|  10|           1|           1|
    |Cr_fu_419_p3           |  Select  |      0|  0|  10|           1|           1|
    |agg_result_Cb_V        |  Select  |      0|  0|   8|           1|           2|
    |agg_result_Cr_V        |  Select  |      0|  0|   8|           1|           2|
    |tmp_13_fu_375_p3       |  Select  |      0|  0|  10|           1|          10|
    |tmp_s_fu_273_p3        |  Select  |      0|  0|  10|           1|          10|
    |icmp1_fu_437_p2        |   icmp   |      0|  0|   2|           2|           1|
    |icmp_fu_407_p2         |   icmp   |      0|  0|   2|           2|           1|
    |tmp_14_fu_383_p2       |   icmp   |      0|  0|  26|          21|          13|
    |tmp_15_fu_413_p2       |   icmp   |      0|  0|  26|          21|          13|
    +-----------------------+----------+-------+---+----+------------+------------+
    |Total                  |          |      7|  0| 235|         173|         251|
    +-----------------------+----------+-------+---+----+------------+------------+

    * Multiplexer: 
    N/A

    * Register: 
    N/A



================================================================
== Interface
================================================================
* Summary: 
+------------------------+-----+-----+------------+-----------------+--------------+
|        RTL Ports       | Dir | Bits|  Protocol  |  Source Object  |    C Type    |
+------------------------+-----+-----+------------+-----------------+--------------+
|ap_start                |  in |    1| ap_ctrl_hs |    rgb2ycbcr    | return value |
|ap_done                 | out |    1| ap_ctrl_hs |    rgb2ycbcr    | return value |
|ap_idle                 | out |    1| ap_ctrl_hs |    rgb2ycbcr    | return value |
|ap_ready                | out |    1| ap_ctrl_hs |    rgb2ycbcr    | return value |
|agg_result_Y_V          | out |    8|   ap_vld   |  agg_result_Y_V |    pointer   |
|agg_result_Y_V_ap_vld   | out |    1|   ap_vld   |  agg_result_Y_V |    pointer   |
|agg_result_Cb_V         | out |    8|   ap_vld   | agg_result_Cb_V |    pointer   |
|agg_result_Cb_V_ap_vld  | out |    1|   ap_vld   | agg_result_Cb_V |    pointer   |
|agg_result_Cr_V         | out |    8|   ap_vld   | agg_result_Cr_V |    pointer   |
|agg_result_Cr_V_ap_vld  | out |    1|   ap_vld   | agg_result_Cr_V |    pointer   |
|s_R_V                   |  in |    8|   ap_none  |      s_R_V      |    scalar    |
|s_G_V                   |  in |    8|   ap_none  |      s_G_V      |    scalar    |
|s_B_V                   |  in |    8|   ap_none  |      s_B_V      |    scalar    |
+------------------------+-----+-----+------------+-----------------+--------------+
こちらの方が若干小さいです。
Image 017.pngImage 018.png
中間値のbit幅が自動計算されてます。ap_fixedの時は18bitだった変数が自動で必要な幅になってます。また、リソースも減ってます。丸めやサチュレーション関連の回路でしょうか。

PlanAheadでインプリしたところ。
   Number of DSP48E1s                        5 out of 220     2%
   Number of External IOBs                  55 out of 200    27%
      Number of LOCed IOBs                   0 out of 55      0%

   Number of Slices                         60 out of 13300   1%
   Number of Slice Registers                 1 out of 106400  1%
      Number used as Flip Flops              1
      Number used as Latches                 0
      Number used as LatchThrus              0

   Number of Slice LUTS                    171 out of 53200   1%
   Number of Slice LUT-Flip Flop pairs     171 out of 53200   1%
こちらだと乗算器が減ってます。詳しくは見てませんが、シフトなどでまかなえる部分は最適化されたんだと思います。速度は約23[ns]。だいたい同じです。


精度をユーザがちゃんと制御したい、自動計算だと中間精度のbit数がふくれあがってしまう、などの場合はfixedなどで精度を制御する必要がありますが、普通はintでコンパイラ任せの方がなんか良さそうです。第一楽ですし。
nice!(0)  コメント(0)  トラックバック(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

Facebook コメント

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。