我想在两个使用eigen3库的640x512矩阵之间做出区别,我的计算延迟很高(英特尔Xeon 16核上的45 ms @ 2.4GHz)。我可以问你一些改善这个异常计算时间的提示吗?下面是相关的代码片段:
static inline void tsnorm(stTime *ts)
{
while (ts->tv_nsec >= NSEC_PER_SEC)
{
ts->tv_nsec -= NSEC_PER_SEC;
ts->tv_sec++;
}
}
const unsigned short usRawFrameRows = 640;
const unsigned short usRawFrameCols = 512;
using pixType = unsigned short;
using pixDynMat = Matrix<pixType, Dynamic, Dynamic, RowMajor>;
pixDynMat biasFrame = pixDynMat::Zero(usRawFrameRows, usRawFrameCols);
pixType *myRawFrame = new pixType[usRawFrameRows * usRawFrameCols];
struct timespec tBeforeProcessFrameCall, tAfterProcessFrameCall;
clock_gettime(CLOCK_MONOTONIC_RAW, &tBeforeProcessFrameCall);
tsnorm(&tBeforeProcessFrameCall);
// Substract the bias from the current raw frame
MatrixXd calFrame = Map<pixDynMat>(myRawFrame, usRawFrameRows, usRawFrameCols).cast<double>()
- biasFrame.cast<double>();
clock_gettime(CLOCK_MONOTONIC_RAW, &tAfterProcessFrameCall);
tsnorm(&tAfterProcessFrameCall);
cout << " PHI processFrame overhead (ms) = " << (tAfterProcessFrameCall.tv_nsec - tBeforeProcessFrameCall.tv_nsec)/1e6 << endl;干杯!
西尔万
发布于 2020-08-16 13:34:46
我已经编译了你的代码(I7-9700 K):
Compiler: g++ -O3 -march=native test.cpp -o testbin
====================================================
PHI processFrame overhead (ms) = 0.952253但是,没有优化:
Compiler: g++ test.cpp -o testbin
====================================================
PHI processFrame overhead (ms) = 20.1365我怀疑您缺少编译器优化。您可以尝试在启用优化的情况下进行编译。根据FAQ页面,这可以很容易地获得十倍或更多的因素(参见http://eigen.tuxfamily.org/index.php?title=FAQ#Optimization)。
https://stackoverflow.com/questions/63338047
复制相似问题