Agora  1.2.0
Agora project
chsim_worker_storage.h
Go to the documentation of this file.
1 
5 #ifndef CHSIM_WORKER_STORAGE_H_
6 #define CHSIM_WORKER_STORAGE_H_
7 
8 #include <cstddef>
9 #include <memory>
10 
11 #include "armadillo"
12 #include "concurrentqueue.h"
13 #include "logger.h"
14 #include "memory_manage.h"
15 #include "message.h"
16 #include "simd_types.h"
17 #include "udp_comm.h"
18 
20  public:
21  ChSimWorkerStorage(size_t tid, size_t ue_ant_count, size_t bs_ant_count,
22  size_t samples_per_symbol, size_t udp_packet_size)
23  : tid_(tid), udp_tx_buffer_(udp_packet_size) {
24  //UE
25  const size_t ue_input_storage_size =
26  (ue_ant_count * samples_per_symbol * sizeof(arma::cx_float));
27  const size_t ue_output_storage_size =
28  (bs_ant_count * samples_per_symbol * sizeof(arma::cx_float));
29 
30  auto* ue_input_float_storage = PaddedAlignedAlloc(
31  Agora_memory::Alignment_t::kAlign64, ue_input_storage_size);
32  ue_input_matrix_ = std::make_unique<arma::cx_fmat>(
33  reinterpret_cast<arma::cx_float*>(ue_input_float_storage),
34  samples_per_symbol, ue_ant_count, false, true);
35  AGORA_LOG_TRACE("Ue input location %zu:%zu diff %zu size %zu\n",
36  reinterpret_cast<intptr_t>(ue_input_matrix_->memptr()),
37  reinterpret_cast<intptr_t>(ue_input_float_storage),
38  reinterpret_cast<intptr_t>(ue_input_matrix_->memptr()) -
39  reinterpret_cast<intptr_t>(ue_input_float_storage),
40  ue_input_storage_size);
41 
42  AGORA_LOG_TRACE("storage %zu:%zu, matrix %zu:%zu memstate %d\n",
43  reinterpret_cast<intptr_t>(ue_input_float_storage),
44  reinterpret_cast<intptr_t>(&reinterpret_cast<std::byte*>(
45  ue_input_float_storage)[ue_input_storage_size - 1]),
46  reinterpret_cast<intptr_t>(&ue_input_matrix_->at(0, 0)),
47  reinterpret_cast<intptr_t>(&ue_input_matrix_->at(
48  samples_per_symbol - 1, ue_ant_count - 1)),
49  ue_input_matrix_->mem_state);
50  //Validate the memory is being reused
51  RtAssert(ue_input_matrix_->memptr() == ue_input_float_storage,
52  "Ue Input storage not at correct location");
53  ue_input_matrix_->zeros(samples_per_symbol, ue_ant_count);
54 
55  auto* ue_output_float_storage = PaddedAlignedAlloc(
56  Agora_memory::Alignment_t::kAlign64, ue_output_storage_size);
57  ue_output_matrix_ = std::make_unique<arma::cx_fmat>(
58  reinterpret_cast<arma::cx_float*>(ue_output_float_storage),
59  samples_per_symbol, bs_ant_count, false, true);
60  RtAssert(ue_output_matrix_->memptr() == ue_output_float_storage,
61  "Ue Input storage not at correct location");
62  ue_output_matrix_->zeros(samples_per_symbol, bs_ant_count);
63 
64  //BS
65  void* bs_input_float_storage = PaddedAlignedAlloc(
66  Agora_memory::Alignment_t::kAlign64, ue_output_storage_size);
67  bs_input_matrix_ = std::make_unique<arma::cx_fmat>(
68  reinterpret_cast<arma::cx_float*>(bs_input_float_storage),
69  samples_per_symbol, bs_ant_count, false, true);
70  RtAssert(bs_input_matrix_->memptr() == bs_input_float_storage,
71  "Bs Input storage not at correct location");
72  bs_input_matrix_->zeros(samples_per_symbol, bs_ant_count);
73 
74  void* bs_output_float_storage = PaddedAlignedAlloc(
75  Agora_memory::Alignment_t::kAlign64, ue_input_storage_size);
76  bs_output_matrix_ = std::make_unique<arma::cx_fmat>(
77  reinterpret_cast<arma::cx_float*>(bs_output_float_storage),
78  samples_per_symbol, ue_ant_count, false, true);
79  RtAssert(bs_output_matrix_->memptr() == bs_output_float_storage,
80  "Bs Output storage not at correct location");
81  bs_output_matrix_->zeros(samples_per_symbol, ue_ant_count);
82  }
84  std::free(ue_input_matrix_->memptr());
85  ue_input_matrix_.reset();
86  std::free(ue_output_matrix_->memptr());
87  ue_output_matrix_.reset();
88  std::free(bs_input_matrix_->memptr());
89  bs_input_matrix_.reset();
90  std::free(bs_output_matrix_->memptr());
91  bs_output_matrix_.reset();
92  };
93 
94  inline size_t Id() const { return tid_; }
95  inline arma::cx_fmat* UeInput() { return ue_input_matrix_.get(); }
96  inline arma::cx_fmat* UeOutput() { return ue_output_matrix_.get(); }
98 
99  inline arma::cx_fmat* BsInput() { return bs_input_matrix_.get(); }
100  inline arma::cx_fmat* BsOutput() { return bs_output_matrix_.get(); }
101 
102  private:
103  size_t tid_;
104  // Aligned
105  std::unique_ptr<arma::cx_fmat> ue_input_matrix_;
106  std::unique_ptr<arma::cx_fmat> ue_output_matrix_;
107 
108  // Aligned
109  std::unique_ptr<arma::cx_fmat> bs_input_matrix_;
110  std::unique_ptr<arma::cx_fmat> bs_output_matrix_;
111 
113 };
114 
116  public:
118  ChSimRxBuffer(ChSimRxType type, const Config* cfg, size_t max_frames,
119  size_t max_symbols, size_t max_antennas,
120  size_t symbol_size_bytes)
121  : type_(type),
122  cfg_(cfg),
123  max_frame_(max_frames),
124  storage_(max_frames, std::vector<std::vector<SimdAlignByteVector>>(
125  max_symbols,
126  std::vector<SimdAlignByteVector>(
127  max_antennas,
128  SimdAlignByteVector(symbol_size_bytes)))) {
129  //Each location accessed by frame / symbol / ant will be aligned at 64
130  }
131 
132  inline void Copy(size_t frame, size_t symbol, size_t ant, const short* input,
133  size_t data_size) {
134  const size_t frame_idx = frame % max_frame_;
135  const size_t symbol_idx = GetSymbolIdx(symbol);
136  auto* dest = storage_.at(frame_idx).at(symbol_idx).at(ant).data();
138  "Adding data %zu:%zu, (Frame %zu:%zu, Symbol %zu:%zu, Ant %zu)\n",
139  data_size, storage_.at(frame_idx).at(symbol_idx).at(ant).size(), frame,
140  frame_idx, symbol, symbol_idx, ant);
141  RtAssert(data_size <= storage_.at(frame_idx).at(symbol_idx).at(ant).size(),
142  "Add data must fit inside of the storage element");
143  //Can make this faster (the destination is 64byte aligned), input is too
144  std::memcpy(dest, input, data_size);
145  }
146 
147  inline const std::byte* Read(size_t frame, size_t symbol, size_t ant) const {
148  const size_t frame_idx = frame % max_frame_;
149  const size_t symbol_idx = GetSymbolIdx(symbol);
150  return storage_.at(frame_idx).at(symbol_idx).at(ant).data();
151  }
152 
153  inline size_t GetSymbolIdx(size_t symbol_id) const {
154  if (type_ == ChSimRxType::kRxTypePilotUl) {
155  return cfg_->GetPilotUlIdx(symbol_id);
156  } else if (type_ == ChSimRxType::kRxTypeBeaconDl) {
157  return cfg_->GetBeaconDlIdx(symbol_id);
158  } else {
159  return SIZE_MAX;
160  }
161  }
162 
163  private:
164  //Need the config for the symbol index functions
166  const Config* const cfg_;
167  const size_t max_frame_;
168  std::vector<std::vector<std::vector<SimdAlignByteVector>>> storage_;
169 };
170 
172  public:
173  ChSimRxStorage(size_t tid, size_t core_id, size_t rx_packet_size,
174  size_t socket_offset, size_t socket_number,
175  std::vector<std::unique_ptr<UDPComm>>* udp_comm,
176  ChSimRxBuffer* rx_output_storage,
178  : tid_(tid),
179  core_id_(core_id),
180  rx_packet_size_(rx_packet_size),
181  socket_offset_(socket_offset),
182  socket_number_(socket_number),
183  comm_(udp_comm),
184  rx_output_(rx_output_storage),
185  response_queue_(response_queue) {}
186 
187  inline size_t Id() const { return tid_; }
188  inline size_t CoreId() const { return core_id_; }
189  inline size_t PacketLength() const { return rx_packet_size_; }
190  inline size_t SocketOffset() const { return socket_offset_; }
191  inline size_t SocketNumber() const { return socket_number_; }
192  inline UDPComm* Socket(size_t id) { return comm_->at(id).get(); }
193  inline void TransferRxData(size_t frame, size_t symbol, size_t ant,
194  const short* input, size_t data_size) {
195  return rx_output_->Copy(frame, symbol, ant, input, data_size);
196  }
198  return *response_queue_;
199  }
200 
201  private:
202  size_t tid_;
203  size_t core_id_;
207 
208  std::vector<std::unique_ptr<UDPComm>>* const comm_;
211 };
212 
213 #endif // CHSIM_WORKER_STORAGE_H_
ChSimRxStorage::tid_
size_t tid_
Definition: chsim_worker_storage.h:202
ChSimRxStorage::ChSimRxStorage
ChSimRxStorage(size_t tid, size_t core_id, size_t rx_packet_size, size_t socket_offset, size_t socket_number, std::vector< std::unique_ptr< UDPComm >> *udp_comm, ChSimRxBuffer *rx_output_storage, moodycamel::ConcurrentQueue< EventData > *response_queue)
Definition: chsim_worker_storage.h:173
ChSimRxStorage::rx_output_
ChSimRxBuffer *const rx_output_
Definition: chsim_worker_storage.h:209
fmt::v8::detail::byte
byte
Definition: core.h:388
udp_comm.h
Declaration file for the UDPComm class. This class is used to send messages and receive messages from...
ChSimRxBuffer::storage_
std::vector< std::vector< std::vector< SimdAlignByteVector > > > storage_
Definition: chsim_worker_storage.h:168
ChSimRxBuffer::ChSimRxType
ChSimRxType
Definition: chsim_worker_storage.h:117
ChSimWorkerStorage::TxBuffer
SimdAlignByteVector & TxBuffer()
Definition: chsim_worker_storage.h:97
ChSimWorkerStorage::~ChSimWorkerStorage
~ChSimWorkerStorage()
Definition: chsim_worker_storage.h:83
fmt::v8::printf
auto printf(const S &fmt, const T &... args) -> int
Definition: printf.h:631
SignalHandler
Definition: signal_handler.h:14
version_config.h
Agora project version configuration file.
ChSimRxBuffer::max_frame_
const size_t max_frame_
Definition: chsim_worker_storage.h:167
UDPComm
Definition: udp_comm.h:18
channel_sim.h
Declaration file for the channel simulator class.
ChSimRxStorage::SocketOffset
size_t SocketOffset() const
Definition: chsim_worker_storage.h:190
ChSimWorkerStorage::ue_output_matrix_
std::unique_ptr< arma::cx_fmat > ue_output_matrix_
Definition: chsim_worker_storage.h:106
ChSimRxBuffer::cfg_
const Config *const cfg_
Definition: chsim_worker_storage.h:166
GetAgoraProjectVersion
const std::string & GetAgoraProjectVersion()
Definition: version_config.h:10
AGORA_LOG_INIT
#define AGORA_LOG_INIT()
Definition: logger.h:35
Agora_memory::PaddedAlignedAlloc
void * PaddedAlignedAlloc(Alignment_t alignment, size_t size)
Definition: memory_manage.cc:15
memory_manage.h
ChSimWorkerStorage::UeOutput
arma::cx_fmat * UeOutput()
Definition: chsim_worker_storage.h:96
ChSimWorkerStorage::BsInput
arma::cx_fmat * BsInput()
Definition: chsim_worker_storage.h:99
TOSTRING
#define TOSTRING(x)
Definition: symbols.h:14
Config::GetBeaconDlIdx
size_t GetBeaconDlIdx(size_t symbol_id) const
Definition: config.h:434
ChSimRxStorage::ResponseQueue
moodycamel::ConcurrentQueue< EventData > & ResponseQueue()
Definition: chsim_worker_storage.h:197
Catch::cerr
std::ostream & cerr()
AGORA_LOG_TRACE
#define AGORA_LOG_TRACE(...)
Definition: logger.h:92
ChSimRxStorage::PacketLength
size_t PacketLength() const
Definition: chsim_worker_storage.h:189
ChSimRxBuffer::ChSimRxBuffer
ChSimRxBuffer(ChSimRxType type, const Config *cfg, size_t max_frames, size_t max_symbols, size_t max_antennas, size_t symbol_size_bytes)
Definition: chsim_worker_storage.h:118
ChSimWorkerStorage::ue_input_matrix_
std::unique_ptr< arma::cx_fmat > ue_input_matrix_
Definition: chsim_worker_storage.h:105
ChSimRxBuffer::Copy
void Copy(size_t frame, size_t symbol, size_t ant, const short *input, size_t data_size)
Definition: chsim_worker_storage.h:132
Config::GetPilotUlIdx
size_t GetPilotUlIdx(size_t symbol_id) const
Definition: config.h:449
ChSimRxStorage::core_id_
size_t core_id_
Definition: chsim_worker_storage.h:203
ChSimRxStorage::CoreId
size_t CoreId() const
Definition: chsim_worker_storage.h:188
simd_types.h
Aligned types for SIMD compatibility.
message.h
Self defined functions for message storage and passing.
ChSimWorkerStorage::ChSimWorkerStorage
ChSimWorkerStorage(size_t tid, size_t ue_ant_count, size_t bs_ant_count, size_t samples_per_symbol, size_t udp_packet_size)
Definition: chsim_worker_storage.h:21
ChSimWorkerStorage::BsOutput
arma::cx_fmat * BsOutput()
Definition: chsim_worker_storage.h:100
ChSimRxBuffer
Definition: chsim_worker_storage.h:115
ChSimRxBuffer::GetSymbolIdx
size_t GetSymbolIdx(size_t symbol_id) const
Definition: chsim_worker_storage.h:153
ChSimRxStorage::Id
size_t Id() const
Definition: chsim_worker_storage.h:187
ChSimRxStorage::socket_offset_
size_t socket_offset_
Definition: chsim_worker_storage.h:205
main
int main(int argc, char *argv[])
Definition: chsim_main.cc:27
ChSimRxStorage
Definition: chsim_worker_storage.h:171
ChSimRxStorage::TransferRxData
void TransferRxData(size_t frame, size_t symbol, size_t ant, const short *input, size_t data_size)
Definition: chsim_worker_storage.h:193
ChSimRxStorage::Socket
UDPComm * Socket(size_t id)
Definition: chsim_worker_storage.h:192
Agora_memory::Alignment_t::kAlign64
@ kAlign64
ChSimWorkerStorage
Definition: chsim_worker_storage.h:19
ChSimRxStorage::response_queue_
moodycamel::ConcurrentQueue< EventData > *const response_queue_
Definition: chsim_worker_storage.h:210
ChSimWorkerStorage::bs_output_matrix_
std::unique_ptr< arma::cx_fmat > bs_output_matrix_
Definition: chsim_worker_storage.h:110
ChSimRxStorage::socket_number_
size_t socket_number_
Definition: chsim_worker_storage.h:206
ChSimRxBuffer::type_
const ChSimRxType type_
Definition: chsim_worker_storage.h:165
ChSimWorkerStorage::UeInput
arma::cx_fmat * UeInput()
Definition: chsim_worker_storage.h:95
ChSimRxStorage::comm_
std::vector< std::unique_ptr< UDPComm > > *const comm_
Definition: chsim_worker_storage.h:208
SimdAlignByteVector
std::vector< std::byte, boost::alignment::aligned_allocator< std::byte, kSimdAlignment > > SimdAlignByteVector
Definition: simd_types.h:18
ChSimWorkerStorage::udp_tx_buffer_
SimdAlignByteVector udp_tx_buffer_
Definition: chsim_worker_storage.h:112
data_size
data_size
Definition: inspect_agora_results.m:16
moodycamel::ConcurrentQueue< EventData >
DEFINE_string
DEFINE_string(conf_file, TOSTRING(PROJECT_DIRECTORY) "/files/config/ci/tddconfig-sim-both.json", "Config filename")
ChSimRxBuffer::kRxTypeBeaconDl
@ kRxTypeBeaconDl
Definition: chsim_worker_storage.h:117
Config
Definition: config.h:26
DEFINE_double
DEFINE_double(chan_snr, 20.0, "Signal-to-Noise Ratio")
ChSimRxBuffer::kRxTypePilotUl
@ kRxTypePilotUl
Definition: chsim_worker_storage.h:117
std
Definition: json.hpp:5213
RtAssert
static void RtAssert(bool condition, const char *throw_str)
Definition: utils.h:104
AGORA_LOG_SHUTDOWN
#define AGORA_LOG_SHUTDOWN()
Definition: logger.h:36
PrintCoreAssignmentSummary
void PrintCoreAssignmentSummary()
Definition: utils.cc:85
ChSimWorkerStorage::tid_
size_t tid_
Definition: chsim_worker_storage.h:103
DEFINE_uint64
DEFINE_uint64(bs_threads, 1, "Number of threads for handling reception of BS packets")
ChSimRxStorage::rx_packet_size_
size_t rx_packet_size_
Definition: chsim_worker_storage.h:204
SignalHandler::SetupSignalHandlers
void SetupSignalHandlers()
Definition: signal_handler.cc:44
ChSimWorkerStorage::bs_input_matrix_
std::unique_ptr< arma::cx_fmat > bs_input_matrix_
Definition: chsim_worker_storage.h:109
SignalException
Definition: signal_handler.h:8
ChSimRxBuffer::Read
const std::byte * Read(size_t frame, size_t symbol, size_t ant) const
Definition: chsim_worker_storage.h:147
concurrentqueue.h
ChSimWorkerStorage::Id
size_t Id() const
Definition: chsim_worker_storage.h:94
fmt::v8::detail::type
type
Definition: core.h:1131
ChSimRxStorage::SocketNumber
size_t SocketNumber() const
Definition: chsim_worker_storage.h:191