【问题标题】:How can I convert an HLS arbitrary precision type into a composite type如何将 HLS 任意精度类型转换为复合类型
【发布时间】:2016-06-28 13:38:55
【问题描述】:

我正在编写一个带有 AXI4 流输入的 HLS 单元。流中的几个单词组成了一个我想访问的结构。例如:

struct eth_header {
    ap_uint<48> dest;
    ap_uint<48> source;
    ap_uint<16> proto;
}

我可以轻松地缓冲流中的单词并将它们连接到一个大的ap_uint&lt;112&gt;。但是,我非常想将ap_uint&lt;112&gt; 转换为一个不错的结构,例如上面的eth_header,我可以使用字段语法访问它。我找不到这样做的好方法。我不能强制转换或使用联合,因为 ap_uint 类不是 POD。

是否可以以某种方式转换类型(无需为每个字段编写显式代码)?

编辑:不清楚是否需要从流中的几个单词转换结构。

【问题讨论】:

    标签: fpga xilinx vivado-hls


    【解决方案1】:

    我最终编写了显式代码来进行转换。例如:

    struct eth_header {
        ap_uint<48> dest;
        ap_uint<48> source;
        ap_uint<16> proto;
    
        static const int width = 112;
    
        eth_header(const ap_uint<width>& d) :
            dest  (d( 47,  0)),
            source(d( 95, 48)),
            proto (d(111, 96))
        {}
    
        operator ap_uint<width>()
        {
            return (hls_helpers::swap16(proto), source, dest);
        }
    };
    

    这很丑陋,但它是唯一对我有用的东西。

    【讨论】:

      【解决方案2】:

      正如here 所解释的那样,出于不同的原因,最好的方法是自己定义一个带有您需要的数据和您喜欢的数据类型的小结构。例如,使用浮点数:

      struct my_data{
        float data;
        bool last;
      };
      

      并且,如果您使用的是 AXI4 流接口:

      #define N 32
      
      
      void my_function(my_data input[N], my_data output[N])
      {
      #pragma HLS INTERFACE axis port=output
      #pragma HLS INTERFACE axis port=input
      #pragma HLS INTERFACE s_axilite port=return
      
      
      float tmp_data;
      float tmp_last;
      
      int k=0;
      
      for(k=0;k<N;k++)
          {
              tmp_data[k] = input[k].data;
              tmp_last[k] = input[k].last;
          }
      
      //...do something here
      
          for(k=0;k<25;k++)
          {
              output[k].data = tmp_data[k];
              output[k].last = tmp_last[k];
          }
       }
      

      【讨论】:

      • 也许我自己解释的不是很清楚,但是我要解析的数据是由轴接口外的几个单词组成的。我会更新问题。
      • 真的很好,我在做同样的事情,所以我们可以互相帮助
      • 当然,我很高兴听到你在做什么。让我们离线讨论
      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      相关资源
      最近更新 更多