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

MKL FFT

Darius_Nicholas
New Contributor I
1,142 Views

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 Kudos
1 Solution
VarshaS_Intel
Moderator
811 Views

Hi,


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


Thanks & Regards,

Varsha


View solution in original post

0 Kudos
6 Replies
VarshaS_Intel
Moderator
1,109 Views

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

 

 

 

0 Kudos
Darius_Nicholas
New Contributor I
1,080 Views

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;

}

 

0 Kudos
Darius_Nicholas
New Contributor I
1,058 Views

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

 

 

0 Kudos
VarshaS_Intel
Moderator
961 Views

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

 

0 Kudos
VarshaS_Intel
Moderator
867 Views

Hi,


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


Thanks & Regards,

Varsha


0 Kudos
VarshaS_Intel
Moderator
812 Views

Hi,


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


Thanks & Regards,

Varsha


0 Kudos
Reply