Agora  1.2.0
Agora project
symbols.h
Go to the documentation of this file.
1 #ifndef SYMBOLS_H_
2 #define SYMBOLS_H_
3 
4 #include <mkl.h>
5 
6 #include <array>
7 #include <cstddef>
8 #include <map>
9 #include <string>
10 
11 #define EXPORT __attribute__((visibility("default")))
12 
13 #define STRINGIFY(x) #x
14 #define TOSTRING(x) STRINGIFY(x)
15 
16 // Number of frames received that we allocate space for in worker threads. This
17 // is the frame window that we track in Agora.
18 static constexpr size_t kFrameWnd = 40;
19 
20 #define TX_FRAME_DELTA (4)
21 #define SETTLE_TIME_MS (1)
22 
23 // Just-in-time optimization for MKL cgemm is available only after MKL 2019
24 // update 3. Disable this on systems with an older MKL version.
25 #if __INTEL_MKL__ >= 2020 || (__INTEL_MKL__ == 2019 && __INTEL_MKL_UPDATE__ > 3)
26 #define USE_MKL_JIT (1)
27 #else
28 #undef USE_MKL_JIT
29 #endif
30 
31 #define ENABLE_RB_IND (0)
32 
34 template <typename T>
35 static constexpr inline bool IsPowerOfTwo(T x) {
36  return x && ((x & T(x - 1)) == 0);
37 }
38 
39 enum class Direction : int { kDownlink, kUplink };
40 
42 enum class EventType : int {
43  kPacketRX,
44  kFFT,
45  kBeam,
46  kDemul,
47  kIFFT,
48  kPrecode,
49  kPacketTX,
51  kDecode,
52  kEncode,
53  kModul,
56  kFFTPilot,
57  kSNRReport, // Signal new SNR measurement from PHY to MAC
58  kRANUpdate, // Signal new RAN config to Agora
59  kRBIndicator, // Signal RB schedule to UEs
61 };
62 
63 static constexpr size_t kNumEventTypes =
64  static_cast<size_t>(EventType::kThreadTermination) + 1;
65 
66 // Types of Agora Doers
67 enum class DoerType : size_t {
68  kFFT,
69  kCSI,
70  kBeam,
71  kDemul,
72  kDecode,
73  kEncode,
74  kIFFT,
75  kPrecode,
76  kRC
77 };
78 
79 static constexpr std::array<DoerType, (static_cast<size_t>(DoerType::kRC) + 1)>
83 static constexpr size_t kNumDoerTypes = kAllDoerTypes.size();
84 
85 static const std::map<DoerType, std::string> kDoerNames = {
86  {DoerType::kFFT, std::string("FFT")},
87  {DoerType::kCSI, std::string("CSI")},
88  {DoerType::kBeam, std::string("Beamweights")},
89  {DoerType::kDemul, std::string("Demul")},
90  {DoerType::kDecode, std::string("Decode")},
91  {DoerType::kEncode, std::string("Encode")},
92  {DoerType::kIFFT, std::string("iFFT")},
93  {DoerType::kPrecode, std::string("Precode")},
94  {DoerType::kRC, std::string("RC")}};
95 
96 enum class PrintType : int {
98  kPacketRX,
99  kFFTPilots,
100  kFFTData,
101  kFFTCal,
102  kBeam,
103  kDemul,
104  kIFFT,
105  kPrecode,
107  kPacketTX,
108  kDecode,
109  kEncode,
110  kRC,
112  kPacketToMac,
113  kModul
114 };
115 
116 enum ScheduleProcessingFlags : uint8_t {
117  kNone = 0,
121 };
122 
123 // Moved from Agora class
125 static constexpr size_t kDefaultMessageQueueSize = 512;
126 static constexpr size_t kDefaultWorkerQueueSize = 256;
127 // Max number of worker threads allowed
128 //static constexpr size_t kMaxWorkerNum = 50;
129 static constexpr size_t kScheduleQueues = 2;
130 // Dequeue batch size, used to reduce the overhead of dequeue in main thread
131 static constexpr size_t kDequeueBulkSizeTXRX = 8;
132 static constexpr size_t kDequeueBulkSizeWorker = 4;
133 
134 // Enable thread pinning and exit if thread pinning fails. Thread pinning is
135 // crucial for good performance. For testing or developing Agora on machines
136 // with insufficient cores, disable this flag.
137 static constexpr bool kEnableThreadPinning = true;
138 static constexpr bool kEnableCoreReuse = false;
139 
140 #define BIGSTATION (0)
141 #if defined(USE_DPDK)
142 static constexpr bool kUseDPDK = true;
143 #else
144 static constexpr bool kUseDPDK = false;
145 #endif
146 
147 #if defined(ENABLE_MAC)
148 static constexpr bool kEnableMac = true;
149 #else
150 static constexpr bool kEnableMac = false;
151 #endif
152 
153 #if defined(USE_ARGOS)
154 static constexpr bool kUseArgos = true;
155 #else
156 static constexpr bool kUseArgos = false;
157 #endif
158 
159 #if defined(USE_UHD)
160 static constexpr bool kUseUHD = true;
161 #else
162 static constexpr bool kUseUHD = false;
163 #endif
164 
165 #if defined(ENABLE_CSV_LOG)
166 static constexpr bool kEnableCsvLog = true;
167 #else
168 static constexpr bool kEnableCsvLog = false;
169 #endif
170 
171 #if defined(ENABLE_MAT_LOG)
172 static constexpr bool kEnableMatLog = true;
173 #else
174 static constexpr bool kEnableMatLog = false;
175 #endif
176 
177 // Use 12-bit IQ sample to reduce network throughput
178 static constexpr bool kUse12BitIQ = false;
179 static constexpr bool kDebug12BitIQ = false;
180 static constexpr bool kDebugDownlink = false;
181 static constexpr bool kDebugUplink = false;
182 
183 static constexpr bool kUsePartialTrans = true;
184 
185 // Enable hard demodulation and disable LDPC decoding
186 // Useful for evaluating constellation quality
187 static constexpr bool kDownlinkHardDemod = false;
188 static constexpr bool kUplinkHardDemod = false;
189 
190 static constexpr bool kExportConstellation = false;
191 static constexpr bool kPrintPhyStats = true;
192 static constexpr bool kCollectPhyStats = true;
193 static constexpr bool kPrintBeamStats = true;
194 
195 static constexpr bool kStatsPrintFrameSummary = true;
196 static constexpr bool kDebugPrintPerFrameDone = true;
197 static constexpr bool kDebugPrintPerFrameStart = true;
198 static constexpr bool kDebugPrintPerSymbolDone = false;
199 static constexpr bool kDebugPrintPerTaskDone = false;
200 static constexpr bool kDebugPrintStatsPerThread = false;
201 static constexpr bool kDebugPrintInTask = false;
202 static constexpr bool kDebugMulticell = false;
203 static constexpr bool kRecordCalibrationMats = false;
204 
206 static constexpr bool kDebugPrintPilot = false;
207 
208 static constexpr bool kDebugRadioTX = false;
209 static constexpr bool kDebugRadioRX = false;
210 
211 static constexpr bool kLogMacPackets = false;
212 
213 enum class ThreadType {
214  kMaster,
215  kWorker,
216  kWorkerFFT,
217  kWorkerBeam,
218  kWorkerDemul,
220  kWorkerRX,
221  kWorkerTX,
222  kWorkerTXRX,
224  kMasterRX,
225  kMasterTX,
227 };
228 
229 static inline std::string ThreadTypeStr(ThreadType thread_type) {
230  switch (thread_type) {
231  case ThreadType::kMaster:
232  return "Master";
233  case ThreadType::kWorker:
234  return "Worker";
236  return "Worker (FFT)";
238  return "Worker (Beamweights)";
240  return "Worker (Demul)";
242  return "Worker (Decode)";
244  return "RX";
246  return "TX";
248  return "TXRX";
250  return "MAC TXRX";
252  return "Master (RX)";
254  return "Master (TX)";
256  return "Recorder Worker";
257  }
258  return "Invalid thread type";
259 }
260 
261 enum class SymbolType {
262  kBeacon,
263  kUL,
264  kDL,
265  kPilot,
266  kCalDL,
267  kCalUL,
268  kGuard,
269  kUnknown
270 };
271 static const std::map<char, SymbolType> kSymbolMap = {
273  {'D', SymbolType::kDL}, {'G', SymbolType::kGuard},
274  {'L', SymbolType::kCalUL}, {'P', SymbolType::kPilot},
275  {'U', SymbolType::kUL}};
276 
277 enum class SubcarrierType { kNull, kDMRS, kData };
278 
279 // Maximum number of symbols per frame allowed by Agora
280 static constexpr size_t kMaxSymbols = 70;
281 
282 // Maximum number of OFDM data subcarriers in the 5G spec
283 static constexpr size_t kMaxDataSCs = 3300;
284 
285 // Maximum number of antennas supported by Agora
286 static constexpr size_t kMaxAntennas = 64;
287 
288 // Maximum number of UEs supported by Agora
289 static constexpr size_t kMaxUEs = 64;
290 
291 // Maximum number of transceiver channels per radio
292 static constexpr size_t kMaxChannels = 2;
293 
294 // Maximum modulation (QAM256) supported by Agora. The implementation might
295 // support only lower modulation orders (e.g., up to QAM64), but using 8 here
296 // helps reduce false cache line sharing.
297 static constexpr size_t kMaxModType = 8;
298 
299 // Number of cellular frames tracked by Agora stats
300 static constexpr size_t kNumStatsFrames = 10000;
301 
302 // If true, enable timing measurements in workers
303 static constexpr bool kIsWorkerTimingEnabled = true;
304 
305 // Maximum breakdown of a statistic (e.g., timing)
306 static constexpr size_t kMaxStatsBreakdown = 4;
307 
308 // Maximum number of hardware threads on one machine
309 static constexpr size_t kMaxThreads = 128;
310 
311 // Number of subcarriers in one cache line, when represented as complex floats
312 static constexpr size_t kSCsPerCacheline = 64 / (2 * sizeof(float));
313 
314 // Agora Client sends UDP packets for UE #i (downlink packets at the client) to
315 // destination port kMacUserRemotePort + i
316 static constexpr size_t kMacUserRemotePort = 9070;
317 
318 // Agora Client Mac Thread listens for UDP packets from applications (uplink
319 // packets at the client)
320 static constexpr size_t kMacUserLocalPort = 9170;
321 
322 // After receiving decoded codeblocks from the PHY (uplink at the
323 // server, downlink at the client), we send UDP packets to kRemoteHostname
324 static constexpr char kMacRemoteHostname[] = "127.0.0.1";
325 
326 // Agora sends UDP packets for UE #i (uplink packets at the server) to
327 // destination port kMacBaseRemotePort + i
328 static constexpr size_t kMacBaseRemotePort = 8080;
329 
330 // Agora listens for UDP packets (downlink data packets at the server) at
331 // port kBaseLocalPort
332 static constexpr size_t kMacBaseLocalPort = 8180;
333 
334 // Agora sends control information over an out-of-band control channel
335 // to each UE #i, at port kBaseClientPort + i
337 static constexpr size_t kMacBaseClientPort = 7070;
338 
339 // Number of subcarriers in a partial transpose block
340 static constexpr size_t kTransposeBlockSize = 8;
341 static_assert(IsPowerOfTwo(kTransposeBlockSize)); // For cheap modulo
342 static_assert(kTransposeBlockSize % kSCsPerCacheline == 0);
343 
344 static constexpr size_t kCalibScGroupSize = 8;
345 static_assert(kCalibScGroupSize % kSCsPerCacheline == 0);
346 
347 #ifdef USE_AVX2_ENCODER
348 static constexpr bool kUseAVX2Encoder = true;
349 #else
350 static constexpr bool kUseAVX2Encoder = false;
351 #endif
352 
353 // Enable debugging for sender and receiver applications
354 static constexpr bool kDebugSenderReceiver = false;
355 
356 #if defined(ENABLE_HDF5)
357 static constexpr bool kOutputUlScData = true;
358 #else
359 static constexpr bool kOutputUlScData = false;
360 #endif
361 
362 static constexpr size_t kOfdmSymbolPerSlot = 1;
363 static constexpr size_t kOutputFrameNum = 1;
364 
365 static constexpr bool kDebugTxData = false;
366 #endif // SYMBOLS_H_
kDebugMulticell
static constexpr bool kDebugMulticell
Definition: symbols.h:202
SymbolType::kUnknown
@ kUnknown
kStatsPrintFrameSummary
static constexpr bool kStatsPrintFrameSummary
Definition: symbols.h:195
ThreadType::kWorkerBeam
@ kWorkerBeam
ThreadType::kRecorderWorker
@ kRecorderWorker
DoerType::kBeam
@ kBeam
kDebug12BitIQ
static constexpr bool kDebug12BitIQ
Definition: symbols.h:179
kMacRemoteHostname
static constexpr char kMacRemoteHostname[]
Definition: symbols.h:324
kMacUserLocalPort
static constexpr size_t kMacUserLocalPort
Definition: symbols.h:320
DoerType::kEncode
@ kEncode
kDownlinkComplete
@ kDownlinkComplete
Definition: symbols.h:119
kOutputUlScData
static constexpr bool kOutputUlScData
Definition: symbols.h:359
EventType::kRANUpdate
@ kRANUpdate
kDebugSenderReceiver
static constexpr bool kDebugSenderReceiver
Definition: symbols.h:354
SymbolType::kCalDL
@ kCalDL
kEnableMatLog
static constexpr bool kEnableMatLog
Definition: symbols.h:174
PrintType
PrintType
Definition: symbols.h:96
DoerType::kRC
@ kRC
kScheduleQueues
static constexpr size_t kScheduleQueues
Definition: symbols.h:129
kDownlinkHardDemod
static constexpr bool kDownlinkHardDemod
Definition: symbols.h:187
kMacBaseRemotePort
static constexpr size_t kMacBaseRemotePort
Definition: symbols.h:328
EventType::kDecode
@ kDecode
EventType::kThreadTermination
@ kThreadTermination
kUse12BitIQ
static constexpr bool kUse12BitIQ
Definition: symbols.h:178
kDebugPrintStatsPerThread
static constexpr bool kDebugPrintStatsPerThread
Definition: symbols.h:200
ThreadType::kWorkerDecode
@ kWorkerDecode
Direction
Direction
Definition: symbols.h:39
SymbolType::kPilot
@ kPilot
SubcarrierType::kDMRS
@ kDMRS
kFrameWnd
static constexpr size_t kFrameWnd
Definition: symbols.h:18
EventType::kPacketFromMac
@ kPacketFromMac
ThreadTypeStr
static std::string ThreadTypeStr(ThreadType thread_type)
Definition: symbols.h:229
EventType
EventType
Definition: symbols.h:42
ThreadType::kWorkerTXRX
@ kWorkerTXRX
EventType::kPacketPilotTX
@ kPacketPilotTX
kExportConstellation
static constexpr bool kExportConstellation
Definition: symbols.h:190
kNone
@ kNone
Definition: symbols.h:117
DoerType::kPrecode
@ kPrecode
kEnableThreadPinning
static constexpr bool kEnableThreadPinning
Definition: symbols.h:137
ThreadType::kMasterTX
@ kMasterTX
ThreadType::kWorkerFFT
@ kWorkerFFT
EventType::kPacketTX
@ kPacketTX
kPrintBeamStats
static constexpr bool kPrintBeamStats
Definition: symbols.h:193
PrintType::kPacketRXPilots
@ kPacketRXPilots
kRecordCalibrationMats
static constexpr bool kRecordCalibrationMats
Definition: symbols.h:203
kTransposeBlockSize
static constexpr size_t kTransposeBlockSize
Definition: symbols.h:340
x
x
Definition: simulate_performance.m:69
kMacBaseLocalPort
static constexpr size_t kMacBaseLocalPort
Definition: symbols.h:332
Direction::kUplink
@ kUplink
PrintType::kFFTPilots
@ kFFTPilots
DoerType::kCSI
@ kCSI
ThreadType
ThreadType
Definition: symbols.h:213
ThreadType::kWorker
@ kWorker
kCalibScGroupSize
static constexpr size_t kCalibScGroupSize
Definition: symbols.h:344
kSCsPerCacheline
static constexpr size_t kSCsPerCacheline
Definition: symbols.h:312
kDebugPrintPilot
static constexpr bool kDebugPrintPilot
Print the I/Q samples in the pilots.
Definition: symbols.h:206
EventType::kModul
@ kModul
kUsePartialTrans
static constexpr bool kUsePartialTrans
Definition: symbols.h:183
EventType::kFFTPilot
@ kFFTPilot
IsPowerOfTwo
static constexpr bool IsPowerOfTwo(T x)
Return true at compile time iff a constant is a power of two.
Definition: symbols.h:35
T
T
Definition: simulate_performance.m:4
EventType::kBeam
@ kBeam
SymbolType::kGuard
@ kGuard
kDequeueBulkSizeTXRX
static constexpr size_t kDequeueBulkSizeTXRX
Definition: symbols.h:131
EventType::kSNRReport
@ kSNRReport
EventType::kPacketToMac
@ kPacketToMac
kOutputFrameNum
static constexpr size_t kOutputFrameNum
Definition: symbols.h:363
kDebugPrintInTask
static constexpr bool kDebugPrintInTask
Definition: symbols.h:201
kDebugDownlink
static constexpr bool kDebugDownlink
Definition: symbols.h:180
ThreadType::kWorkerRX
@ kWorkerRX
kDoerNames
static const std::map< DoerType, std::string > kDoerNames
Definition: symbols.h:85
kSymbolMap
static const std::map< char, SymbolType > kSymbolMap
Definition: symbols.h:271
kPrintPhyStats
static constexpr bool kPrintPhyStats
Definition: symbols.h:191
kNumEventTypes
static constexpr size_t kNumEventTypes
Definition: symbols.h:63
kEnableMac
static constexpr bool kEnableMac
Definition: symbols.h:150
ThreadType::kMasterRX
@ kMasterRX
EventType::kFFT
@ kFFT
kEnableCsvLog
static constexpr bool kEnableCsvLog
Definition: symbols.h:168
PrintType::kFFTCal
@ kFFTCal
SymbolType::kBeacon
@ kBeacon
kProcessingComplete
@ kProcessingComplete
Definition: symbols.h:120
PrintType::kPacketTXFirst
@ kPacketTXFirst
kUseUHD
static constexpr bool kUseUHD
Definition: symbols.h:162
ThreadType::kWorkerMacTXRX
@ kWorkerMacTXRX
kUseAVX2Encoder
static constexpr bool kUseAVX2Encoder
Definition: symbols.h:350
Direction::kDownlink
@ kDownlink
EventType::kDemul
@ kDemul
kUseArgos
static constexpr bool kUseArgos
Definition: symbols.h:156
EventType::kPacketRX
@ kPacketRX
kDefaultMessageQueueSize
static constexpr size_t kDefaultMessageQueueSize
Definition: symbols.h:125
kMaxStatsBreakdown
static constexpr size_t kMaxStatsBreakdown
Definition: symbols.h:306
kNumStatsFrames
static constexpr size_t kNumStatsFrames
Definition: symbols.h:300
DoerType::kIFFT
@ kIFFT
kMaxChannels
static constexpr size_t kMaxChannels
Definition: symbols.h:292
EventType::kPrecode
@ kPrecode
kDebugPrintPerFrameStart
static constexpr bool kDebugPrintPerFrameStart
Definition: symbols.h:197
kUplinkHardDemod
static constexpr bool kUplinkHardDemod
Definition: symbols.h:188
kMaxDataSCs
static constexpr size_t kMaxDataSCs
Definition: symbols.h:283
kDebugUplink
static constexpr bool kDebugUplink
Definition: symbols.h:181
kIsWorkerTimingEnabled
static constexpr bool kIsWorkerTimingEnabled
Definition: symbols.h:303
DoerType::kDecode
@ kDecode
kDebugTxData
static constexpr bool kDebugTxData
Definition: symbols.h:365
kMaxModType
static constexpr size_t kMaxModType
Definition: symbols.h:297
kUseDPDK
static constexpr bool kUseDPDK
Definition: symbols.h:144
kDequeueBulkSizeWorker
static constexpr size_t kDequeueBulkSizeWorker
Definition: symbols.h:132
SubcarrierType
SubcarrierType
Definition: symbols.h:277
kMaxThreads
static constexpr size_t kMaxThreads
Definition: symbols.h:309
DoerType::kDemul
@ kDemul
EventType::kEncode
@ kEncode
kOfdmSymbolPerSlot
static constexpr size_t kOfdmSymbolPerSlot
Definition: symbols.h:362
ThreadType::kWorkerDemul
@ kWorkerDemul
kLogMacPackets
static constexpr bool kLogMacPackets
Definition: symbols.h:211
kDebugPrintPerSymbolDone
static constexpr bool kDebugPrintPerSymbolDone
Definition: symbols.h:198
SubcarrierType::kNull
@ kNull
kDebugRadioRX
static constexpr bool kDebugRadioRX
Definition: symbols.h:209
kCollectPhyStats
static constexpr bool kCollectPhyStats
Definition: symbols.h:192
kNumDoerTypes
static constexpr size_t kNumDoerTypes
Definition: symbols.h:83
ThreadType::kWorkerTX
@ kWorkerTX
ThreadType::kMaster
@ kMaster
SymbolType
SymbolType
Definition: symbols.h:261
EventType::kIFFT
@ kIFFT
SymbolType::kCalUL
@ kCalUL
ScheduleProcessingFlags
ScheduleProcessingFlags
Definition: symbols.h:116
PrintType::kFFTData
@ kFFTData
SubcarrierType::kData
@ kData
kMaxUEs
static constexpr size_t kMaxUEs
Definition: symbols.h:289
kDefaultWorkerQueueSize
static constexpr size_t kDefaultWorkerQueueSize
Definition: symbols.h:126
kMacUserRemotePort
static constexpr size_t kMacUserRemotePort
Definition: symbols.h:316
kMaxSymbols
static constexpr size_t kMaxSymbols
Definition: symbols.h:280
kMaxAntennas
static constexpr size_t kMaxAntennas
Definition: symbols.h:286
kDebugRadioTX
static constexpr bool kDebugRadioTX
Definition: symbols.h:208
kEnableCoreReuse
static constexpr bool kEnableCoreReuse
Definition: symbols.h:138
SymbolType::kUL
@ kUL
kDebugPrintPerFrameDone
static constexpr bool kDebugPrintPerFrameDone
Definition: symbols.h:196
kUplinkComplete
@ kUplinkComplete
Definition: symbols.h:118
DoerType::kFFT
@ kFFT
EventType::kRBIndicator
@ kRBIndicator
DoerType
DoerType
Definition: symbols.h:67
kMacBaseClientPort
static constexpr size_t kMacBaseClientPort
Definition: symbols.h:337
SymbolType::kDL
@ kDL
kDebugPrintPerTaskDone
static constexpr bool kDebugPrintPerTaskDone
Definition: symbols.h:199
kAllDoerTypes
static constexpr std::array< DoerType,(static_cast< size_t >DoerType::kRC)+1)> kAllDoerTypes
Definition: symbols.h:80