16 #ifndef NVHLS_VECTOR_H 17 #define NVHLS_VECTOR_H 20 #include <nvhls_int.h> 21 #include <nvhls_types.h> 22 #include <hls_globals.h> 23 #include <nvhls_array.h> 25 #include <nvhls_assert.h> 26 #include <nvhls_message.h> 30 inline std::string synth_to_string(
const unsigned int& n) {
32 std::ostringstream stm;
76 template <
typename Type,
unsigned int VectorLength>
79 Type data[VectorLength];
81 static const unsigned int type_width = Wrapped<Type>::width;
82 static const unsigned int length = VectorLength;
83 static const unsigned int width = type_width * VectorLength;
84 static const bool is_signed = Wrapped<Type>::is_signed;
89 #pragma hls_unroll yes 90 for (
unsigned i = 0; i < VectorLength; i++)
91 data[i] = that.data[i];
94 #pragma hls_unroll yes 95 for (
unsigned i = 0; i < VectorLength; i++)
100 #pragma hls_unroll yes 101 for (
unsigned int i = 0; i < VectorLength; i++) {
102 data[i] = nvhls::get_slc<type_width>(rawbits, i * type_width);
106 const NVUINTW(width) & rawbits_local = rawbits;
107 #pragma hls_unroll yes 108 for (
unsigned int i = 0; i < VectorLength; i++) {
109 data[i] = nvhls::get_slc<type_width>(rawbits_local, i * type_width);
114 #pragma hls_unroll yes 115 for (
unsigned i = 0; i < VectorLength; i++)
116 data[i] = that.data[i];
121 #pragma hls_unroll yes 122 for (
unsigned i = 0; i < VectorLength; i++)
123 out.data[i] = data[i];
125 Type& operator[](
unsigned int i) {
126 return this->data[i];
128 const Type& operator[](
unsigned int i)
const {
129 return this->data[i];
132 NVUINTW(width) to_rawbits() {
133 NVUINTW(width) rawbits = 0;
134 #pragma hls_unroll yes 135 for (
unsigned int i = 0; i < VectorLength; i++) {
141 void to_vector(NVUINTW(width) rawbits) {
142 #pragma hls_unroll yes 143 for (
unsigned int i = 0; i < VectorLength; i++) {
144 data[i] = nvhls::get_slc<type_width>(rawbits, i * type_width);
148 template <
unsigned int Size>
149 void Marshall(Marshaller<Size>& m) {
150 #pragma hls_unroll yes 151 for (
unsigned int i = 0; i < VectorLength; i++) {
157 template <
typename Type,
unsigned int VectorLength>
158 inline bool operator==(
161 bool is_equal =
true;
162 #pragma hls_unroll yes 163 for (
unsigned i = 0; i < VectorLength; i++)
164 is_equal &= (lhs.data[i] == rhs.data[i]);
168 template <
typename Type,
unsigned int VectorLength>
169 inline std::ostream& operator<<(std::ostream& os,
171 for (
unsigned i = 0; i < VectorLength; i++) {
172 os << vec.data[i] <<
" ";
208 template <
typename InType1,
typename InType2,
typename OutType,
209 unsigned int VectorLength,
bool Unroll>
214 if (Unroll ==
true) {
215 #pragma hls_unroll yes 216 for (
unsigned i = 0; i < VectorLength; i++)
217 out[i] = in1[i] * in2[i];
219 for (
unsigned i = 0; i < VectorLength; i++)
220 out[i] = in1[i] * in2[i];
256 template <
typename InType1,
typename InType2,
typename OutType,
257 unsigned int VectorLength,
bool Unroll>
261 if (Unroll ==
true) {
262 #pragma hls_unroll yes 263 for (
unsigned i = 0; i < VectorLength; i++)
264 out[i] = in1[i] + in2[i];
266 for (
unsigned i = 0; i < VectorLength; i++)
267 out[i] = in1[i] + in2[i];
302 template <
typename InType1,
typename InType2,
typename OutType,
303 unsigned int VectorLength,
bool Unroll>
307 if (Unroll ==
true) {
308 #pragma hls_unroll yes 309 for (
unsigned i = 0; i < VectorLength; i++)
310 out[i] = in1[i] - in2[i];
312 for (
unsigned i = 0; i < VectorLength; i++)
313 out[i] = in1[i] - in2[i];
348 template <
typename InType,
typename OutType,
unsigned int VectorLength,
353 if (VectorLength > 1) {
354 if (UseReduceTree ==
true) {
355 #pragma hls_unroll yes 356 #pragma cluster addtree 357 #pragma cluster_type both 358 for (
unsigned i = 0; i < VectorLength; i++)
361 for (
unsigned i = 0; i < VectorLength; i++)
404 template <
typename InType1,
typename InType2,
typename OutType,
405 unsigned int VectorLength,
bool UseReduceTree>
409 if (VectorLength > 1) {
410 if (UseReduceTree ==
true) {
411 #pragma hls_unroll yes 412 #pragma cluster multadd addtree 413 #pragma cluster_type both 414 for (
unsigned i = 0; i < VectorLength; i++)
415 sum += in1[i] * in2[i];
417 for (
unsigned i = 0; i < VectorLength; i++)
418 sum += in1[i] * in2[i];
421 sum = in1[0] * in2[0];
460 template <
typename InType1,
typename InType2,
typename InType3,
typename OutType,
461 unsigned int VectorLength,
bool Unroll>
467 if (Unroll ==
true) {
468 #pragma hls_unroll yes 469 for (
unsigned i = 0; i < VectorLength; i++)
470 out[i] = in1[i] * in2[i] + in3[i];
472 for (
unsigned i = 0; i < VectorLength; i++)
473 out[i] = in1[i] * in2[i] + in3[i];
486 template <
typename InType1,
typename InType2,
typename InType3,
487 typename OutType,
unsigned int VectorLength,
bool UseReduceTree>
491 if (UseReduceTree ==
true) {
492 #pragma hls_unroll yes 493 #pragma cluster addtree 494 #pragma cluster_type both 495 for (
unsigned i = 0; i < VectorLength; i++)
496 sum += in1[i] * in2[i];
498 for (
unsigned i = 0; i < VectorLength; i++)
499 sum += in1[i] * in2[i];
Vector helper container with vector operations.
void vector_sub(nv_scvector< InType1, VectorLength > in1, nv_scvector< InType2, VectorLength > in2, nv_scvector< OutType, VectorLength > &out)
Function implementing vector subtraction.
type1 set_slc(type1 X, type2 Y, const unsigned int i)
Function that replaces slice of bits.
void vector_add(nv_scvector< InType1, VectorLength > in1, nv_scvector< InType2, VectorLength > in2, nv_scvector< OutType, VectorLength > &out)
Function implementing vector addition.
void vector_mac(nv_scvector< InType1, VectorLength > in1, nv_scvector< InType2, VectorLength > in2, nv_scvector< InType3, VectorLength > in3, nv_scvector< OutType, VectorLength > &out)
Function implementing vector multiply and add.
void vector_mul(nv_scvector< InType1, VectorLength > in1, nv_scvector< InType2, VectorLength > in2, nv_scvector< OutType, VectorLength > &out)
Function implementing vector multiplication.
void reduction(nv_scvector< InType, VectorLength > in, OutType &out)
Function implementing vector reduction.
void dp(nv_scvector< InType1, VectorLength > in1, nv_scvector< InType2, VectorLength > in2, OutType &out)
Function implementing vector dot-product.