Agora  1.2.0
Agora project
data_generator.h
Go to the documentation of this file.
1 
6 #ifndef DATA_GENERATOR_H_
7 #define DATA_GENERATOR_H_
8 
9 #include <string>
10 
11 #include "common_typedef_sdk.h"
12 #include "comms-lib.h"
13 #include "config.h"
14 #include "modulation.h"
15 #include "utils_ldpc.h"
16 
22  public:
23  // The profile of the input information bits
24  enum class Profile {
25  kRandom, // The input information bytes are chosen at random
26 
27  // The input informatioon bytes are {1, 2, 3, 1, 2, 3, ...} for UE 0,
28  // {4, 5, 6, 4, 5, 6, ...} for UE 1, and so on
30  };
31 
32  explicit DataGenerator(Config* cfg, uint64_t seed = 0,
33  Profile profile = Profile::kRandom)
34  : cfg_(cfg), profile_(profile) {
35  if (seed != 0) {
36  fast_rand_.seed_ = seed;
37  }
38  }
39 
40  void DoDataGeneration(const std::string& directory);
41 
49  void GenMacData(MacPacketPacked* mac, size_t ue_id) {
50  for (size_t i = 0; i < mac->PayloadLength(); i++) {
51  if (profile_ == Profile::kRandom) {
52  mac->DataPtr()[i] = static_cast<int8_t>(fast_rand_.NextU32());
53  } else if (profile_ == Profile::kProfile123) {
54  mac->DataPtr()[i] = 1 + (ue_id * 3) + (i % 3);
55  }
56  }
57  }
58 
65  void GenRawData(Direction dir, std::vector<int8_t>& information,
66  size_t ue_id) {
67  const LDPCconfig& lc = cfg_->LdpcConfig(dir);
68  information.resize(
70 
71  for (size_t i = 0; i < lc.NumInputBytes(); i++) {
72  if (profile_ == Profile::kRandom) {
73  information.at(i) = static_cast<int8_t>(fast_rand_.NextU32());
74  } else if (profile_ == Profile::kProfile123) {
75  information.at(i) = 1 + (ue_id * 3) + (i % 3);
76  }
77  }
78  }
79 
87  void GenCodeblock(Direction dir, const int8_t* input_ptr,
88  std::vector<int8_t>& encoded_codeword) {
89  const LDPCconfig& lc = cfg_->LdpcConfig(dir);
90  std::vector<int8_t> parity;
91  parity.resize(
93 
94  encoded_codeword.resize(
96 
98  &encoded_codeword.at(0), &parity.at(0), input_ptr);
99 
100  encoded_codeword.resize(lc.NumEncodedBytes());
101  }
102 
108  std::vector<complex_float> GetModulation(
109  const std::vector<int8_t>& encoded_codeword) {
110  std::vector<complex_float> modulated_codeword(cfg_->OfdmDataNum());
111  std::vector<uint8_t> mod_input(cfg_->OfdmDataNum());
112 
113  AdaptBitsForMod(reinterpret_cast<const uint8_t*>(&encoded_codeword[0]),
114  &mod_input[0],
117 
118  for (size_t i = 0; i < cfg_->OfdmDataNum(); i++) {
119  modulated_codeword[i] =
121  }
122  return modulated_codeword;
123  }
124 
125  std::vector<complex_float> GetDLModulation(
126  const std::vector<int8_t>& encoded_codeword, complex_float* pilot_seq) {
127  std::vector<complex_float> modulated_codeword(cfg_->OfdmDataNum());
128  std::vector<uint8_t> mod_input(cfg_->GetOFDMDataNum());
129 
130  AdaptBitsForMod(reinterpret_cast<const uint8_t*>(&encoded_codeword[0]),
131  &mod_input[0],
134 
135  for (size_t i = 0; i < cfg_->OfdmDataNum(); i++) {
136  if (cfg_->IsDataSubcarrier(i) == true) {
137  modulated_codeword[i] =
138  ModSingleUint8(mod_input[cfg_->GetOFDMDataIndex(i)],
140  } else {
141  modulated_codeword[i] = pilot_seq[i];
142  }
143  }
144  return modulated_codeword;
145  }
146 
147  std::vector<complex_float> GetModulation(const int8_t* encoded_codeword,
148  size_t num_bits) {
149  std::vector<complex_float> modulated_codeword(cfg_->OfdmDataNum());
150  std::vector<uint8_t> mod_input(cfg_->OfdmDataNum());
151 
152  AdaptBitsForMod(reinterpret_cast<const uint8_t*>(&encoded_codeword[0]),
153  &mod_input[0], BitsToBytes(num_bits),
155 
156  for (size_t i = 0; i < cfg_->OfdmDataNum(); i++) {
157  modulated_codeword[i] =
159  }
160  return modulated_codeword;
161  }
162 
169  std::vector<complex_float> BinForIfft(
170  const std::vector<complex_float>& modulated_codeword) const {
171  std::vector<complex_float> pre_ifft_symbol(cfg_->OfdmCaNum()); // Zeroed
172  std::memcpy(&pre_ifft_symbol[cfg_->OfdmDataStart()], &modulated_codeword[0],
173  cfg_->OfdmDataNum() * sizeof(complex_float));
174 
175  return pre_ifft_symbol;
176  }
177 
179  std::vector<complex_float> GetCommonPilotTimeDomain() const {
180  const std::vector<std::complex<float>> zc_seq = Utils::DoubleToCfloat(
182 
183  const std::vector<std::complex<float>> zc_common_pilot =
184  CommsLib::SeqCyclicShift(zc_seq, M_PI / 4.0); // Used in LTE SRS
185 
186  std::vector<complex_float> ret(cfg_->OfdmCaNum()); // Zeroed
187  for (size_t i = 0; i < cfg_->OfdmDataNum(); i++) {
188  ret[i + cfg_->OfdmDataStart()] = {zc_common_pilot[i].real(),
189  zc_common_pilot[i].imag()};
190  }
191 
192  return ret;
193  }
194 
195  private:
196  FastRand fast_rand_; // A fast random number generator
197  Config* cfg_; // The global Agora config
198  const Profile profile_; // The pattern of the input byte sequence
199 };
200 
201 #endif // DATA_GENERATOR_H_
sqrt
2 sqrt()
FastRand::seed_
uint64_t seed_
Definition: utils.h:181
CommsLib::IFFT
static MKL_LONG IFFT(std::vector< std::complex< float >> &in_out, int fft_size, bool normalize=true)
Definition: comms-lib.cc:410
LdpcEncodingInputBufSize
static size_t LdpcEncodingInputBufSize(size_t base_graph, size_t zc)
Definition: utils_ldpc.h:167
fmt::v8::detail::byte
byte
Definition: core.h:388
Config::UeAntNum
size_t UeAntNum() const
Definition: config.h:41
Table::Calloc
void Calloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:45
kOutputUlScData
static constexpr bool kOutputUlScData
Definition: symbols.h:359
complex_float
Definition: test_transpose.cc:22
kPrintDlTxData
static constexpr bool kPrintDlTxData
Definition: data_generator.cc:30
Config::SampsPerSymbol
size_t SampsPerSymbol() const
Definition: config.h:234
kDlLdpcDataPrefix
static const std::string kDlLdpcDataPrefix
Definition: data_generator.cc:39
size
end IFFT Reshape the symbol vector into two different spatial streams size
Definition: generate_data.m:73
fmt::v8::printf
auto printf(const S &fmt, const T &... args) -> int
Definition: printf.h:631
datatype_conversion.h
DataGenerator::GenRawData
void GenRawData(Direction dir, std::vector< int8_t > &information, size_t ue_id)
Generate one raw information bit sequence.
Definition: data_generator.h:65
Config::UeChannel
std::string UeChannel() const
Definition: config.h:114
FrameStats::NumBeaconSyms
size_t NumBeaconSyms() const
Definition: framestats.cc:87
Config::MacPacketsPerframe
size_t MacPacketsPerframe(Direction dir) const
Definition: config.h:276
LdpcEncodeHelper
static void LdpcEncodeHelper(size_t base_graph, size_t zc, size_t nRows, int8_t *encoded_buffer, int8_t *parity_buffer, const int8_t *input_buffer)
Definition: utils_ldpc.h:195
Config::OfdmTxZeroPrefix
size_t OfdmTxZeroPrefix() const
Definition: config.h:211
DataGenerator::Profile::kProfile123
@ kProfile123
DataGenerator::profile_
const Profile profile_
Definition: data_generator.h:198
Direction
Direction
Definition: symbols.h:39
Config::OfdmTxZeroPostfix
size_t OfdmTxZeroPostfix() const
Definition: config.h:212
kPrintUplinkInformationBytes
static constexpr bool kPrintUplinkInformationBytes
Definition: data_generator.cc:32
Config::CpLen
size_t CpLen() const
Definition: config.h:46
modulation.h
Config::GetOFDMDataNum
size_t GetOFDMDataNum() const
Definition: config.h:554
Agora_memory::PaddedAlignedAlloc
void * PaddedAlignedAlloc(Alignment_t alignment, size_t size)
Definition: memory_manage.cc:15
Config::NoiseLevel
float NoiseLevel() const
Definition: config.h:310
LDPCconfig::NumRows
size_t NumRows() const
Definition: ldpc_config.h:52
crc.h
memory_manage.h
Config::BsAntNum
size_t BsAntNum() const
Definition: config.h:35
BitsToBytes
static size_t BitsToBytes(size_t n_bits)
Definition: utils_ldpc.h:124
fclose
fclose(fileID)
AGORA_LOG_ERROR
#define AGORA_LOG_ERROR(...)
Definition: logger.h:39
Direction::kUplink
@ kUplink
Config::Frame
const FrameStats & Frame() const
Definition: config.h:340
AGORA_LOG_TRACE
#define AGORA_LOG_TRACE(...)
Definition: logger.h:92
DataGenerator::GenCodeblock
void GenCodeblock(Direction dir, const int8_t *input_ptr, std::vector< int8_t > &encoded_codeword)
Generate the encoded bit sequence for one code block for the active LDPC configuration from the input...
Definition: data_generator.h:87
LdpcEncodingEncodedBufSize
static size_t LdpcEncodingEncodedBufSize(size_t base_graph, size_t zc)
Definition: utils_ldpc.h:181
DataGenerator::BinForIfft
std::vector< complex_float > BinForIfft(const std::vector< complex_float > &modulated_codeword) const
An array with OfdmDataNum() elements with the OfdmDataNum() modulated elements binned at the center.
Definition: data_generator.h:169
Table< complex_float >
kPrintDownlinkInformationBytes
static constexpr bool kPrintDownlinkInformationBytes
Definition: data_generator.cc:33
DataGenerator::GetModulation
std::vector< complex_float > GetModulation(const int8_t *encoded_codeword, size_t num_bits)
Definition: data_generator.h:147
Config::UeNum
size_t UeNum() const
Definition: config.h:40
fmt::v8::detail::abs
constexpr std::chrono::duration< Rep, Period > abs(std::chrono::duration< Rep, Period > d)
Definition: chrono.h:1488
DataGenerator::GenMacData
void GenMacData(MacPacketPacked *mac, size_t ue_id)
Generate random Mac payload bit sequence.
Definition: data_generator.h:49
Config::OfdmDataNum
size_t OfdmDataNum() const
Definition: config.h:47
kOutputFrameNum
static constexpr size_t kOutputFrameNum
Definition: symbols.h:363
data_generator.h
Implementation file for the Data generator class to generate binary files as inputs to Agora,...
fmt::v8::detail::num_bits
constexpr auto num_bits() -> int
Definition: format.h:343
DataGenerator::Profile::kRandom
@ kRandom
DataGenerator::fast_rand_
FastRand fast_rand_
Definition: data_generator.h:196
DataGenerator::DoDataGeneration
void DoDataGeneration(const std::string &directory)
Definition: data_generator.cc:51
simd_types.h
Aligned types for SIMD compatibility.
fmt::v8::ptr
auto ptr(T p) -> const void *
Definition: format.h:2680
Table::Free
void Free()
Definition: memory_manage.h:84
kPrintDlModData
static constexpr bool kPrintDlModData
Definition: data_generator.cc:31
CommsLib::FFTShift
static std::vector< std::complex< float > > FFTShift(const std::vector< std::complex< float >> &in)
Definition: comms-lib.cc:581
data_start
data_start
Definition: inspect_agora_results.m:17
MacPacketPacked::Set
void Set(const uint16_t &f, const uint16_t &s, const uint16_t &u, const uint16_t &data_size)
Definition: message.h:286
FrameStats::ClientUlPilotSymbols
size_t ClientUlPilotSymbols() const
Definition: framestats.h:73
scrambler.h
Scramble Class and helper functions.
i
for i
Definition: generate_data.m:107
Config::OfdmCaNum
size_t OfdmCaNum() const
Definition: config.h:45
Config::MacPayloadMaxLength
size_t MacPayloadMaxLength(Direction dir) const
Definition: config.h:272
FrameStats::NumDlDataSyms
size_t NumDlDataSyms() const
Definition: framestats.h:83
DataGenerator
Building blocks for generating end-to-end or unit test workloads for Agora.
Definition: data_generator.h:21
LDPCconfig::NumInputBytes
size_t NumInputBytes() const
Definition: ldpc_config.h:30
kPrintDebugCSI
static constexpr bool kPrintDebugCSI
Definition: data_generator.cc:28
u
Plot Rx waveform for u
Definition: inspect_single_frame.m:108
comms-lib.h
Communications Library: a) Generate pilot/preamble sequences b) OFDM modulation.
Config::ModTable
Table< complex_float > & ModTable(Direction dir)
Definition: config.h:284
Agora_memory::Alignment_t::kAlign64
@ kAlign64
Config::NumBytesPerCb
size_t NumBytesPerCb(Direction dir) const
Definition: config.h:251
Direction::kDownlink
@ kDownlink
ModSingleUint8
complex_float ModSingleUint8(uint8_t x, Table< complex_float > &mod_table)
Definition: modulation.cc:213
Config::IsDataSubcarrier
bool IsDataSubcarrier(size_t sc_id) const
Definition: config.h:562
CommsLib::kLteZadoffChu
@ kLteZadoffChu
Definition: comms-lib.h:35
LDPCconfig
Definition: ldpc_config.h:14
Config::MacPacketLength
size_t MacPacketLength(Direction dir) const
Definition: config.h:268
Config::OfdmDataStart
size_t OfdmDataStart() const
Definition: config.h:48
FastRand::NextU32
uint32_t NextU32()
Definition: utils.h:189
Config::LdpcConfig
const LDPCconfig & LdpcConfig(Direction dir) const
Definition: config.h:280
FrameStats::ClientDlPilotSymbols
size_t ClientDlPilotSymbols() const
Definition: framestats.h:76
SimdAlignByteVector
std::vector< std::byte, boost::alignment::aligned_allocator< std::byte, kSimdAlignment > > SimdAlignByteVector
Definition: simd_types.h:18
FrameStats::NumDLSyms
size_t NumDLSyms() const
Definition: framestats.cc:83
DataGenerator::Profile
Profile
Definition: data_generator.h:24
kUlDataPrefix
static const std::string kUlDataPrefix
Output files.
Definition: data_generator.cc:36
n
n
Definition: simulate_performance.m:1
CommsLib::SeqCyclicShift
static std::vector< std::complex< float > > SeqCyclicShift(const std::vector< std::complex< float >> &in, float alpha)
Definition: comms-lib.cc:725
kDlTxPrefix
static const std::string kDlTxPrefix
Definition: data_generator.cc:41
kUlScBitsPrefix
static const std::string kUlScBitsPrefix
Definition: data_generator.cc:42
FrameStats::NumULSyms
size_t NumULSyms() const
Definition: framestats.cc:85
Config::MacBytesNumPerframe
size_t MacBytesNumPerframe(Direction dir) const
Definition: config.h:263
AGORA_LOG_SYMBOL
#define AGORA_LOG_SYMBOL(...)
Definition: logger.h:82
LDPCconfig::ExpansionFactor
uint16_t ExpansionFactor() const
Definition: ldpc_config.h:47
Agora_memory::Alignment_t::kAlign32
@ kAlign32
Config::NumUeChannels
size_t NumUeChannels() const
Definition: config.h:99
Config
Definition: config.h:26
FastRand
Definition: utils.h:179
AGORA_LOG_INFO
#define AGORA_LOG_INFO(...)
Definition: logger.h:62
DataGenerator::cfg_
Config * cfg_
Definition: data_generator.h:197
fwrite
fwrite(fileID, pilot_f, 'float')
kOfdmSymbolPerSlot
static constexpr size_t kOfdmSymbolPerSlot
Definition: symbols.h:362
MacPacketPacked::PayloadLength
uint16_t PayloadLength() const
Definition: message.h:282
Table::Malloc
void Malloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:37
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
Config::NumPaddingBytesPerCb
size_t NumPaddingBytesPerCb(Direction dir) const
Definition: config.h:255
MacPacketPacked::DataPtr
unsigned char * DataPtr()
Definition: message.h:294
Config::ScrambleEnabled
bool ScrambleEnabled() const
Definition: config.h:296
kRxLdpcPrefix
static const std::string kRxLdpcPrefix
Definition: data_generator.cc:40
to_string
std::string to_string() const
Definition: eth_common.h:64
LDPCconfig::BaseGraph
uint16_t BaseGraph() const
Definition: ldpc_config.h:46
Config::Modulation
std::string Modulation(Direction dir) const
Definition: config.h:243
LDPCconfig::NumEncodedBytes
size_t NumEncodedBytes() const
Definition: ldpc_config.h:36
config.h
Declaration file for the configuration class which importants json configuration values into class va...
MacPacketPacked
Definition: message.h:274
RandFloatFromShort
static float RandFloatFromShort(float min, float max)
Definition: data_generator.cc:44
DataGenerator::GetDLModulation
std::vector< complex_float > GetDLModulation(const std::vector< int8_t > &encoded_codeword, complex_float *pilot_seq)
Definition: data_generator.h:125
kDlDataPrefix
static const std::string kDlDataPrefix
Definition: data_generator.cc:38
DataGenerator::GetCommonPilotTimeDomain
std::vector< complex_float > GetCommonPilotTimeDomain() const
Return the time-domain pilot symbol with OfdmCaNum complex floats.
Definition: data_generator.h:179
kShrtFltConvFactor
static constexpr float kShrtFltConvFactor
Definition: datatype_conversion.h:18
FrameStats::NumUlDataSyms
size_t NumUlDataSyms() const
Definition: framestats.h:80
kDebugPrintRxData
static constexpr bool kDebugPrintRxData
Definition: data_generator.cc:29
Config::FreqOrthogonalPilot
bool FreqOrthogonalPilot() const
Definition: config.h:208
kUlLdpcDataPrefix
static const std::string kUlLdpcDataPrefix
Definition: data_generator.cc:37
Utils::DoubleToCfloat
static std::vector< std::complex< float > > DoubleToCfloat(const std::vector< std::vector< double >> &in)
Definition: utils.cc:232
LdpcEncodingParityBufSize
static size_t LdpcEncodingParityBufSize(size_t base_graph, size_t zc)
Definition: utils_ldpc.h:174
CommsLib::GetSequence
static std::vector< std::vector< double > > GetSequence(size_t seq_len, int type)
Definition: comms-lib.cc:734
max
max(y1, y1_1)
Config::ModOrderBits
size_t ModOrderBits(Direction dir) const
Definition: config.h:247
LDPCconfig::NumBlocksInSymbol
void NumBlocksInSymbol(size_t num_blocks)
Definition: ldpc_config.h:41
FrameStats::GetULSymbol
size_t GetULSymbol(size_t location) const
Definition: framestats.cc:114
Config::GetOFDMDataIndex
size_t GetOFDMDataIndex(size_t sc_id) const
Definition: config.h:558
AdaptBitsForMod
static void AdaptBitsForMod(const uint8_t *bit_seq_in, uint8_t *bytes_out, size_t len, size_t mod_type)
Fill-in the bytes of bytes_out with mod_type bits per byte, taken from the bit sequence bit_seq_in.
Definition: utils_ldpc.h:60
DataGenerator::GetModulation
std::vector< complex_float > GetModulation(const std::vector< int8_t > &encoded_codeword)
Return the output of modulating the encoded codeword.
Definition: data_generator.h:108
Config::OfdmDataStop
size_t OfdmDataStop() const
Definition: config.h:50
FrameStats::NumTotalSyms
size_t NumTotalSyms() const
Definition: framestats.cc:93
DataGenerator::DataGenerator
DataGenerator(Config *cfg, uint64_t seed=0, Profile profile=Profile::kRandom)
Definition: data_generator.h:32
utils_ldpc.h