简体   繁体   English

在Matlab2014a中用MEX编译CUDA的问题

[英]Problems compiling CUDA with MEX in Matlab2014a

I am trying to compile a CUDA program using MEX within Matlab2014a and can't get it to work. 我正在尝试使用Matlab2014a中的MEX编译CUDA程序,但无法使其工作。 I installed the newest CUDA toolbox (6.5) and driver (340.62) and the samples work correctly, so I guess it is correctly installed. 我安装了最新的CUDA工具箱(6.5)和驱动程序(340.62)并且示例正常工作,所以我猜它已正确安装。

I also installed MS Visual Studio 2012 Professional and Matlab 2014a. 我还安装了MS Visual Studio 2012 Professional和Matlab 2014a。

I followed the exact description in the Matlab Help in "GPU Computing -> Examples and How To -> Run MEX-Functions Containing CUDA Code". 我遵循Matlab帮助中的“GPU计算 - >示例和如何 - >运行包含CUDA代码的MEX函数”中的确切描述。 My CUDA file ends with .cu (so I am trying to compile Matlab's standard example mexGPUExample.cu, but I get the same error with other .cu files), the mex_CUDA_win64.xml is in the same folder, the environment variable MW_NVCC_PATH is set correctly in the user variables and just to be sure I also called "setenv('MW_NVCC_PATH,...)" in Matlab. 我的CUDA文件以.cu结尾(所以我试图编译Matlab的标准示例mexGPUExample.cu,但我得到与其他.cu文件相同的错误),mex_CUDA_win64.xml在同一个文件夹中,环境变量MW_NVCC_PATH被设置正确地在用户变量中,并且确保我在Matlab中也称为“setenv('MW_NVCC_PATH,...)”。

If I try to compile a CUDA example with 如果我尝试编译一个CUDA示例

mex -largeArrayDims mexGPUExample.cu

I get the following error: 我收到以下错误:

cl : Command line warning D9024 : unrecognized source file type 'mexGPUExample.cu', object file assumed 
cl : Command line warning D9027 : source file 'mexGPUExample.cu' ignored 
cl : Command line warning D9021 : no action performed 

D:\PROGRAMS\MATLAB~1\BIN\MEX.PL: Error: Compile of 'mexGPUExample.cu' failed. 

Unable to complete successfully.

I also tried to set the compiler correctly using 我还尝试使用正确设置编译器

mex -setup

and chose the MS Visual Studio Compiler. 并选择了MS Visual Studio编译器。

The code itself works because I tested it on other systems. 代码本身有效,因为我在其他系统上测试过。

I have no idea what I am doing wrong. 我不知道我做错了什么。 Any help is appreciated. 任何帮助表示赞赏。

Matlab only supports CUDA 5.5 on R2014a, so your CUDA 6.5 by default cannot compile mex files under Matlab. Matlab仅在R2014a上支持CUDA 5.5,因此默认情况下你的CUDA 6.5无法在Matlab下编译mex文件。 Matlab R2014a supports VS 2012 now, but you need to verify you have VS 64-bit compiler if your Matlab is 64-bit. Matlab R2014a现在支持VS 2012,但如果您的Matlab是64位,则需要验证您是否具有VS 64位编译器。 You can compile a normal .mex file with .cpp source file, (lots of these files under matlabroot/extern folder) to see whether Matlab works well with your VS. 您可以使用.cpp源文件编译一个普通的.mex文件(在matlabroot / extern文件夹下有很多这些文件),看看Matlab是否适合您的VS.

Note that Matlab has a lag in supporting the latest compilers, both VS/gcc and Cuda. 请注意,Matlab在支持VS / gcc和Cuda等最新编译器方面存在滞后。 It is always good choice to check the compiler requirement by Matlab, before using the latest compilers. 在使用最新的编译器之前,最好通过Matlab检查编译器要求。

Also check whether your Cuda kit and graphics drivers are correctly installed and work seamlessly with VS. 还要检查您的Cuda套件和图形驱动程序是否已正确安装并与VS无缝协作。 You can compile and run some .cu files under the VS environment. 您可以在VS环境下编译和运行一些.cu文件。

If you have finished all above and changed to the correct version of compilers, follow the instructions on matheworks website to compile the mexGPUExample file. 如果您已完成上述所有操作并更改为正确版本的编译器,请按照matheworks网站上的说明编译mexGPUExample文件。 If my memory is correct, you need to set environment variables and copy the XML file to the .mex file path. 如果我的内存是正确的,您需要设置环境变量并将XML文件复制到.mex文件路径。 Then it should work. 然后它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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