|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright 2021-2024 Software Radio Systems Limited |
| 4 | + * |
| 5 | + * This file is part of srsRAN. |
| 6 | + * |
| 7 | + * srsRAN is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as |
| 9 | + * published by the Free Software Foundation, either version 3 of |
| 10 | + * the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * srsRAN is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * A copy of the GNU Affero General Public License can be found in |
| 18 | + * the LICENSE file in the top-level directory of this distribution |
| 19 | + * and at http://www.gnu.org/licenses/. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +#include "du_low_hal_factory.h" |
| 24 | +#include "srsran/ran/sch/sch_constants.h" |
| 25 | +#ifdef DPDK_FOUND |
| 26 | +#include "srsran/hal/dpdk/bbdev/bbdev_acc_factory.h" |
| 27 | +#include "srsran/hal/phy/upper/channel_processors/hw_accelerator_factories.h" |
| 28 | +#include "srsran/hal/phy/upper/channel_processors/pusch/ext_harq_buffer_context_repository_factory.h" |
| 29 | +#include "srsran/hal/phy/upper/channel_processors/pusch/hw_accelerator_factories.h" |
| 30 | +#endif // DPDK_FOUND |
| 31 | + |
| 32 | +using namespace srsran; |
| 33 | + |
| 34 | +#ifdef DPDK_FOUND |
| 35 | +std::shared_ptr<dpdk::bbdev_acc> |
| 36 | +srsran::init_bbdev_hwacc(const bbdev_appconfig& bbdev_app_cfg, srslog::basic_logger& logger, unsigned nof_hwacc_dus) |
| 37 | +{ |
| 38 | + // Initialize the bbdev-based hardware accelerator, if required. |
| 39 | + static std::shared_ptr<dpdk::bbdev_acc> bbdev_accelerator = [bbdev_app_cfg, &logger, nof_hwacc_dus]() { |
| 40 | + // Intefacing to the bbdev-based hardware-accelerator. |
| 41 | + dpdk::bbdev_acc_configuration bbdev_config; |
| 42 | + bbdev_config.id = bbdev_app_cfg.id; |
| 43 | + if (bbdev_app_cfg.pdsch_enc && bbdev_app_cfg.pdsch_enc->nof_hwacc > 0) { |
| 44 | + bbdev_config.nof_ldpc_enc_lcores = nof_hwacc_dus * bbdev_app_cfg.pdsch_enc->nof_hwacc; |
| 45 | + } |
| 46 | + if (bbdev_app_cfg.pusch_dec && bbdev_app_cfg.pusch_dec->nof_hwacc > 0) { |
| 47 | + bbdev_config.nof_ldpc_dec_lcores = nof_hwacc_dus * bbdev_app_cfg.pusch_dec->nof_hwacc; |
| 48 | + } |
| 49 | + // If no msg_mbuf size is defined, a worst-case value will be used. |
| 50 | + bbdev_config.msg_mbuf_size = bbdev_app_cfg.msg_mbuf_size.value_or(RTE_BBDEV_LDPC_E_MAX_MBUF); |
| 51 | + // If no rm_mbuf size is defined, a worst-case value will be used. |
| 52 | + bbdev_config.rm_mbuf_size = bbdev_app_cfg.rm_mbuf_size.value_or(RTE_BBDEV_LDPC_E_MAX_MBUF); |
| 53 | + // If no number of mbufs is defined, a worst-case value will be used. |
| 54 | + bbdev_config.nof_mbuf = bbdev_app_cfg.nof_mbuf.value_or(static_cast<unsigned>(pow2(log2_ceil(MAX_NOF_SEGMENTS)))); |
| 55 | + std::shared_ptr<dpdk::bbdev_acc> bbdev_acc = create_bbdev_acc(bbdev_config, logger); |
| 56 | + report_error_if_not(bbdev_acc, "Unable to open the {} hardware-accelerator.", bbdev_app_cfg.hwacc_type); |
| 57 | + return bbdev_acc; |
| 58 | + }(); |
| 59 | + |
| 60 | + return bbdev_accelerator; |
| 61 | +} |
| 62 | +#endif // DPDK_FOUND |
| 63 | + |
| 64 | +o_du_low_hal_dependencies srsran::make_du_low_hal_dependencies(const du_low_unit_config& du_low_unit_cfg, |
| 65 | + unsigned nof_cells) |
| 66 | +{ |
| 67 | + o_du_low_hal_dependencies hal_dependencies; |
| 68 | + |
| 69 | + // Initialize hardware-accelerator (only once and if needed). |
| 70 | +#ifdef DPDK_FOUND |
| 71 | + if (du_low_unit_cfg.hal_config && du_low_unit_cfg.hal_config->bbdev_hwacc && |
| 72 | + !du_low_unit_cfg.hal_config->bbdev_hwacc->hwacc_type.empty()) { |
| 73 | + const bbdev_appconfig& bbdev_app_cfg = du_low_unit_cfg.hal_config->bbdev_hwacc.value(); |
| 74 | + srslog::basic_logger& hwacc_logger = srslog::fetch_basic_logger("HWACC", false); |
| 75 | + hwacc_logger.set_level(du_low_unit_cfg.loggers.hal_level); |
| 76 | + |
| 77 | + // Create a hardware-accelerated PDSCH encoder factory (only if needed). |
| 78 | + if (bbdev_app_cfg.pdsch_enc && bbdev_app_cfg.pdsch_enc->nof_hwacc > 0) { |
| 79 | + hal::bbdev_hwacc_pdsch_enc_factory_configuration hwacc_pdsch_enc_cfg; |
| 80 | + hwacc_pdsch_enc_cfg.acc_type = bbdev_app_cfg.hwacc_type; |
| 81 | + hwacc_pdsch_enc_cfg.bbdev_accelerator = init_bbdev_hwacc(bbdev_app_cfg, hwacc_logger, nof_cells); |
| 82 | + hwacc_pdsch_enc_cfg.cb_mode = bbdev_app_cfg.pdsch_enc->cb_mode; |
| 83 | + // If no maximum buffer size is defined, a worst-case value will be used. |
| 84 | + hwacc_pdsch_enc_cfg.max_tb_size = bbdev_app_cfg.pdsch_enc->max_buffer_size.value_or(RTE_BBDEV_LDPC_E_MAX_MBUF); |
| 85 | + hwacc_pdsch_enc_cfg.dedicated_queue = bbdev_app_cfg.pdsch_enc->dedicated_queue; |
| 86 | + hal_dependencies.hw_encoder_factory = hal::create_bbdev_pdsch_enc_acc_factory(hwacc_pdsch_enc_cfg); |
| 87 | + } |
| 88 | + |
| 89 | + // // Create a hardware-accelerated PUSCH decoder factory (only if needed). |
| 90 | + if (bbdev_app_cfg.pusch_dec && bbdev_app_cfg.pusch_dec->nof_hwacc > 0) { |
| 91 | + hal::bbdev_hwacc_pusch_dec_factory_configuration hwacc_pusch_dec_cfg; |
| 92 | + std::shared_ptr<hal::ext_harq_buffer_context_repository> harq_buffer_context = nullptr; |
| 93 | + hwacc_pusch_dec_cfg.acc_type = bbdev_app_cfg.hwacc_type; |
| 94 | + hwacc_pusch_dec_cfg.bbdev_accelerator = init_bbdev_hwacc(bbdev_app_cfg, hwacc_logger, nof_cells); |
| 95 | + hwacc_pusch_dec_cfg.ext_softbuffer = bbdev_app_cfg.pusch_dec->ext_softbuffer; |
| 96 | + if (hwacc_pusch_dec_cfg.ext_softbuffer) { |
| 97 | + // Set up an external HARQ buffer context repository. |
| 98 | + unsigned nof_cbs = bbdev_app_cfg.pusch_dec->harq_context_size.value_or(MAX_NOF_SEGMENTS); |
| 99 | + uint64_t ext_harq_buff_size = hwacc_pusch_dec_cfg.bbdev_accelerator->get_harq_buff_size_bytes(); |
| 100 | + harq_buffer_context = hal::create_ext_harq_buffer_context_repository(nof_cbs, ext_harq_buff_size, false); |
| 101 | + report_error_if_not(harq_buffer_context, |
| 102 | + "Unable to create the external HARQ buffer context for the {} hardware-accelerator.", |
| 103 | + bbdev_app_cfg.hwacc_type); |
| 104 | + hwacc_pusch_dec_cfg.harq_buffer_context = harq_buffer_context; |
| 105 | + } |
| 106 | + hwacc_pusch_dec_cfg.dedicated_queue = bbdev_app_cfg.pusch_dec->dedicated_queue; |
| 107 | + hal_dependencies.hw_decoder_factory = hal::create_bbdev_pusch_dec_acc_factory(hwacc_pusch_dec_cfg); |
| 108 | + } |
| 109 | + } |
| 110 | +#endif // DPDK_FOUND |
| 111 | + |
| 112 | + return hal_dependencies; |
| 113 | +} |
0 commit comments