1

Hey there... so I am here using VS2008, programming with CUDA C. I have the 3.2 toolkit installed and working.

Now my problem is, i have a file with this:

#ifndef _cuda_rng_cu_included_
#define _cuda_rng_cu_included_

#include <stdio.h>


static void HandleError( cudaError_t err,
                         const char *file,
                         int line ) {
    if (err != cudaSuccess) {
        printf( "%s in %s at line %d\n", cudaGetErrorString( err ),
                file, line );
        exit( EXIT_FAILURE );
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

//some other struct

I got this code from the book CUDA by example, so it should work.. but when i hit build i get this error (the first):

error C2065: 'cudaError_t' : undeclared identifier

and then a tsunami of errors are appended, like uint2 type not being found and variables not being declared.

What could be the problem? cudaError_t is defined in $(CUDA_PATH_V3_2)\include and this path is in my required include directory.

The file property is set like to: Tool: CUDA Runtime API

I put that #ifndef because i haven't figured out how to work with the linker between normal C++ and CUDA C. Like if i have a struct with both CUDA C (__global__ and ` __device__) and some normal methods. If i name this file .cu then in the normal C++ code that uses this struct an error is printed saying it wasn't declared.

I tried to manually include driver_types.h and tons of other headers, but none of them are found by the compiler.

Sorry if i wasn't clear, i'm sleepy.

hfingler
  • 1,931
  • 4
  • 29
  • 36

2 Answers2

3

Files with the .cu extension are handled by nvcc which automatically includes the CUDA-specific headers such that the CUDA types are declared. When you name it .c/.cpp you need to include the relevant header to get the types. Since you're using the runtime API, try include cuda_runtime_api.h.

The fact that you're not finding them suggests your paths have not been set correctly. Try adding $(CUDA_PATH)\include to the include paths (see this post for more details).

Having said that, there are concerns here...

You don't need to declare a struct (or a class) as __global__ or __device__, the struct is just a type and the type is cross-platform. Where you need those declarations is where storage is implied, i.e. when you create an instance of the struct or where you are creating code that must be compiled for the device.

If you are simply declaring a struct then you should be able to declare it in a header file and include it in both .cpp and .cu files with no problems, and if not then by all means post a separate question with more details.

Community
  • 1
  • 1
Tom
  • 20,852
  • 4
  • 42
  • 54
  • I saw that post once, and i forgot to do it in this new project. But still it doesn't work. I can now include cuda.h, cuda_runtime.h and others, and that undeclared identifier goes away. But now i get another error: `'threadIdx' : undeclared identifier`. Goddamnit.. feels like i should be doing this on linux... – hfingler Nov 23 '10 at 18:43
  • What is the declaration of the function where you get the error regarding threadIdx? It should be declared as global. – Eugene Smith Nov 23 '10 at 19:18
  • @user434507, it is in a `__device__` function. It should work, i got this code from a website, it generates random numbers on the device, it's called Rand48. I got it from here: `http://forums.nvidia.com/index.php?showtopic=64545` – hfingler Nov 23 '10 at 19:25
  • Sounds like you're including a `__device__` function into a `.cpp` file. `threadIdx` is a special variable that is defined in device code. You'll need to keep the code separate. – Tom Nov 25 '10 at 15:25
0

Do you have the include paths set correctly? That would explain why the compiler doesn't find the include files.

Henry H
  • 103
  • 1
  • 1
  • 8