Access violation reading location

Hello everyone, I have a problem with the command cudaMemcpy,I have a structure data type Scene (hScene) that must be copied into dScene on my device

the data structure type (scene) is defined:

[codebox]struct _scene

{

double* vertex;

double* normal;

double* texture;

int* face;

int* faceIndex;

int vertexSize;

int normalSize;

int textureSize;

int faceSize;

int faceIndexSize;

int vertexNum;

int normalNum;

int textureNum;

int faceNum;

};

typedef struct _scene scene;[/codebox]

This is the function code AllocaScena:

[codebox]

host void AllocaScena(scene *dScene, scene *hScene)

{

scene tempScene;

cudaMalloc((void**) &(tempScene.vertex), hScene->vertexSize * sizeof(double));

cudaMalloc((void**) &(tempScene.normal), hScene->normalSize * sizeof(double));

cudaMalloc((void**) &(tempScene.texture), hScene->textureSize * sizeof(double));

cudaMalloc((void**) &(tempScene.face), hScene->faceSize * sizeof(int));

cudaMalloc((void**) &(tempScene.faceIndex), hScene->faceIndexSize * sizeof(int));



cudaMemcpy(hScene->vertex, &(tempScene.vertex), hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);

cudaMemcpy(hScene->normal, &(tempScene.normal), hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);

cudaMemcpy(hScene->texture, &(tempScene.texture), hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);

cudaMemcpy(hScene->face, &(tempScene.face), hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);

cudaMemcpy(hScene->faceIndex, &(tempScene.faceIndex), hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);



tempScene.faceNum = hScene->faceNum;



if (dScene==NULL){

cudaMalloc((void**) &dScene, sizeof(scene));

cudaMemcpy(&tempScene, &dScene, sizeof(scene),cudaMemcpyHostToDevice);



}

}

[/codebox]

This is one piece of kernel’s code:

[codebox]

global void DrawScreen(float *a_d, int w, int h, int ch,float3 eye, float3 xdir, float3 ydir, float3 LLdir, scene *dScene)

{

<b>Error-></b> for (int i=0; i<dScene->faceNum; i++){   

}

}

[/codebox]

problem occurs when I read parameters into the dscene, visual studio gives me the following error:

0xC0000005: Access violation reading location 0x00000034

I’m working on Windows XP with Visual Studio 2008 and Cuda_SDK 2.3

These are the settings of Visual Studio 2008:

please help me !!!

your setting of cudaMemcpy is wrong.

prototype of cudaNemcpy is

cudaError_t cudaMemcpy (void dst, const void src, size_t count, enum cudaMemcpyKind kind)

destination is at first argument.

modify

cudaMemcpy(hScene->vertex, &(tempScene.vertex), hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(hScene->normal, &(tempScene.normal), hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(hScene->texture, &(tempScene.texture), hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(hScene->face, &(tempScene.face), hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);	

cudaMemcpy(hScene->faceIndex, &(tempScene.faceIndex), hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);

as

cudaMemcpy(&(tempScene.vertex), hScene->vertex, hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.normal), hScene->normal, hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.texture), hScene->texture, hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.face), hScene->face, hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.faceIndex), hScene->faceIndex, hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);

thank you very much :rolleyes:

why the compiler compiled anyway?

sorry, I must correct what I post

the following code is wrong

cudaMemcpy(&(tempScene.vertex), hScene->vertex, hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.normal), hScene->normal, hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.texture), hScene->texture, hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.face), hScene->face, hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);	

cudaMemcpy(&(tempScene.faceIndex), hScene->faceIndex, hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);

please use

cudaMemcpy( tempScene.vertex, hScene->vertex, hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy( tempScene.normal, hScene->normal, hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy( tempScene.texture, hScene->texture, hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);	

cudaMemcpy( tempScene.face, hScene->face, hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);	

cudaMemcpy( tempScene.faceIndex, hScene->faceIndex, hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);

I corrected the code, as I’ve suggested you, but the error remains the same spot

this is the code:

[codebox]host void AllocaScena(scene *dScene, scene *hScene)

{

scene tempScene;

cudaMalloc((void**) &(tempScene.vertex), hScene->vertexSize * sizeof(double));

cudaMalloc((void**) &(tempScene.normal), hScene->normalSize * sizeof(double));

cudaMalloc((void**) &(tempScene.texture), hScene->textureSize * sizeof(double));

cudaMalloc((void**) &(tempScene.face), hScene->faceSize * sizeof(int));

cudaMalloc((void**) &(tempScene.faceIndex), hScene->faceIndexSize * sizeof(int));





cudaMemcpy( tempScene.vertex, hScene->vertex, hScene->vertexSize * sizeof(double),cudaMemcpyHostToDevice);    

    cudaMemcpy( tempScene.normal, hScene->normal, hScene->normalSize * sizeof(double),cudaMemcpyHostToDevice);    

    cudaMemcpy( tempScene.texture, hScene->texture, hScene->textureSize * sizeof(double),cudaMemcpyHostToDevice);    

    cudaMemcpy( tempScene.face, hScene->face, hScene->faceSize * sizeof(int),cudaMemcpyHostToDevice);    

    cudaMemcpy( tempScene.faceIndex, hScene->faceIndex, hScene->faceIndexSize * sizeof(int),cudaMemcpyHostToDevice);

tempScene.faceNum = hScene->faceNum;



if (dScene==NULL){

cudaMalloc((void**) &dScene, sizeof(scene));

cudaMemcpy(dScene, &tempScene, sizeof(scene),cudaMemcpyHostToDevice);



}

}

global void DrawScreen(float *a_d, int w, int h, int ch,float3 eye, float3 xdir, float3 ydir, float3 LLdir, scene *dScene)

{

int n =w*h*ch; 

int tdx = (threadIdx.x+blockIdx.x*blockDim.x);

int tdy = (threadIdx.y+blockIdx.y*blockDim.y);

int idarray = (tdx+tdy*w)*ch;



float3 dir= CalcolaVettorePunto(xdir, ydir, LLdir, tdx, tdy);





for (int i=0; i<dScene->faceNum; i++){  //<b>ERROR</b>

	

	double v1=dScene->vertex[dScene->face[dScene->faceIndex[i]+1]]; //<b>Warning</b>

	double v2=dScene->vertex[dScene->face[dScene->faceIndex[i]+4]]; //<b>Warning</b>

	double v3=dScene->vertex[dScene->face[dScene->faceIndex[i]+7]]; //<b>Warning</b>

	

	float inc = RayTriangleInc (dir,eye, &v1 , &v2, &v3);

		if(idarray<n){

			if(inc==1){

			a_d[idarray]=1.0f;

			a_d[idarray+1]=1.0f;

			a_d[idarray+2]=1.0f;

			a_d[idarray+3]=1.0f;

			}else{a_d[idarray]=0.0f;

				a_d[idarray+1]=0.0f;

				a_d[idarray+2]=0.0f;

				a_d[idarray+3]=1.0f;

				}		

		}

}

}

[/codebox]

I do not know if it can serve, but when compiling the compiler gives me the following warnings:

[b]2>c:/Documents and Settings/alberto.viale/Desktop/Matteo_G/Matteo_G/DrawScreen.cu(135): Warning: Cannot tell what pointer points to, assuming global memory space

2>c:/Documents and Settings/alberto.viale/Desktop/Matteo_G/Matteo_G/DrawScreen.cu(135): Warning: Cannot tell what pointer points to, assuming global memory space

2>c:/Documents and Settings/alberto.viale/Desktop/Matteo_G/Matteo_G/DrawScreen.cu(135): Warning: Cannot tell what pointer points to, assuming global memory space

2>c:/Documents and Settings/alberto.viale/Desktop/Matteo_G/Matteo_G/DrawScreen.cu(136): Warning: Cannot tell what pointer points to, assuming global memory space

2>c:/Documents and Settings/alberto.viale/Desktop/Matteo_G/Matteo_G/DrawScreen.cu(137): Warning: Cannot tell what pointer points to, assuming global memory space[/b]

The warning comes from non-unified memory space of Tesla architecture
(this would not be the problem when using Fermi architecture)

on-chip shared memory and global memory are seperable, so pointer to shared memory

and pointer to global memory are different, when compiler cannot identify which memory pointer points to,

then it shows warning message “Cannot tell what pointer points to, assuming global memory space”.

since all your pointers point to global memory, you can ignore warning messages.

I have no idea about your algorithm, my suggestion is

check if your allocation for device memory and copy from host to device are correct.

for example, check vertex only, this would narrow down the bug.