Help getting CUDA to work with an array of structs Passing a struct array to and from a global kerna

I’m sorry, I have posted this in the wrong section. Could an admin please move this to CUDA Programming and Development?

Hi everyone, I am having some difficulty getting a struct array to pass from to the kernal call. I am able to pass the struct to and from the .cu file in the main function called by my c++ program, but once I send it to CUDA the values seem to be lost.

The following is the code which pertains to this problem (I apologize for any errata, I did my best to strip out what was unnecessary and keep the important parts but I may have missed a variable definition or five External Image ):

Here are the struct declarations:

typedef struct D3DXVECTOR3 {

  FLOAT x;

  FLOAT y;

  FLOAT z;

} D3DXVECTOR3, *LPD3DXVECTOR3;

typedef struct D3DXVECTOR4 {

  FLOAT x;

  FLOAT y;

  FLOAT z;

  FLOAT w;

} D3DXVECTOR4, *LPD3DXVECTOR4;

using namespace std;

struct vertexStruct

{

    D3DXVECTOR3 Pos;

    D3DXVECTOR4 Color;

};

This is so I it can read in the directX struct types. This part seems to work for the regular function call.

Then, I call the function which looks like this (grid and block are set to 1 for debugging purposes):

void fillvertices( vertexStruct vertices [], const int WIDTH, const int HEIGHT, float TriScale)

{

	

	

	D3DXVECTOR4 color;

	D3DXVECTOR4 color2;

	color.x = 0.0f;

	color.y = 0.0f;

	color.z = 1.0f;

	color.w = 0.0f;

	color2.x = 0.0f;

	color2.y = 0.0f;

	color2.z = 1.0f;

	color2.w = 0.0f;

	std::ifstream f_DataFile;

     f_DataFile.open("height.bmp", std::ios::binary);

	 int div = 3;

if (f_DataFile.is_open())

     {

		 int grid = 1;

		 int block = 1;

		kernelRun<<<grid,block>>>(vertices, WIDTH, HEIGHT, TriScale, div, color, color2);

else{

        MessageBox(NULL,"HeighData file not found!","FillVertices()",MB_OK);

    }

f_DataFile.close();

};

Then the global kernel call is this:

__global__ void kernelRun(vertexStruct input [], const int WIDTH, const int HEIGHT, float TriScale, int div, D3DXVECTOR4 color, D3DXVECTOR4 color2) 

       { 

    int y = 1;//1 for debugging				

    int x = 1;//1 for debugging	

	//first triangle

	int tot = y + x*WIDTH;

	int divx = x/div;

	int divy = y/div;

	tot = 0;

	divy = 0;

	divx = 0;

				//1

					{

						input[tot].Pos.x = divy*TriScale;

						input[tot].Pos.y = divx*TriScale;

						input[tot].Pos.z = 0;

                input[y + x*WIDTH].Color = color;

					}

					//2

					{

						input[tot+1].Pos.x = divy;

						input[tot+1].Pos.y = (divx+1)*TriScale;

						input[tot+1].Pos.z = 0;

                input[tot+1].Color = color;

					}

					//3

					{

						input[tot+2].Pos.x = (divy+1)*TriScale;

						input[tot+2].Pos.y = (divx)*TriScale;

						input[tot+2].Pos.z = 0;

                input[tot+2].Color = color;

					}

       }

WIDTH and HEIGHT are set to 1024 each, div is 3, TriScale is 5, , and all values worked previously sequentially. It is basically a 1024x1024 grid of coordinates which I am trying to pass back to directX. If I can get this to work, I should be able to instance a very nice Parallax Occlusion effect and make a realistic, fast vegetation engine.

Thank you in advance and I’ll keep everyone updated on my progress!

EDIT:

Also, the problem is that it runs, but variables seem not to be transferred from the kernel version of the struct as I only see the backdrop and no triangle.

I seem to have sorted the problem for now. It was a combination of things (isn’t it always?) - my card seems to support up to 512x512 thread x blocks. Additionally, I actually needed to pass a memory pointer to the cuda function and also change around the code. If anyone is having similar problems just ask here, post your code, and I’ll see if I can help! I am a neophyte programmer, but I am acquainted with graphics cards and 3d environments, mostly through games and modding, and hopefully will be able to point you in the right direction.