简体   繁体   中英

Write a mex-File from Matlab to CUDA (CUSPARSE)

I use the sparse Martix format in Matlab to store my Matrix. But the computation will the cusparse libary do. I search for a example to connect matlab und Cusparse via a mex File.

Have anyone an idea ?

Thanks Christian

If I understand your question, I had a similar problem that I just figured out how to solve. I wanted to write program in C that uses CUSPARSE, compile that into a mex file, and run that in MATLAB. Here are some sources that I found that helped me out.

The MATLAB documentation has some examples for what your C program should look like.

Here's the MATLAB documentation on how to set up and compile your program. Note that you have to set the path to NVCC before you can compile your code. I could never get it to work this way though.

I chose to compile the code outside of MATLAB, and I just compile the mex file with the line

mex myFile.cu -L/path/to/your/cuda/libs -lcusparse -lcudart

And that worked for me. Note that the MATLAB documentation says that your C file has to have the ".cu" suffix for this to compile properly, as well as setting the "MW_NVCC_PATH" environment variable to point to nvcc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM