tags:

views:

43

answers:

0

Hi, we have the following struct defined

typedef struct PurchaseOrder {

char* Value1;

double Value2;

int Value3Length; device int GetValue3Length() {return Value3Length;}

double* Value3; device double GetValue3(int i) { return Value3[i];} device void SetValue3(int i, double value) { Value3[i] = value;}

};

The PurchaseOrder data (array of structs) are marshalled from C# application into the following C dll function

int RunMonteCarlo(PurchaseOrder *hostPurchaseOrders, int length) {    
PurchaseOrder *devPurchaseOrders; 
// display the results
for (int i = 0; i < length; i++) 
{            
    //printf("\n\nAddress: %u",hostPurchaseOrders+i);            
    printf("\n\nIndex: %d", i);            
    printf("\nValue1: %s",(hostPurchaseOrders+i)->Value1);
    printf("\nValue2: %f",(hostPurchaseOrders+i)->Value2);


    for(int  j = 0; j < (hostPurchaseOrders+i)->Value3Length; j++)
    {
        printf("\nValue3[%d]: %fl", j, (hostPurchaseOrders+i)->Value3[j]);            
    }
    }    

// allocate the memory on the GPU
HANDLE_ERROR( cudaMalloc( (void**)&devPurchaseOrders, length * sizeof(PurchaseOrder) ) );

// copy the array 'PurchaseOrder' to the GPU
HANDLE_ERROR( cudaMemcpy( devPurchaseOrders, hostPurchaseOrders, length * sizeof(PurchaseOrder), cudaMemcpyHostToDevice ) );    

// Run the kernel code
MonteCarloKernel<<<60,32>>>( devPurchaseOrders, length);

// copy the array 'PurchaseOrders' back from the GPU to the CPU
HANDLE_ERROR( cudaMemcpy(hostPurchaseOrders, devPurchaseOrders, length * sizeof(PurchaseOrder), cudaMemcpyDeviceToHost ) );    



// free the memory allocated on the GPU
    HANDLE_ERROR( cudaFree( devPurchaseOrders ) );     

return 0;}

__global__ void MonteCarloKernel(PurchaseOrder *purchaseorders, long length) {
    int i = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;

 while (i < length) 
 {        

purchaseorders[i].SetAAUS(1.11);


    for (int j=0; j < purchaseorders[i].GetValue3Length(); j++) 
{            

   //purchaseorders[i].SetValue3(j,1.0);
}


    i += stride;
}}

The data are marshalled correctly as verified by the printf code at the beginning.

However, the Value3 (array of double) seems not copied into the device memory as the line purchaseorders[i].SetValue3(j,1.0) in the kernel crashes the application.

What should I do to solve it out?

When the application crashes, the console windows just closed. What debug technique I could use to get some meaningful messages?