gpt4 book ai didi

c++ - "Segmentation fault"在linux上实现intel MKL的DFT

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:32:29 25 4
gpt4 key购买 nike

我正在尝试实现 INTEL MKL 的 dft api 以测试其在 CentOS 7 上的速度。编译成功但在运行时出现段错误。但是,代码已经在 Windows 上使用 Visual Studio 2017 成功运行。 Windows 上的结果是这样的:result on windows

#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
#include <cxxabi.h>
#include <omp.h>
#include <complex>
#include "mkl_dfti.h"

int main() {
MKL_LONG len[2] = { 1080, 961 }, status;
float x_in[1080][1920];
DFTI_DESCRIPTOR_HANDLE fft;
status = DftiCreateDescriptor(&fft, DFTI_SINGLE, DFTI_REAL, 2, len);
status = DftiSetValue(fft, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
status = DftiCommitDescriptor(fft);

//float x[1080* 2000];
std::complex<float> x_out[1080][961];
for (int i = 0; i < 10; i++) {
double totalcputime = (double)cv::getTickCount();
//std::cout << status << std::endl;
status = DftiComputeForward(fft, x_in, x_out);
//std::cout << status << std::endl;
totalcputime = ((double)cv::getTickCount() - totalcputime) / cv::getTickFrequency();
std::cout << "MKL-DFT Time: " << totalcputime << std::endl;
}
cv::Mat sizedimage = cv::Mat::zeros(1080, 1920, CV_32FC1);
cv::Mat opencvtransform = cv::Mat(1080, 1920 / 2 + 1, CV_32FC1);
for (int i = 0; i < 10; i++) {
double totalcputime = (double)cv::getTickCount();
cv::dft(sizedimage, opencvtransform);
totalcputime = ((double)cv::getTickCount() - totalcputime) / cv::getTickFrequency();
std::cout << "opencv-DFT Time: " << totalcputime << std::endl;
}

return 0;
}

我已经使用 GDB 调试了我的代码,它为我提供了以下信息:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004012b8 in main () at comparison.cpp:25
25 status = DftiCreateDescriptor(&fft, DFTI_SINGLE, DFTI_REAL, 2, len);

文件通过以下参数编译成功:

g++ comparison.cpp `pkg-config opencv --cflags --libs` -lmkl_rt -g

有人知道这个错误的原因吗?

最佳答案

你能检查一下 MKL 2019 u4 的问题吗?

我稍微重新设计了您的代码,通过删除 opencv 条目和动态分配输入/输出数组来检查最新的 mkl 2019 是否存在问题

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
//#include <execinfo.h>
//#include <cxxabi.h>
#include <assert.h>
#include <omp.h>
#include <complex>
#include "mkl.h"

#define N1 1080
#define N2 961
#define N3 1920

int main()
{
// MKL_LONG len[2] = { 1080, 961 }, status;
MKL_LONG status;
MKL_LONG len[2];
len[0] = N1;
len[1] = N2;

//float x_in[1080][1920];
float* x_in = (float*)mkl_malloc(N1*N3*sizeof(float), 64);
assert(NULL != x_in);

DFTI_DESCRIPTOR_HANDLE fft;
status = DftiCreateDescriptor(&fft, DFTI_SINGLE, DFTI_REAL, 2, len);
if (0 != status){
std::cout << "\t DftiCreateDescriptor Error : " << status << std::endl;
}
status = DftiSetValue(fft, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
if (0 != status){
std::cout << "\t DftiSetValue Error : " << status << std::endl;
}
status = DftiCommitDescriptor(fft);
if (0 != status){
std::cout << "\t DftiCommitDescriptor Error : " << status << std::endl;
}

double t1,texec;
// std::complex<float> x_out[1080][961];
MKL_Complex8* x_out = (MKL_Complex8*)mkl_malloc(N1*N2*sizeof(MKL_Complex8), 64);

t1 = dsecnd();
for (int i = 0; i < 10; i++) {

t1 = dsecnd();
status = DftiComputeForward(fft, x_in, x_out);
if (0 != status){std::cout << "\t DftiComputeForward Error : " << status << std::endl;}
texec = dsecnd() - t1;
std::cout << "MKL-DFT Time: " << texec << std::endl;
}

status = DftiFreeDescriptor(&fft);
if (0 != status){
std::cout << "\t DftiFreeDescriptor Error : " << status << std::endl;
}

return 0;
}

这是我看到的输出:

]$ ./a.out
MKL-DFT Time: 0.00725237
MKL-DFT Time: 0.00381843
MKL-DFT Time: 0.00362679
MKL-DFT Time: 0.0021284
MKL-DFT Time: 0.00221884
MKL-DFT Time: 0.00215556
MKL-DFT Time: 0.00211133
MKL-DFT Time: 0.002133
MKL-DFT Time: 0.00212184
MKL-DFT Time: 0.00215306

关于c++ - "Segmentation fault"在linux上实现intel MKL的DFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55646303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com