tags:

views:

43

answers:

0

Hi all! I need to use cuda in my application. But i can't create a dll. Some code here.

__global__ void calc(float *a, int n) {  
    int idx = blockIdx.x * blockDim.x + threadIdx.x;  
    float val = a[idx];  
    if (idx < n){  
        a[idx] = 4.0 /(1.0 + val*val);  
    } 
}

...

extern "C" __declspec(dllexport) void GPU_Code ( float *a_h, float *sum ) {
    float *a_d;
    const int numSteps = 10000;
    cudaMalloc((void **) &a_d, sizeof(float)*numSteps);
    int blockSize = 4;  
    int blocks = numSteps / blockSize + (numSteps % blockSize == 0 ? 0:1);  
    cudaMemcpy(a_d, a_h, sizeof(float)*numSteps, cudaMemcpyHostToDevice);

    calc<<< blocks, blockSize >>> (a_d, numSteps);  

    cudaMemcpy(a_h, a_d, sizeof(float)*numSteps, cudaMemcpyDeviceToHost);
        ...
    return; 
}

and dll successfully created! But when i try to include in my application code, i'm take a mistake - fatal error LNK1107: invalid or corrupt file: cannot read at 0x2D0.

__declspec(dllimport) void GPU_Code ( float *a_h, float *sum );

int main() {
float*a_h;  
a_h = (float*)malloc(sizeof(double)*10000);  
float sum = 0.0;
GPU_Code(a_h, &sum);

...
return 0;
}

If you can, take me please a some source code with using dll. P.S. Sorry for my bad english.