1

While compiling mex files with nvcc I have struggled to pass compiler options specific to CUDA to the nvcc compiler, as mex doesn't recognize them.

I found some old posts about passing compiler flags and some newer ones, but the questions are quite user-specific, and the mex compiler has changed over the years, so I cant figure out what to do.

So, my specific question: What should I do to make mex pass compiler flags to nvcc?

A bit more generic: What should one do to make mex pass compiler flags to another compiler?

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • It's such a headache that I just do it in the [Visual Studio IDE](http://stackoverflow.com/a/30408715/2778484) using the integration installed with the CUDA Toolkit. But I'd like to add an answer to your question if I get time today. In short, I usually use property sheets, where you can type additional flags, but again this uses the IDE to compile rather than `mex`. Is that too specific of a use case? Or the new way with an XML... – chappjc Oct 27 '15 at 16:25
  • Or the new way with an XML [as I do for MinGW](https://github.com/chappjc/MATLAB/tree/master/MinGW). Or is this not what you mean? – chappjc Oct 27 '15 at 16:31
  • @chappjc if you have an answer add it, at least for future lost compilers. – Ander Biguri Oct 27 '15 at 16:31
  • 1
    Yes, I figured you have _your_ answer. :) Just wanted to be on topic... – chappjc Oct 27 '15 at 16:54

1 Answers1

0

If working with the newest compiling way where the options are in an xml file, one can hardcode the default compile flags in there. For example mine looks like:

COMPILER="nvcc"
      COMPFLAGS="-gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_35,code=sm_35 -gencode=arch=compute_50,code=\"sm_50,compute_50\" --compiler-options=/c,/GR,/W3,/EHs,/nologo,/MD"
      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"

One can change the defaults modifiying COMPFLAGS

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Where does one find this file? Is it generated automatically? – Floris Nov 06 '20 at 00:01
  • @Floris Good question, but vague answer (this is 5 years ago!). I found mine within MATLAB installation. There are few `xml` files there for visual studio compiling, and then I added these things to that. If you want a modified template that should work for CUDA, check my tool "TIGRE toolbox" in github, I provide various `xml` already set for CUDA. – Ander Biguri Nov 06 '20 at 10:05
  • 1
    Answering my own question... you can find the file in the `prefdir` directory - so `dir(fullfile(prefdir,'mex*.xml'))` should give you a pretty good idea of what's there. – Floris Nov 06 '20 at 14:13