Skip to content

Commit cdd5c3c

Browse files
xavierarteagacodebot
authored andcommitted
phy: redduce EVM calculator memory footprint
1 parent 8e2fdbf commit cdd5c3c

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

lib/phy/upper/channel_modulation/evm_calculator_generic_impl.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,42 @@ float evm_calculator_generic_impl::calculate(span<const log_likelihood_ratio> so
1919
span<const cf_t> symbols,
2020
modulation_scheme modulation)
2121
{
22-
// Perform hard-decision.
23-
bit_buffer hard_bits = temp_hard_bits.first(soft_bits.size());
24-
hard_decision(hard_bits, soft_bits);
22+
// Get modulation order.
23+
unsigned bits_per_symbol = get_bits_per_symbol(modulation);
2524

26-
// Modulate.
27-
span<cf_t> modulated = temp_modulated.first(symbols.size());
28-
modulator->modulate(modulated, hard_bits, modulation);
25+
// Verify that soft bits and symbols dimensions are consistent.
26+
srsran_assert(soft_bits.size() == symbols.size() * bits_per_symbol,
27+
"The number of soft bits (i.e., {}) is not consistent with the number of symbols (i.e., {}) and "
28+
"modulation (i.e., {}).",
29+
soft_bits.size(),
30+
symbols.size(),
31+
to_string(modulation));
2932

30-
// Calculate EVM.
31-
srsvec::subtract(modulated, symbols, modulated);
32-
return std::sqrt(srsvec::average_power(modulated));
33+
unsigned nof_symbols = symbols.size();
34+
float avg_power = 0.0;
35+
36+
while (!soft_bits.empty()) {
37+
unsigned block_nof_symbols = std::min(static_cast<unsigned>(symbols.size()), MAX_NOF_SYMBOLS);
38+
unsigned block_nof_bits = block_nof_symbols * bits_per_symbol;
39+
40+
// Perform hard-decision.
41+
bit_buffer hard_bits = temp_hard_bits.first(block_nof_bits);
42+
hard_decision(hard_bits, soft_bits.first(block_nof_bits));
43+
44+
// Modulate.
45+
span<cf_t> modulated = temp_modulated.first(block_nof_symbols);
46+
modulator->modulate(modulated, hard_bits, modulation);
47+
48+
// Calculate EVM.
49+
srsvec::subtract(modulated, symbols.first(block_nof_symbols), modulated);
50+
51+
// Accumulate power.
52+
avg_power += std::real(srsvec::dot_prod(modulated, modulated));
53+
54+
// Pop bits and symbols.
55+
symbols = symbols.last(symbols.size() - block_nof_symbols);
56+
soft_bits = soft_bits.last(soft_bits.size() - block_nof_bits);
57+
}
58+
59+
return std::sqrt(avg_power / static_cast<float>(nof_symbols));
3360
}

lib/phy/upper/channel_modulation/evm_calculator_generic_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class evm_calculator_generic_impl : public evm_calculator
3434

3535
private:
3636
/// Maximum number of symbols assuming 156 RE/RB, 275 RB and 4 layers.
37-
static constexpr unsigned MAX_NOF_SYMBOLS = 156 * 275 * 4;
37+
static constexpr unsigned MAX_NOF_SYMBOLS = 4096;
3838
/// Maximum number of bits.
3939
static constexpr unsigned MAX_NOF_BITS = MAX_NOF_SYMBOLS * 8;
4040
/// Internal modulator.

0 commit comments

Comments
 (0)