Compile Error - Include Directory? Expression must have class type

In the past the small CUDA demonstrations I have built have been reworkings of the cppIntegration project.

I have recently updated the CUDA runtimes libraries and include files and the new cppIntegration project works fine.

However there is a problem when I create my own “.cu” source file containing just the code for the host side, not the kernel, however I imagine it might affect that too.

“Expression must have class type”

This is strange seeing as I have included the directories of the “inc” folder and getting desperate I added all directories of the “vector_types.h” file.

I know that the inclusion of the vector types header file is the problem because it wont let me access .x property of a float3 type.

i then found out that cutil_inline.h doesn’t work either…

[codebox]

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <vector_types.h>

#include <windows.h>

#include

#include <actual_kernel.cu>

#include <cutil_inline.h>

using namespace std;

//global void randompos_kernel(float3* devicevbodata, float pos1, float pos2, float pos3)//the actual kernel, ignore this bit

extern “C” void launch_kernel(float3* myvbodata)

{

float3* devicevbo;

cudaMalloc((void **) &devicevbo, sizeof(float3));

cudaMemcpy(devicevbo, myvbodata, sizeof(float3), cudaMemcpyHostToDevice);

cout << "data copied to the GPU" << endl;

cout << devicevbo.x << endl;                          //** cannot access the .x because the float3 type does not exist in this context so cannot be mapped to the gpu from above...

float pos1 = (float) rand()/RAND_MAX;

float pos2 = (float) rand()/RAND_MAX;

float pos3 = (float) rand()/RAND_MAX;

randompos_kernel<<< 1, 1>>>(devicevbo, pos1, pos2, pos3);

cout << "kernel launched:" << endl; //<< devicevbo[0].x << " " << devicevbo[0].y<< endl;    

bool successful = cudaMemcpy(myvbodata, devicevbo, sizeof(float3), cudaMemcpyDeviceToHost);

if (successful != TRUE)

{

cout << "error" << endl;

}

else

{

cout << myvbodata.x << endl;

}

// cout << “we got this far” << endl;

// cout << *myvbo.x << " " << *devicevbo.x << endl;

// cout << *myvbo.y << " " << *devicevbo.y << endl;

// cout << *myvbo.z << " " << *devicevbo.z << endl;

Sleep(100);

cudaFree(devicevbo);

}

[/codebox]

This is frustrating as I thought that the directory inclusion happened automatically and even when I’ve added all directories this STILL fails…

Advice please!

  1. following code segment is wrong since devicevbo is a pointer
float3* devicevbo;		

	cudaMalloc((void **) &devicevbo, sizeof(float3));	

	cudaMemcpy(devicevbo, myvbodata, sizeof(float3), cudaMemcpyHostToDevice);	

	cout << "data copied to the GPU" << endl;	

	cout << devicevbo.x << endl;

modify it as

cudaMalloc((void **) &devicevbo, sizeof(float3));	

	cudaMemcpy(devicevbo, myvbodata, sizeof(float3), cudaMemcpyHostToDevice);	

	cout << "data copied to the GPU" << endl;	

	cout << devicevbo->x << endl;

Remark: devicevbo points to device memory, you cannot access the content it points, you will obtain segmentation fault,

so "cout << devicevbo->x " is invalid.

  1. the same error occurs in
extern "C" void launch_kernel(float3* myvbodata)

....

	if (successful != TRUE)	{	

		cout << "error" << endl;	

	}	else	{	

		cout << myvbodata.x << endl;	

	}

modify it as

extern "C" void launch_kernel(float3* myvbodata)

....

	if (successful != TRUE)	{	

		cout << "error" << endl;	

	}	else	{	

		cout << myvbodata->x << endl;	

	}

Thankyou for the advice and I have changed the code accordingly, however I am still getting problems with the “.cu” file not recognizing the locations of the include files.

This has not happened before since I have always used the default “.cu” files to house my code and now I have made one of my own it doesn’t recognize the locations of the headers such as “vector_types.h”.

Richt clicking on "open document ‘vector_types.h’ " results in an error window telling me it cannot find it.

I have added the location of the header files directory but that still doesn’t work?

what platform do you work on?

if you use visual studio, can you post project–>property–>C/C++ -->command line