如何为mexcuda编译器指定最低计算能力以编译mexfunction? [英] How can I specify a minimum compute capability to the mexcuda compiler to compile a mexfunction?

查看:99
本文介绍了如何为mexcuda编译器指定最低计算能力以编译mexfunction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .cu 文件中有一个CUDA项目,我想使用 mexcuda 编译为 .mex 文件.因为我的代码使用了64位浮点原子操作 atomicAdd(double *,double),该操作仅适用于计算能力为6.0或更高的GPU设备,所以我需要将其指定为我编译时标记.

I have a CUDA project in a .cu file that I would like to compile to a .mex file using mexcuda. Because my code makes use of the 64-bit floating point atomic operation atomicAdd(double *, double), which is only supposed for GPU devices of compute capability 6.0 or higher, I need to specify this as a flag when I am compiling.

在我的标准IDE中,这可以很好地工作,但是当使用 mexcuda 进行编译时,这并没有达到我想要的效果.在关于MathWorks的帖子中,建议使用以下命令(根据乔斯·奈特的评论编辑):

In my standard IDE, this works fine, but when compiling with mexcuda, this is not working as I would like. In this post on MathWorks, it was suggested to use the following command (edited from the comment by Joss Knight):

mexcuda('-v', 'mexGPUExample.cu', 'NVCCFLAGS=-gencode=arch=compute_60,code=sm_60')

但是当我在文件上使用此命令时,详细选项最后吐出以下行:

but when I use this command on my file, the verbose option spits out the following line last:

Building with 'NVIDIA CUDA Compiler'.
nvcc -c --compiler-options=/Zp8,/GR,/W3,/EHs,/nologo,/MD - 
gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=sm_50 - 
gencode=arch=compute_60,code=sm_60 - 
gencode=arch=compute_70,code=\"sm_70,compute_70\"

(依此类推),这向我发出信号,表明指定的标志未正确传递给 nvcc .实际上,编译失败并显示以下错误:

(and so on), which signals to me that the specified flag was not passed to the nvcc properly. And indeed, compilation fails with the following error:

C:/path/mexGPUExample.cu(35): error: no instance of overloaded function "atomicAdd" matches 
the argument list. Argument types are: (double *, double)

我在该主题上唯一能找到的其他帖子是

The only other post I could find on this topic was this post on SO, but it is almost three years old and seemed to me more like a workaround - one which I do not understand even after some research, otherwise I would have tried it - rather than a true solution to the problem.

是否有我错过的设置?或者如果没有解决方法,就无法做到这一点吗?

Is there a setting I missed, or can this simply not be done without a workaround?

推荐答案

在弄乱MatLab文件夹中的标准 xml 文件后,我能够解决此问题.以下步骤使我可以使用 -mexcuda 进行编译:

I was able to work my way around this problem after some messing around with the standard xml-files in the MatLab folder. The following steps allowed me to compile using -mexcuda:

-1)转到文件夹 C:\ Program Files \ MATLAB \ -version- \ toolbox \ distcomp \ gpu \ extern \ src \ mex \ win64 ,其中包含 xml -用于不同版本的msvcpp的文件;

-1) Go to the folder C:\Program Files\MATLAB\-version-\toolbox\distcomp\gpu\extern\src\mex\win64, which contains xml-files for different versions of msvcpp;

-2)备份与您使用的版本相对应的文件.就我而言,我制作了文件 nvcc_msvcpp2017 的副本,并将其命名为 nvcc_msvcpp2017_old ,以始终具有原始文件.

-2) Make a backup of the file that corresponds to the version you are using. In my case, I made a copy of the file nvcc_msvcpp2017 and named it nvcc_msvcpp2017_old, to always have the original.

-3)用记事本打开 nvcc_msvcppYEAR ,然后滚动到以下几行:

-3) Open nvcc_msvcppYEAR with notepad, and scroll to the following block of lines:

COMPILER="nvcc"
COMPFLAGS="--compiler-options=/Zp8,/GR,/W3,/EHs,/nologo,/MD $ARCHFLAGS"
ARCHFLAGS="-gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=sm_50 -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=\"sm_70,compute_70\" $NVCC_FLAGS"
COMPDEFINES="--compiler-options=/D_CRT_SECURE_NO_DEPRECATE,/D_SCL_SECURE_NO_DEPRECATE,/D_SECURE_SCL=0,$MATLABMEX"
MATLABMEX="/DMATLAB_MEX_FILE"
OPTIMFLAGS="--compiler-options=/O2,/Oy-,/DNDEBUG"
INCLUDE="-I"$MATLABROOT\extern\include" -I"$MATLABROOT\simulink\include""
DEBUGFLAGS="--compiler-options=/Z7"

-4)删除将不允许您的代码进行编译的体系结构,即在我的情况下,所有低于60的体系结构标志:

-4) Remove the architectures that will not allow your code to compile, i.e. all the architecture flags below 60 in my case:

ARCHFLAGS="-gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_70,code=\"sm_70,compute_70\" $NVCC_FLAGS"

-5)此后,我可以使用 mexcuda 进行编译.您无需在 mexcuda 调用中指定任何体系结构标志.

-5) I was able to compile using mexcuda after this. You do not need to specify any architecture flags in the mexcuda call.

-6)(可选)我想您想在完成需要进行此更改的项目后恢复此更改,如果要确保最大的可移植性,您将在此之后进行编译.

-6) (optional) I suppose you want to revert this change after you are done with the project that required you to make this change, if you want to ensure maximum portability of the code you will compile after this.

注意:您将需要管理员权限才能进行这些更改.

Note: you will need administrator permission to make these changes.

这篇关于如何为mexcuda编译器指定最低计算能力以编译mexfunction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆