【问题标题】:Gnuradio C++ block: high CPUGnuradio C++ 块:高 CPU
【发布时间】:2017-12-14 06:01:55
【问题描述】:

我已经创建了一个 python Gnuradio 块,现在我正在用 C++ 对其进行重新编码。我注意到一些非常出乎意料的事情——C++ 块(python 流程图进程)比执行相同操作的 Python 版本(18%)消耗更多的 CPU(~125%)。我一定是做错了什么......所以 -

我创建了一个没有自定义代码的新块,只是将变量类型设置为浮点数,输入和输出数设置为 1,我看到了相同的行为。我一定是做错了什么,但我不知道是什么……

$ gnuradio-config-info -v
3.7.11

Platform: Mac / x86_64

这是我在现有模块中创建块的方式:

$ gr_modtool add -t general donothingcpp
GNU Radio module name identified: acsound
Language (python/cpp): cpp
Language: C++
Block/code identifier: donothingcpp
Enter valid argument list, including default arguments: 
Add Python QA code? [Y/n] n
Add C++ QA code? [Y/n] n
Adding file 'lib/donothingcpp_impl.h'...
Adding file 'lib/donothingcpp_impl.cc'...
Adding file 'include/acsound/donothingcpp.h'...
Editing swig/acsound_swig.i...
Adding file 'grc/acsound_donothingcpp.xml'...
Editing grc/CMakeLists.txt...

这是用于测试的流程图:

我修改了构造函数以指定一个输入和一个输出,然后我调整了 general_work 函数中的变量类型,现在看起来像这样:

int
donothingcpp_impl::general_work (int noutput_items,
                   gr_vector_int &ninput_items,
                   gr_vector_const_void_star &input_items,
                   gr_vector_void_star &output_items)
{
  const float *in = (const float *) input_items[0];
  float *out = (float *) output_items[0];

  // Do <+signal processing+>
  // Tell runtime system how many input items we consumed on
  // each input stream.
  consume_each (noutput_items);

  // Tell runtime system how many output items we produced.
  return noutput_items;
}

无论我是否在 general_work 函数中进行任何工作,该进程的 CPU 消耗大约为 125%。当然,每次更改代码时,我都会进行 clean、make 和 make install 以将块放入 gnuradio。如果我添加调试消息,我会在控制台上看到它们,因此我知道我的代码更改在我运行流程图时会被看到和使用。

如果我绕过 donthing 块并运行流程图,它会消耗 0.3% 的 CPU。

我尝试了空信号接收器和探测信号接收器,但似乎都不是一个因素。

但是,当我运行自定义 C++ 块时,我无法解释高 CPU 消耗。

【问题讨论】:

    标签: c++ signal-processing gnuradio


    【解决方案1】:

    您正在消耗输出样本的数量,但在一般情况下这是错误的(在同步块情况下是正确的,输出项的数量始终与消耗的输入项的数量相同)。

    现在,由于您的块不检查是否有足够的输入项,它总是被要求运行 - 因此,CPU 的烧毁。

    我觉得你“不小心”做了一个通用块(general_work),但打算做一个同步块(work)。

    【讨论】:

    • 工作就像一个魅力,谢谢。我必须使用-t sync 创建块并将我的信号处理逻辑放在work() 函数中,如你所说。新块 CPU 使用率约为 0.0x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2019-11-06
    • 1970-01-01
    • 2019-02-24
    • 2010-12-06
    相关资源
    最近更新 更多