I am doing gpgpu programming in windows and I have been doing that in Microsoft visual studio 2010. But for some reason I need to use matlab to run my cuda kernels. So I was checking this site and they have mentioned that I need to create a .ptx from .cu file to run my cuda kernels. But I am using windows and I want to create the .ptx file in windows. It would be really helpful if anyone could guide me know how to convert a .cu file to .ptx file. Thanks
1 Answers
One approach is to do this from the command line. You may need to know the location of nvcc.exe as well as cl.exe (the MS VC compiler). In my case I have MS VC 2008 express installed, and cl.exe is located at C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe I also have CUDA 4.2 on this particular machine, and nvcc is located at C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe You can probably also use windows search to find these.
With the above information, open a command prompt, and change directory to the .cu file (let's call it foo.cu) that you want to convert to PTX. nvcc may already be on your PATH, so you may not have to use it's path:
<path-to-nvcc>nvcc -ptx -ccbin "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin" -o foo.ptx foo.cu
You can put the path to cl.exe on your PATH variable to simplify the above (should be able to eliminate the -ccbin switch that way.) To get more info about nvcc options, use:
nvcc --help
If your program needs additional include files beyond what nvcc knows about, you'll have to specify the path to those as well using the -I switch. Review the nvcc options for more info.

- 143,785
- 11
- 213
- 257
-
Thanks for your reply. My nvcc.exe is in "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin" folder and I tried : "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin"nvcc -ptx -ccbin "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin" -o foo.ptx foo.cu. But I am getting a reply of : "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin"nvcc' is not recognized as an internal or external command. – duttasankha Nov 17 '12 at 01:03
-
don't put quotes around the path to nvcc. Just launch it like you would launch an ordinary windows program with full path: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc -ptx -ccbin "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin" -o foo.ptx foo.cu Also, nvcc may already be on your path, so you may not even have to specify the path. You may just be able to type: nvcc -ptx .... – Robert Crovella Nov 17 '12 at 01:15
-
Thanks for your help. I did what you have mentioned. Again some error is occurring but the message is bit different. So I copy pasted your line and executed it and the error that I am getting is : 'C:\Program' is not recognized as an internal or external command,operable program or batch file. I tried the same thing by rubbing of the path of nvcc and just appending nvcc with it and the error that time is : 'nvcc' is not recognized as an internal or external command,operable program or batch file. – duttasankha Nov 17 '12 at 01:25
-
OK try this: "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc" -ptx -ccbin "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin" -o foo.ptx foo.cu – Robert Crovella Nov 17 '12 at 01:32
-
now I am getting : nvcc fatal : Unsupported host compiler 'bin' – duttasankha Nov 17 '12 at 01:42
-
where is your cl.exe located? You are using MS VC 2010, it's not going to be on the same path as my cl.exe which is in the path on the example I gave. – Robert Crovella Nov 17 '12 at 01:45
-
actually cl.exe is located in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin I know I made the mistake and I made it correct. But even now I am getting the error which is : nvcc fatal : Visual studio configuration file '(null)' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/../..' – duttasankha Nov 17 '12 at 01:53
-
OK that is a separate issue. The above steps work for me. You may need to reinstall Visual Studio and then the CUDA toolkit. The CUDA toolkit should be installed after you install Visual Studio, not before. You may also want to look for similar issues like [this one](http://stackoverflow.com/questions/8900617/how-can-i-setup-nvcc-to-use-visual-c-express-2010-x64-from-windows-sdk-7-1) or [this one](http://stackoverflow.com/questions/2970493/cuda-linking-error-visual-express-2008-nvcc-fatal-due-to-null-configuratio). – Robert Crovella Nov 17 '12 at 01:58