NVCC complaining about incomplete types and unknown storage size

I have looked all over the place for a solution to this problem. This means there are two equally likely possibilities. Either this problem is tricky or really obvious. If it’s the second one, bear with me.

Ok, so I go to compile my beautifully written CUDA code. To my horror I get the message that the CUDA types I use all have incomplete type, or that their storage size of unknown. See for yourself:

This example code:

#line 2

// -----------------------------------------------------------------------------

// 

// Common functions, such as initialization and freeing. 

// 

// -----------------------------------------------------------------------------

#ifndef EXAMPLE_C

#define EXAMPLE_C

#include <stdio.h>

#include <stdlib.h>

#include <cuda.h>

#include "matrix_types.h"

// -----------------------------------------------------------------------------

// 

// Reporting and diagnostic functions. 

// 

// -----------------------------------------------------------------------------

#define REPORT_FAILURE(__DEATH_MESSAGE__) printf("%s.%d : FAILURE : %s\n", __FILE__, __LINE__, __DEATH_MESSAGE__);exit(-1);

void reportcudaProperties(char * return_string, int dev) 

{

// Compiler says: 

// error: storage size of ‘properties’ isn’t known

  struct cudaDeviceProp properties;

  cudaGetDeviceProperties(&properties, dev);

sprintf(return_string, "Device Name					 : %s\n", properties.name);

  sprintf(return_string, "Total Global Memory (bytes)	 : %d\n", properties.totalGlobalMem);

  sprintf(return_string, "Shared Memory per Block (bytes) : %d\n", properties.sharedMemPerBlock);

  sprintf(return_string, "Total Multiprocessors		   : %d\n", properties.multiProcessorCount);

  sprintf(return_string, "Registers Per Block			 : %d\n", properties.regsPerBlock);

  sprintf(return_string, "Warp Size					   : %d\n", properties.warpSize);

  sprintf(return_string, "Maximum Pitch (bytes)		   : %d\n", properties.memPitch);

  sprintf(return_string, "Maximum Threads per Block	   : %d\n", properties.maxThreadsPerBlock);

  sprintf(return_string, "Max Block Dimensions (x,y,z)	: (%d,%d,%d) \n", 

	  properties.maxThreadsDim[0],

	  properties.maxThreadsDim[1],

	  properties.maxThreadsDim[2]);

  sprintf(return_string, "Max. Grid Size (x,y,z)		  : (%d,%d,%d) \n",

	  properties.maxGridSize[0],

	  properties.maxGridSize[1],

	  properties.maxGridSize[2]);

  sprintf(return_string, "Total Constant Memory (bytes)   : %d\n", properties.totalConstMem);

  sprintf(return_string, "Compute Capability			  : %d.%d\n",

	  properties.major, properties.minor);

  sprintf(return_string, "Clock Rate (Kilohertz)		  : %d\n", properties.clockrate);

  sprintf(return_string, "Texture Alignment			   : %d\n", properties.textureAlignment);

  sprintf(return_string, "Can copy memory during kernel execution ?\n----> %s", 

	  (properties.deviceOverlap == 1 ? "yes" : "no"));

}

// Initialize a matrix into device memory memory. 

matrix_error_t matrix_int_init(matrix_int * ret_matrix, 

				   int rows,

				   int cols) 

{

  if ((rows <= 0) || (cols <= 0)) {

	REPORT_FAILURE("Improper matrix dimensions");

  }

// Allocate a cudaMatrix on the device. 

  size_t pitch;

  struct cudaError_t error_code = cudaMallocPitch((void **) &(ret_matrix->contents), &pitch, 

		  sizeof(int) * rows, cols);

if (error_code != cudaSuccess) {

	REPORT_ERROR(cudaGetErrorString(error_code));

  }

ret_matrix->rows = rows;

  ret_matrix->cols = cols;

  ret_matrix->pitch = pitch;

}

#endif // EXAMPLE_C

Generates the following errors:

$ nvcc example.c 

example.c: In function ‘reportcudaProperties’:

example.c:33: error: storage size of ‘properties’ isn’t known

example.c: In function ‘matrix_int_init’:

example.c:73: error: variable ‘error_code’ has initializer but incomplete type

example.c:73: error: storage size of ‘error_code’ isn’t known

example.c:76: error: ‘cudaSuccess’ undeclared (first use in this function)

example.c:76: error: (Each undeclared identifier is reported only once

example.c:76: error: for each function it appears in.)

I doubt it’s something on the end of the CUDA developer, but this i something one might expect to see when a type is declared as extern…

Any ideas?

Don’t all answer at once…

For the purpose of google crawling your forum, I’l answer my own question. These types are defined in driver_types.h, which you need to #include. Turns out it was pretty simple.

Don’t all answer at once…

For the purpose of google crawling your forum, I’l answer my own question. These types are defined in driver_types.h, which you need to #include. Turns out it was pretty simple.