Compiling Cuda Example on Visual Studio 2010 my experience

hello,

i downloaded Cuda examples, and they all work fine when i execute them.
but today i tried compiling with Visual Studio 2010 Beta some of the examples from the CUDA SDK, but i get error which says this plus more messages:

…“XmlTaskFactory” could not be loaded from the assembly…

the error points to “Cuda.target” which is an XML file with the rules defined.

is a compatibility problem because of VS2010 Beta?, or i need to do something else before compiling those examples?
thanks

we don’t support VS2010 yet.

Well I played around with this too. I’d like to get VS2010 CUDA rules because VC 2010 has MPI debugging support. So apparently the conversion wizard in VC2010 can convert the old-style .rule files to the new .targets and .xml rule files but the cuda.rule file needs to be in the solution directory and you need to have its rules enabled (right click on the project in VC and select “Custom Build rules…”. ) rather than perhaps the rules file that is in the VC/VCDefaults directory, which the conversion wizard won’t find. For me, the conversion worked and I saw both a .targets and a .xml file produced, and the CUDA rule set available in the project properties. However compilation didn’t work:
1>Error: Could not find an “AvailableItemName” item for the item type “CUDA_Build_Rule”.
Have to do more research…

see this MSDN thread http://social.msdn.microsoft.com/Forums/en…23-a99ed17cfd4d
lloks like we have to wait until at least beta 2 :-( but that should only take a few more days!

Any word on Visual Studio 2010 for CUDA (or the other way around CUDA support for Visual Studio 2010)???

Any word on Visual Studio 2010 for CUDA (or the other way around CUDA support for Visual Studio 2010)???

You might find this useful to hold you over. It’s a set of modified custom build rules that use allow you to have a CUDA project in VS 2010 but compiles the CU code using the VS 2008 compiler.

http://www.ademiller.com/blogs/tech/2010/0…al-studio-2010/

You might find this useful to hold you over. It’s a set of modified custom build rules that use allow you to have a CUDA project in VS 2010 but compiles the CU code using the VS 2008 compiler.

http://www.ademiller.com/blogs/tech/2010/0…al-studio-2010/

Hi. I’m a beginner, both to CUDA C as well as to Visual Studio 2010. Can someone point me to a guide to help me configure VC2010 to compile CUDA C code? Can’t seem to find any :-|

  1. Create a new C++ empty project in VS2010.

  2. Right click on the project from your Solution Explorer and select Properties. Under the General tab, select v90 under Platform Toolset.

  3. Left click and select the project from your Solution Explorer window, then click on the Project menu and select Build Customizations. The Visual C++ Build Customizations Files window will now pop up.

  4. Check the CUDA 3.2 build customization checkbox and click Ok.

  5. After you’ve selected the required rules file in step 3, right click on your project and click on Properties. Under Properties > Linker > General > Additional Library Directories, key in: $(CUDA_PATH)\lib$(PlatformName)

  6. And then under Properties > Linker > Input > Additional Dependencies, key in all the required CUDA library file dependencies for your CUDA project. E.g if you’re writing your CUDA code using the CUDA Runtime Api, you should include cudart.lib and if you’re writing your CUDA code using CUDA Driver Api, you should include cuda.lib and so on.

  7. The CUDA C/C++ tab will not show up under project Properties until you added in a .cu file inside the project. A quick way to add a .cu file is to either drag and drop one in OR Add an existing item OR Add new item > select c++ file > name your the file with a .cu file extension, i.e. .cu . If after adding the .cu file still doesn’t make the CUDA C/C++ tab show up in the project Properties, right click on your .cu file, select Properties and under General > Item Type, select CUDA C/C++ from the drop down box.

Hope this helps.

Hi,

I have tried Daniel @ NV’s guide to startup CUDA on VS2010, but it doesn’t work for me. When trying to build project I get “this declaration has no storage class or type specifier” and “identifier x is undefined” errors with all cuda-specific calls.

It seems linker can’t see all those cuda declarations, which is odd as I’ve successfully added CUDA header (there is cuda.h in “external dependencies” folder, no errors in #include <cuda.h> line)

I enclose sample code I’m using, and I really count on your help,

Chris

#include "stdafx.h"

#include <stdio.h>

#include <cuda.h>

//Kernel that executes on the CUDA device

__global__ void square_array(float *a, int N)

{

  int idx = blockIdx.x * blockDim.x + threadIdx.x;

  if (idx<N) a[idx] = a[idx] * a[idx];

}

// main routine that executes on the host

int main(void)

{

  float *a_h, *a_d;  // Pointer to host & device arrays

  const int N = 10;  // Number of elements in arrays

  size_t size = N * sizeof(float);

  a_h = (float *)malloc(size);        // Allocate array on host

  cudaMalloc((void **) &a_d, size);   // Allocate array on device

  Initialize host array and copy it to CUDA device

  for (int i=0; i<N; i++) a_h[i] = (float)i;

  cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);

  // Do calculation on device:

  int block_size = 4;

  int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);

  square_array <<< n_blocks, block_size >>> (a_d, N);

  // Retrieve result from device and store it in host array

  cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);

  // Print results

  for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);

  // Cleanup

  free(a_h); cudaFree(a_d);

}

mafiagustawa, the kernel is alright. I think what went wrong could be the build customization settings.

Are you using the CUDA 4.0 toolkit? If yes, did you select the CUDA 4.0 build customization? For CUDA 4.0, there is native support for the v100 toolset. You should use that if you’re using the 4.0 toolkit.

Hello again,
thank you for your post, and I also apologize for such a late reply (holidays ;) )

Indeed, I’m using CUDA 4.0 (CUDA 4.0 build customization is selected, v100 as well) . I’ve just found out that both 4.0 and 3.2 versions are installed on my PC, I’ll try uninstalling 3.2. I don’t think it would help though, so don’t hesitate to share any other ideas, please.

Maybe you might want to zip up your entire project and email it to me at dtoh@nvidia.com too.

I can try taking a look at it and see if it compiles fine on my end.

I have already tried to send it twice - MAILER-DEAMON thinks there’s no such address. Check the spelling please.

dtoh@nvidia.com is correct. You might want to PM me your email address, let me drop you a test mail real quick and you can reply me from there.

mafiagustawa,

I opened your project and made the following changes:

  1. Changed the value under “Linker -> General -> Additional Library Directories” to “$(CudaToolkitLibDir);%(AdditionalLibraryDirectories)”
  2. Under “Linker -> Input”, I added cudart.lib as an additional dependency.

This would ensure that your project would compile fine.

The earlier errors that you saw were errors with VS Intellisense. Syntax highlighting is not supported on VS2010 yet for CUDA. These intellisense errors would not hinder your development but if you want to get rid of them, I recommend you to follow the tutorial on this link:

http://www.ademiller…ort-for-cuda-c/

Hope this helps.

It worked fine, BUT!

Today I’ve tried to do the same on the other machine. It works, but i have no syntax highlighting at all! My .cu file is just plain black text, even simple C++ types aren’t highlighted.

Note that when I was trying to startup CUDA first time (on the other PC) , it was never like that. If something wasn’t working fine I’ve still had standard C++ keywords highlighted.

I’ve already tried guide suggested by Daniel (http://www.ademiller.com/blogs/tech/2010/10/visual-studio-2010-adding-intellisense-support-for-cuda-c/)Any other ideas?

Installing Parallel NSight fixes the syntax higlighting problem.