2

I am having problem converting .cu to .ptx. I am using nvcc as follows:

"C:\ Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc" -ptx -ccbin "C:\ Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -o foo.ptx foo.cu

The following is displayed in return:

foo.cu
c1xx : fatal error C1083: cannot open source file: 'foo.cu': No such file or directory

foo.cu is located in the \CUDA\v5.0\bin.

BenC
  • 8,729
  • 3
  • 49
  • 68
Maverick
  • 61
  • 1
  • 6
  • In which folder are you running the command? This just means that `nvcc` cannot find your `foo.cu` file. Either run the command in the file's folder, or provide a full path to `nvcc`. – BenC May 15 '13 at 13:21
  • I am giving the full path in the command but you have edited my message. > "C:\ Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc" -ptx -ccbin "C:\ Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -o foo.ptx foo.cu – Maverick May 15 '13 at 15:42
  • You are right. I gave the command from the said directory and it is now compiling. Its giving something like: 'tmpxft_00001100_000000000-5_foo.cudafe1.gpu' and 'tmpxft_00001100_000000000-10_foo.cudafe2.gpu' But where do I find my foo.ptx? I cannot see it. Is something still wrong? – Maverick May 15 '13 at 16:10
  • The `ptx` files are in the directory from which you launched `nvcc`. For instance, if I run the following command on Linux: `nvcc test.cu -ptx -o test.ptx`, I get `test.ptx` in the current directory. – BenC May 16 '13 at 01:39
  • No, not there. Is there any other non-commandline method? – Maverick May 16 '13 at 04:59
  • Does the compilation work? If compilation fails, you will not get any `ptx` file, obviously. – BenC May 16 '13 at 05:11
  • I have Visual Studio 2010 to basically compile and run my `.cu` files. I need to convert them to `.ptx` to be able to use these gpu functions in the MATLAB code. Now, I have gone back and tried to generate the `.ptx` file by changing the custom build options of the VC project for `CUDA C/C++`. In there, I have allowed to keep the `pre-processed files` and enabled to `generate relocatable device code`. `.cu` and `.gpu` files are being output successfully but as it tries to generate the `.ptx` the following happens: – Maverick May 16 '13 at 09:24
  • You should use http://pastebin.com/ to share long messages in the comment section. – BenC May 16 '13 at 09:36
  • Ben, thanks and sorry. Here is the [build output](http://pastebin.com/CbQhcxZD) – Maverick May 16 '13 at 11:36
  • Could you also share the content of your `x64/Debug/TestingPTX.cu.obj.cu.ptx` file, or at least the beginning? You should have a `.version` and `.target` at the start of the file. I think these are actually not `ptx` files, since I don't see any `-ptx` option for `nvcc` in your build output. – BenC May 16 '13 at 11:53
  • No, I do not have a `.version` or `.target` in my TestingPTX.cu file. The C++ code for the given file can be seen at: [http://pastebin.com/f78v7ReM](http://pastebin.com/f78v7ReM) – Maverick May 16 '13 at 12:10
  • So what is in the `.ptx` file then? By doing `nvcc -ptx testingptx.cu -o testingptx.ptx` with your code, I get http://pastebin.com/hQ6hBqcg. – BenC May 16 '13 at 12:31
  • That is the problem. In my case such commands are not working. What i get is [pastebin.com/nAZDgDth](http://pastebin.com/nAZDgDth) – Maverick May 16 '13 at 13:06
  • You are using Windows so the compiler may expect some different things. You just need to make sure that the `-ptx` flag is used by Visual Studio. – BenC May 16 '13 at 13:08

1 Answers1

4

Go to the Project Properties in Visual Studio 2010. In CUDA C/C++, in Common change the property Keep Preprocessed Files to Yes(--keep). Build the project. You should be able to see the .ptx file in folder as C:/Users/Mansoor/Documents/Visual Studio 2010/Projects/Testing_PTX/x64/Debug depending on the configuration (x32 or x64). If your .cu filename was TestingPTX.cu then the filename for PTX file would be TestingPTX.compute_xx.ptx where xx is the compute capability defined in your project properties. For multiple compute capability options there will be a dedicated .ptx file. The content of a typical PTX file can be seen at pastebin.com It is very straight forward but took me quite some time to figure out because there is not much material over the internet regarding generation of .ptx within the Visual Studio environment. Hope it will help the newbies like me.

Maverick
  • 61
  • 1
  • 6