Thread Subject: Compiling CUDA C/C++ mex code under linux

Subject: Compiling CUDA C/C++ mex code under linux

From: Oliver Woodford

Date: 29 Sep, 2009 08:53:01

Message: 1 of 1

Hi all

There a several methods available on the file exchange for compiling CUDA C/C++ code into mex files under Windows, but none that I've come across work for linux. However, I've found a nice, easy way to do it, which I'll share with you, though I must confess I haven't tested it extensively.

The idea is to use Nvidia's nvcc compiler to convert CUDA C/C++ code into standard C++ code, then use mex after that. The first stage looks something like:

system(sprintf('nvcc -I"%s/extern/include" --cuda "mexfun.cu" --output-file "mexfun.cpp"', matlabroot));

Then the second stage is roughly:

mex -I/opt/cuda/include -L/opt/cuda/lib -lcudart mexfun.cpp

Obviously you need to set the various paths and file/function names to suit your needs.

HTH,
Oliver

PS Does anyone think this approach could reduce the efficiency of the resulting machine code? I do wonder if it doesn't limit the level of optimization that can be applied.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mex Oliver Woodford 29 Sep, 2009 04:54:02
compile Oliver Woodford 29 Sep, 2009 04:54:02
linux Oliver Woodford 29 Sep, 2009 04:54:02
cuda Oliver Woodford 29 Sep, 2009 04:54:02
c Oliver Woodford 29 Sep, 2009 04:54:02
nvcc Oliver Woodford 29 Sep, 2009 04:54:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com