Search code examples
c++vectorgputhrust

type mismatch while calling the subroutine


argument of type "int *" is incompatible with parameter of type "int"

__global__ void DeviceFun(thrust::device_vector<int>* arr, int len0, int len1)
{
    int i = threadIdx;
    if ( (i>=len0) && (i<len1) )
        printf("arr[%d] = %d    ", i, arr[i]);
}

int main()
{
    thrust::device_vector<int> v(4);
    thrust::fill(v.begin(), v.end(), 137);

    int len = 4;
    int len0 = 0;
    int len1 = len;

    DeviceFun<<<1, len>>>(&v, &len0, &len1);
    cudaDeviceSynchronize();

    return 0;
}

Try to fix the errors in order to compile and run the program.


Solution

  • DeviceFun<<<1, len>>>(&v, &len0, &len1);

    The signature of DeviceFun is:

    DeviceFun(int* arr, int len0, int len1)
    

    However you are passing pointers to len0 and len1 to the function. I think you should be calling DeviceFun like this:

    DeviceFun<<1, len>>(&v[0], len0, len1);