FelixReorder.hh
Go to the documentation of this file.
1 #ifndef FELIX_REORDER_HH_
2 #define FELIX_REORDER_HH_
3 
4 /*
5  * FelixReorder
6  * Authors
7  * Milo Vermeulen for base implementation
8  * Thijs Miedema for AVX implementation
9  * Description: Reorder Felix Frames in software to group headers and
10  * channeldata. Date: July 2018
11  */
12 
13 #include <immintrin.h>
14 #include <inttypes.h>
15 #include <cstring>
16 #include <iomanip>
17 #include <string>
18 
19 namespace dune {
20 
21 class FelixReorder {
22  private:
23  /// SIZE CONSTANTS ///
24  static constexpr size_t m_num_blocks_per_frame = 4;
25  static constexpr size_t m_num_ch_per_frame = 256;
26  static constexpr size_t m_num_ch_per_block = 64;
27  static constexpr size_t m_num_seg_per_block = 8;
28  static constexpr size_t m_num_ch_per_seg = 8;
29 
30  static constexpr size_t m_num_bytes_per_seg = 12;
31  static constexpr size_t m_num_bytes_per_reord_seg = 16;
32  static constexpr size_t m_num_bytes_per_block =
33  m_num_bytes_per_seg * m_num_seg_per_block;
34  static constexpr size_t m_coldata_header_size = 4 * 4;
35  static constexpr size_t m_wib_header_size = 4 * 4;
36  static constexpr size_t m_num_bytes_per_data = m_num_ch_per_frame * 2;
37  static constexpr size_t m_adc_size = 2;
38 
39  /// BIT OFFSET CONSTANTS ///
40  // Segments //
41  static const unsigned b_seg_0 = 0;
42  static const unsigned b_seg_1 = 12;
43  static const unsigned b_seg_2 = 24;
44  static const unsigned b_seg_3 = 36;
45 
46  // ADC value byte positions
47  static const uint8_t b_adc0_ch0_p0 = 0;
48  static const uint8_t b_adc0_ch0_p1 = 2;
49  static const uint8_t b_adc0_ch1_p0 = 2;
50  static const uint8_t b_adc0_ch1_p1 = 4;
51  static const uint8_t b_adc0_ch2_p0 = 6;
52  static const uint8_t b_adc0_ch2_p1 = 8;
53  static const uint8_t b_adc0_ch3_p0 = 8;
54  static const uint8_t b_adc0_ch3_p1 = 10;
55  static const uint8_t b_adc1_ch0_p0 = 1;
56  static const uint8_t b_adc1_ch0_p1 = 3;
57  static const uint8_t b_adc1_ch1_p0 = 3;
58  static const uint8_t b_adc1_ch1_p1 = 5;
59  static const uint8_t b_adc1_ch2_p0 = 7;
60  static const uint8_t b_adc1_ch2_p1 = 9;
61  static const uint8_t b_adc1_ch3_p0 = 9;
62  static const uint8_t b_adc1_ch3_p1 = 11;
63 
64  public:
65  /// Framesize public constants
66  static constexpr size_t m_num_bytes_per_frame =
67  m_wib_header_size +
68  m_num_blocks_per_frame * (m_coldata_header_size + m_num_bytes_per_block);
69  static constexpr size_t m_num_bytes_per_reord_frame =
70  m_wib_header_size +
71  m_num_blocks_per_frame * (m_coldata_header_size + m_num_ch_per_block * 2);
72 
73  /// METHODS ///
74  static bool do_reorder(uint8_t* dst, const uint8_t* src,
75  const unsigned& num_frames,
76  unsigned* num_faulty) noexcept;
77  static bool do_avx_reorder(uint8_t* dst, const uint8_t* src,
78  const unsigned& num_frames,
79  unsigned* num_faulty) noexcept;
80  static bool do_avx512_reorder(uint8_t* dst, const uint8_t* src,
81  const unsigned& num_frames,
82  unsigned* num_faulty) noexcept;
83 
84  static bool do_reorder_part(uint8_t* dst, const uint8_t* src,
85  const unsigned frames_start,
86  const unsigned frames_stop,
87  const unsigned& num_frames,
88  unsigned* num_faulty) noexcept;
89  static bool do_avx_reorder_part(uint8_t* dst, const uint8_t* src,
90  const unsigned frames_start,
91  const unsigned frames_stop,
92  const unsigned& num_frames,
93  unsigned* num_faulty) noexcept;
94  static bool do_avx512_reorder_part(uint8_t* dst, const uint8_t* src,
95  const unsigned frames_start,
96  const unsigned frames_stop,
97  const unsigned& num_frames,
98  unsigned* num_faulty) noexcept;
99 
100  static unsigned calculate_reordered_size(unsigned num_frames,
101  unsigned num_faulty) {
102  return m_num_bytes_per_data * num_frames +
103  (m_wib_header_size +
104  m_num_blocks_per_frame * m_coldata_header_size) *
105  (num_faulty + 1) +
106  (num_frames + 7) / 8;
107  }
108 
109 #ifdef __AVX2__
110  static const bool avx_available = true;
111 #else
112  static const bool avx_available = false;
113 #endif
114 
115 #ifdef __AVX512__REMOVE_ME_AFTER_GCC_PATCH
116  static const bool avx512_available = true;
117 #else
118  static const bool avx512_available = false;
119 #endif
120 
121  private:
122  /// FRAME OFFSETS ///
123  static constexpr unsigned m_frame0 = 0 * m_num_bytes_per_frame;
124  static constexpr unsigned m_frame1 = 1 * m_num_bytes_per_frame;
125  static constexpr unsigned m_frame2 = 2 * m_num_bytes_per_frame;
126  static constexpr unsigned m_frame3 = 3 * m_num_bytes_per_frame;
127 
128  static void copy_headers(uint8_t* dst, const uint8_t* src);
129  static void handle_headers(uint8_t* dst, const uint8_t* src,
130  const unsigned frame_index,
131  const unsigned& num_frames, unsigned* num_faulty);
132 
133  /// BASELINE REORDERING ///
134  static void baseline_handle_frames(uint8_t* dst, const uint8_t* src,
135  const unsigned frames_start,
136  const unsigned frames_stop,
137  const unsigned& num_frames,
138  unsigned* num_faulty);
139 
140 #ifdef __AVX2__
141  /// AVX2 REORDERING ///
142  static void reorder_avx_handle_four_segments(const uint8_t* src, uint8_t* dst,
143  const unsigned& num_frames);
144  static void reorder_avx_handle_block(const uint8_t* src, uint8_t* dst,
145  const unsigned& num_frames);
146  static void reorder_avx_handle_frame(const uint8_t* src, uint8_t* dst,
147  unsigned frame_num,
148  const unsigned& num_frames,
149  unsigned* num_faulty);
150 #endif
151 #ifdef __AVX512__REMOVE_ME_AFTER_GCC_PATCH
152  /// AVX512 REORDERING ///
153  static void reorder_avx512_handle_four_frames_two_segments(
154  const uint8_t* src, uint8_t* dst, const unsigned& num_frames);
155  static void reorder_avx512_handle_four_frames_one_block(
156  const uint8_t* src, uint8_t* dst, const unsigned& num_frames);
157  static void reorder_avx512_handle_four_frames(const uint8_t* src,
158  uint8_t* dst,
159  unsigned frame_num,
160  const unsigned& num_frames,
161  unsigned* num_faulty);
162 #endif
163 };
164 
165 } // namespace dune
166 
167 #endif /* FELIX_REORDER_HH_ */
static const uint8_t b_adc1_ch3_p0
Definition: FelixReorder.hh:61
static const uint8_t b_adc0_ch0_p1
Definition: FelixReorder.hh:48
static constexpr size_t m_num_bytes_per_seg
Definition: FelixReorder.hh:30
static const unsigned b_seg_0
BIT OFFSET CONSTANTS ///.
Definition: FelixReorder.hh:41
static constexpr size_t m_num_bytes_per_frame
Framesize public constants.
Definition: FelixReorder.hh:66
static bool do_avx512_reorder(uint8_t *dst, const uint8_t *src, const unsigned &num_frames, unsigned *num_faulty) noexcept
static constexpr size_t m_coldata_header_size
Definition: FelixReorder.hh:34
static constexpr size_t m_wib_header_size
Definition: FelixReorder.hh:35
static constexpr unsigned m_frame3
static const uint8_t b_adc0_ch0_p0
Definition: FelixReorder.hh:47
static constexpr size_t m_num_seg_per_block
Definition: FelixReorder.hh:27
static const uint8_t b_adc0_ch2_p1
Definition: FelixReorder.hh:52
static const uint8_t b_adc1_ch3_p1
Definition: FelixReorder.hh:62
static void copy_headers(uint8_t *dst, const uint8_t *src)
Definition: FelixReorder.cc:10
static bool do_reorder_part(uint8_t *dst, const uint8_t *src, const unsigned frames_start, const unsigned frames_stop, const unsigned &num_frames, unsigned *num_faulty) noexcept
static const uint8_t b_adc1_ch1_p1
Definition: FelixReorder.hh:58
static const bool avx512_available
static constexpr unsigned m_frame2
static const uint8_t b_adc1_ch2_p0
Definition: FelixReorder.hh:59
static constexpr size_t m_num_ch_per_seg
Definition: FelixReorder.hh:28
static const uint8_t b_adc1_ch0_p0
Definition: FelixReorder.hh:55
static const unsigned b_seg_2
Definition: FelixReorder.hh:43
static const bool avx_available
static const uint8_t b_adc0_ch2_p0
Definition: FelixReorder.hh:51
static bool do_reorder(uint8_t *dst, const uint8_t *src, const unsigned &num_frames, unsigned *num_faulty) noexcept
METHODS ///.
static const unsigned b_seg_1
Definition: FelixReorder.hh:42
static constexpr size_t m_adc_size
Definition: FelixReorder.hh:37
static constexpr size_t m_num_bytes_per_reord_seg
Definition: FelixReorder.hh:31
static constexpr size_t m_num_ch_per_block
Definition: FelixReorder.hh:26
static const uint8_t b_adc0_ch3_p0
Definition: FelixReorder.hh:53
static const unsigned b_seg_3
Definition: FelixReorder.hh:44
static const uint8_t b_adc0_ch1_p1
Definition: FelixReorder.hh:50
static bool do_avx512_reorder_part(uint8_t *dst, const uint8_t *src, const unsigned frames_start, const unsigned frames_stop, const unsigned &num_frames, unsigned *num_faulty) noexcept
static constexpr size_t m_num_blocks_per_frame
SIZE CONSTANTS ///.
Definition: FelixReorder.hh:24
static constexpr size_t m_num_ch_per_frame
Definition: FelixReorder.hh:25
static bool do_avx_reorder_part(uint8_t *dst, const uint8_t *src, const unsigned frames_start, const unsigned frames_stop, const unsigned &num_frames, unsigned *num_faulty) noexcept
static const uint8_t b_adc0_ch1_p0
Definition: FelixReorder.hh:49
static const uint8_t b_adc1_ch0_p1
Definition: FelixReorder.hh:56
static bool do_avx_reorder(uint8_t *dst, const uint8_t *src, const unsigned &num_frames, unsigned *num_faulty) noexcept
static constexpr size_t m_num_bytes_per_reord_frame
Definition: FelixReorder.hh:69
static const uint8_t b_adc1_ch1_p0
Definition: FelixReorder.hh:57
static const uint8_t b_adc0_ch3_p1
Definition: FelixReorder.hh:54
static const uint8_t b_adc1_ch2_p1
Definition: FelixReorder.hh:60
static constexpr size_t m_num_bytes_per_data
Definition: FelixReorder.hh:36
static constexpr size_t m_num_bytes_per_block
Definition: FelixReorder.hh:32
static constexpr unsigned m_frame1
static void baseline_handle_frames(uint8_t *dst, const uint8_t *src, const unsigned frames_start, const unsigned frames_stop, const unsigned &num_frames, unsigned *num_faulty)
BASELINE REORDERING ///.
Definition: FelixReorder.cc:88
static unsigned calculate_reordered_size(unsigned num_frames, unsigned num_faulty)
static void handle_headers(uint8_t *dst, const uint8_t *src, const unsigned frame_index, const unsigned &num_frames, unsigned *num_faulty)
Definition: FelixReorder.cc:23
static constexpr unsigned m_frame0
FRAME OFFSETS ///.