Gnuradio C ++块:高CPU

时间:2017-07-10 13:17:56

标签: c++ signal-processing gnuradio

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

我创建了一个没有自定义代码的新块,除了将变量类型设置为float,输入和输出的数量设置为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...

以下是用于测试的流程图: gnuradio flow graph

我修改了构造函数以指定一个输入和一个输出,然后我在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。如果我添加调试消息,我在控制台上看到它们,所以我知道在运行流程图时我的代码更改正在被查看和使用。

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

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

然而,我在解释运行自定义C ++块时的高CPU消耗时却不知所措。

1 个答案:

答案 0 :(得分:1)

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

现在,由于你的块没有检查是否有足够的输入项,所以总是要求它运行 - 因此,燃烧CPU。

我觉得你“意外地”制作了一个通用区块(使用general_work),但意味着要制作一个同步区块(使用work)。