Vitis_Libraries

DataType

For the C++ language, the header file ap_int.h defines the arbitrary precision integer data
types ap_(u)int. For example, ap_int<8> represents an 8-bit signed integer data type
and ap_uint<234> represents a 234-bit unsigned integer type.

vivado HLS 的任意精度数据类型:

Language Integer Data Type Required Header
C [u]int< W>(1024 bits) .#include< ap_cint.h>
C++ ap_[u]int< W>(1024 bits) .#include< ap_int.h>
C++ ap_[u]fixed< W,I,Q,O,N> .#include< ap_fixed.h>

对于ap_[u]int类型
在Vivado Hls里是支持copy initialization(Y)和direct initialization(Y)这两种方式来进行初始化例如:
int data_i = 5;
ap_int<8> a_8bit_data_c = 18;
ap_int<8> a_8bit_data_d (18);
ap_int<8> a_8bit_data_r2(“0b010010”,2); //表示2进制
ap_int<8> a_8bit_data_r8(“0o22”,8); //表示8进制
ap_int<8> a_8bit_data_r10(“18”,10); //表示10进制
ap_int<8> a_8bit_data_r16(“0x12”,16); //表示16进制

对于ap_[u]fixed类型

定义如下

ap_[u]fixed;

这里W代表整个数据的字长,I代表整数部分的字长,那么小数部分被的字长就是W-I,Q表示量化模式(针对低位部分),O表示溢出模式,针对高位部分,例如:

ap_fixed<3, 2, AP_RND, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.5
ap_fixed<3, 2, AP_RND, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0
AP_RND 指示该值应舍入到最接近ap_ [u]定点类型的可表示值。

ap_fixed<3, 2, AP_RND_ZERO, AP_SAT> UAPFixed4 = 1.25; // Yields: 1.0
ap_fixed<3, 2, AP_RND_ZERO, AP_SAT> UAPFixed4 = -1.25; // Yields: -1.0
AP_RND_ZERO 指示该值向零取整(AP_RND_MIN_INF 向负无穷取整,AP_RND_INF 向正无穷取整)

p_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 15.0 4位无符号最大能取到15
ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = 19.0; // Yields: 7.0 4位有符号数最大能取到7
ap_ufixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: 0.0 4位无符号最大能取到0
ap_fixed<4, 4, AP_RND, AP_SAT> UAPFixed4 = -19.0; // Yields: -8.0 4位有符号极限能取到-8

AP_SAT 表示取到剩余位数能表示的最大的值

ap_ufixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_fixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = 19.0; // Yields: 0.0
ap_ufixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0
ap_fixed<4, 4, AP_RND, AP_SAT_ZERO> UAPFixed4 = -19.0; // Yields: 0.0

ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 19.0; // Yields: 3.0 10011取低4位就是3
ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = 31.0; // Yields: -1.0
ap_ufixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: 13.0
ap_fixed<4, 4, AP_RND, AP_WRAP> UAPFixed4 = -19.0; // Yields: -3.0
.
.
.

原文链接:https://blog.csdn.net/weixin_41967965/article/details/82080230
/---------------------------------------------------------------------------------------------

Vitis_Libraries

xf_params.hpp

Vitis_Libraries-master\vision\L1\include\common\

// Word width
enum _word_width {
     
    XF_2UW = 0,
    XF_8UW = 1,
    XF_9UW = 2,
    XF_32FW = 13,
    XF_64UW = 20
};
typedef _word_width XF_word_width_e;

xf_types.hpp


#define XF_BITSHIFT(flags) xfNPixelsPerCycle::datashift
#define XF_DEPTH(flags, npc) DataType::pixeldepth
#define XF_WORDWIDTH(flags, npc) DataType::wordwidth
#define XF_NPIXPERCYCLE(flags) xfNPixelsPerCycle::nppc
#define XF_SNAME(flags) typename StreamType::name
#define XF_WORDDEPTH(flags) StreamType::bitdepth

#define XF_PTNAME(flags) typename PixelType::name
#define XF_PIXELDEPTH(flags) PixelType::bitdepth
#define XF_PTUNAME(flags) typename PixelType::uname
template <int T>
struct xfNPixelsPerCycle {
     };

template <>
struct xfNPixelsPerCycle<XF_NPPC1> {
     
    static const int datashift = 0;
    static const int nppc = 1;
};
template <>
struct xfNPixelsPerCycle<XF_NPPC8> {
     
    static const int datashift = 3;
    static const int nppc = 8;
};
struct DataType<XF_8UC1, XF_NPPC8> {
     
    typedef ap_uint<64> name;
    typedef ap_uint<8> uname;
    typedef ap_uint<8> cname;
    typedef unsigned char sname;
    typedef unsigned long long wname;
    static const int bitdepth = 8;
    static const int pixelwidth = 8;
    static const int pixeldepth = XF_8UP;
    static const int wordwidth = XF_64UW;
    static const int channel = 1;
};

template <>
struct DataType<XF_8UC1, XF_NPPC1> {
     
    typedef ap_uint<8> name;
    typedef ap_uint<8> uname;
    typedef ap_uint<8> cname;
    typedef unsigned char sname;
    typedef unsigned char wname;
    static const int bitdepth = 8;
    static const int pixelwidth = 8;
    static const int pixeldepth = XF_8UP;
    static const int wordwidth = XF_8UW;
    static const int channel = 1;
};
typedef ap_uint<17> ap_uint17_t;
typedef ap_uint<8> ap_uint8_t;


template <int T>
struct PixelType {
     };
template <>
struct PixelType<XF_8UP> {
     
    typedef ap_uint<8> name;
    typedef ap_uint<8> uname;
    typedef unsigned char name2;
    static const int bitdepth = 8;
};
template <>
struct PixelType<XF_8SP> {
     
    typedef ap_int<8> name;
    typedef ap_uint<8> uname;
    static const int bitdepth = 8;
};
template <>
struct PixelType<XF_9UP> {
     
    typedef ap_uint<9> name;
    typedef ap_uint<9> uname;
    static const int bitdepth = 9;
};
template <>
struct PixelType<XF_9SP> {
     
    typedef ap_int<9> name;
    typedef ap_uint<9> uname;
    static const int bitdepth = 9;
};
template <>
struct PixelType<XF_16UP> {
     
    typedef ap_uint<16> name;
    typedef ap_uint<16> uname;
    static const int bitdepth = 16;
};
template <>
struct PixelType<XF_16SP> {
     
    typedef ap_int<16> name;
    typedef ap_uint<16> uname;
    static const int bitdepth = 16;
};
template <>
struct PixelType<XF_32UP> {
     
    typedef ap_uint<32> name;
    typedef ap_uint<32> uname;
    static const int bitdepth = 32;
};
template <>
struct PixelType<XF_32SP> {
     
    typedef ap_int<32> name;
    typedef ap_uint<32> uname;
    static const int bitdepth = 32;
};
template <>
struct PixelType<XF_19SP> {
     
    typedef ap_int<19> name;
    typedef ap_uint<19> uname;
    static const int bitdepth = 19;
};
template <>
struct PixelType<XF_35SP> {
     
    typedef ap_int<35> name;
    typedef ap_uint<35> uname;
    static const int bitdepth = 35;
};
template <>
struct PixelType<XF_32FP> {
     
    typedef float name;
    static const int bitdepth = 32;
};
template <>
struct PixelType<XF_24SP> {
     
    typedef ap_int<24> name;
    typedef ap_uint<24> uname;
    static const int bitdepth = 24;
};
template <>
struct PixelType<XF_20SP> {
     
    typedef ap_int<20> name;
    typedef ap_uint<20> uname;
    static const int bitdepth = 20;
};
template <>
struct PixelType<XF_48SP> {
     
    typedef ap_int<48> name;
    typedef ap_uint<48> uname;
    static const int bitdepth = 48;
};
template <>
struct PixelType<XF_2UP> {
     
    typedef ap_uint<2> name;
    static const int bitdepth = 2;
};
template <>
struct PixelType<XF_24UP> {
     
    typedef ap_uint<24> name;
    typedef ap_uint<24> uname;
    static const int bitdepth = 24;
};
template <int T>
struct StreamType {
     };
template <>
struct StreamType<XF_2UW> {
     
    typedef ap_uint<2> name;
    static const int bitdepth = 2;
};
template <>
struct StreamType<XF_8UW> {
     
    typedef ap_uint<8> name;
    static const int bitdepth = 8;
};
template <>
struct StreamType<XF_9UW> {
     
    typedef ap_uint<9> name;
    static const int bitdepth = 9;
};
template <>
struct StreamType<XF_10UW> {
     
    typedef ap_uint<10> name;
    static const int bitdepth = 10;
};
template <>
struct StreamType<XF_12UW> {
     
    typedef ap_uint<12> name;
    static const int bitdepth = 12;
};
template <>
struct StreamType<XF_16UW> {
     
    typedef ap_uint<16> name;
    static const int bitdepth = 16;
};
template <>
struct StreamType<XF_19SW> {
     
    typedef ap_int<19> name;
    static const int bitdepth = 19;
};
template <>
struct StreamType<XF_20UW> {
     
    typedef ap_uint<20> name;
    static const int bitdepth = 20;
};
template <>
struct StreamType<XF_22UW> {
     
    typedef ap_uint<22> name;
    static const int bitdepth = 22;
};
template <>
struct StreamType<XF_24UW> {
     
    typedef ap_uint<24> name;
    static const int bitdepth = 24;
};
template <>
struct StreamType<XF_24SW> {
     
    typedef ap_int<24> name;
    static const int bitdepth = 24;
};
template <>
struct StreamType<XF_30UW> {
     
    typedef ap_uint<30> name;
    static const int bitdepth = 30;
};
template <>
struct StreamType<XF_32UW> {
     
    typedef ap_uint<32> name;
    static const int bitdepth = 32;
};
template <>
struct StreamType<XF_32FW> {
     
    typedef float name;
    static const int bitdepth = 32;
};
.
.
.
template <>
struct StreamType<XF_64UW> {
     
    typedef ap_uint<64> name;
    static const int bitdepth = 64;
};

xf_utility.hpp

Vitis_Libraries-master\vision\L1\include\common\

namespace xf {
     
namespace cv {
     

/**
 * Extract Pixels from a packed word into an array from the index pos.
 * The number of pixels to be extracted is determined by the NPC.
 */


template <int NPC, int WORDWIDTH, int PIXELDEPTH>
void xfPackPixels(
    XF_PTNAME(PIXELDEPTH) * tmp_buf, XF_SNAME(WORDWIDTH) & val, uint16_t pos, int16_t loopIter, uint16_t& shift) {
     
// clang-format off
    #pragma HLS INLINE
    // clang-format on
    ap_uint<8> STEP = XF_PIXELDEPTH(PIXELDEPTH);

    for (ap_int<9> i = 0; i < loopIter; i++) {
     
// clang-format off
        #pragma HLS unroll
        // clang-format on
        XF_PTUNAME(PIXELDEPTH) tmp = tmp_buf[pos];
        val = val | (((XF_SNAME(WORDWIDTH))tmp) << (shift * STEP));
        pos++;
        shift++;
    }
}
template <int NPC, int WORDWIDTH, int PIXELDEPTH>
void xfExtractPixels(XF_PTNAME(PIXELDEPTH) * tmp_buf, XF_SNAME(WORDWIDTH) & val1, int pos) {
     
// clang-format off
    #pragma HLS inline off
    // clang-format on
    XF_SNAME(WORDWIDTH) v = val1;

    int shift = 0;
    int STEP = XF_PIXELDEPTH(PIXELDEPTH);
Extract_pixels_loop:
    for (int i = 0; i < (1 << (XF_BITSHIFT(NPC))); i++) {
     
// clang-format off
        #pragma HLS UNROLL
        // clang-format on
        tmp_buf[pos + i] = v.range(shift + STEP - 1, shift);
        shift = shift + STEP;
    }
}
} // namespace cv
} // namespace xf

你可能感兴趣的:(VITIS,HLS)