【发布时间】: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