Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

MKL FFT

Darius_Nicholas
新貢獻者 I
3,354 檢視

I have used the MKL library to run the FFT algorithm on the CPU. How should I run it on the GPU? I have tried many times and failed. Can you give me an example of running the FFT algorithm on a GPU using the MKL library? Thanks! I use DPC++.

0 積分
1 解決方案
VarshaS_Intel
主席
3,023 檢視

Hi,


We have not heard back from you. Could you please provide us with an update on your issue?


Thanks & Regards,

Varsha


在原始文章中檢視解決方案

6 回應
VarshaS_Intel
主席
3,321 檢視

Hi,

 

Thanks for posting in Intel Communities.

 

Could you please let us know the OS details, and Intel MKL version you are using?

 

Could you please let us know and provide us with the sample reproducer code you are trying to run the FFT algorithm on the CPU?

 

When we tried sample example codes(/dpcpp/dft/source/1dp_complex_1d.cpp) of MKL on a Linux machine, we are able to run the code on CPU as well as GPU, please find the below screenshot and commands for more details:

 

 

Compilation:  icpx -fsycl -DMKL_ILP64 -DSYCL_DEVICES_gpu -I"${MKLROOT}/include" -I"/home/u 119712/varsha/mkl/dpcpp/common" dp_complex_1d.cpp -fsycl -fsycl-device-code-split=per_kernel ${MKLROOT}/lib/intel64/libmkl_s ycl.a -Wl,-export-dynamic -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_sequentia l.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lsycl -lOpenCL -lpthread -lm -ldl

Running: ./a.out

 

 

VarshaS_Intel_0-1702407647894.pngVarshaS_Intel_1-1702407703755.png

 

You can also use Intel Link Line Advisor for exact compiling and linking the code. Please find the below link for more details:

https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

 

Thanks & Regards,

Varsha

 

 

 

Darius_Nicholas
新貢獻者 I
3,292 檢視

OS:Windows 11

MKL version: OneMKL 2023

 

My Sample on CPU:

#include <iostream>
#include <vector>
#include <chrono>
#include <mkl.h>
#include <CL/sycl.hpp>
#include <oneapi/mkl/dfti.hpp>

using namespace cl::sycl;

void runFFTOnCPU(const std::vector<std::complex<float>>& input, std::vector<std::complex<float>>& output) {
// Perform FFT on CPU using MKL
DFTI_DESCRIPTOR_HANDLE descriptor;
DftiCreateDescriptor(&descriptor, DFTI_SINGLE, DFTI_COMPLEX, 1, input.size());
DftiSetValue(descriptor, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
DftiCommitDescriptor(descriptor);
const float* input_real = reinterpret_cast<const float*>(input.data()); // Use const_cast instead of reinterpret_cast
float* output_real = reinterpret_cast<float*>(output.data());

DftiComputeForward(descriptor, const_cast<float*>(input_real), output_real);

DftiFreeDescriptor(&descriptor);
}

int main() {
const int size = 8192; // Adjust the size as needed
std::vector<std::complex<float>> input(size, { 1.0f, 0.0f });
std::vector<std::complex<float>> output(size);

// Measure CPU execution time
auto start_cpu = std::chrono::high_resolution_clock::now();
runFFTOnCPU(input, output);
auto end_cpu = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> cpu_duration = end_cpu - start_cpu;

std::cout << "CPU FFT Time: " << cpu_duration.count() << " seconds" << std::endl;

return 0;

}

 

Darius_Nicholas
新貢獻者 I
3,270 檢視

I tried to run this sample on Visual Studio, but failed! The failure situation is as shown below! Could you please help me see how to modify it?

Darius_Nicholas_1-1702523488988.png

This is my include directory and library directory.

Darius_Nicholas_2-1702523571950.png

Can this sample only be run on Visual Studio Code?

OS:Windows 11

MKL version:2023

 

 

VarshaS_Intel
主席
3,173 檢視

Hi,

 

Thanks for your reply.

 

When we tried using the MKL Sample code "cl_solver_export_c.c" on Visual Studio. Could you please find the attached zip file where we are able to run successfully and could you please let us know if you are getting any errors?

 

Thanks & Regards,

Varsha

 

VarshaS_Intel
主席
3,079 檢視

Hi,


We have not heard back from you. Could you please provide us with an update on your issue?


Thanks & Regards,

Varsha


VarshaS_Intel
主席
3,024 檢視

Hi,


We have not heard back from you. Could you please provide us with an update on your issue?


Thanks & Regards,

Varsha


回覆