0

i'm compiling a cuda 5.5 project on vs2010. i need to use mpir library because my project consist of large numbers. when i use mpir instructions this error appears. i do not know how can i fix it. this program adds array A and array B using mpir functions.

 __global__
void vecAdd(mpz_t *A,mpz_t *B,mpz_t *C,int N)
{
    int i = threadIdx.x + blockDim.x * blockIdx.x;
    if(i<N)
    mpz_add(C[i],A[i],B[i]); 
}

int main()
{
    mpz_t *h_A;
    h_A=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(h_A[0],5,16);
    mpz_set_si(h_A[0],1);
    mpz_set_si(h_A[1],2);
    mpz_set_si(h_A[2],3);
    mpz_set_si(h_A[3],4);
    mpz_set_si(h_A[4],5);

    mpz_t *h_B;
    h_B=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(h_B[0],5,16);
    mpz_set_si(h_B[0],1);
    mpz_set_si(h_B[1],2);
    mpz_set_si(h_B[2],3);
    mpz_set_si(h_B[3],4);
    mpz_set_si(h_B[4],5);
    mpz_t *h_C;
    h_C=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(h_C[0],5,16);

    int N=5;
    int size=N*sizeof(mpz_t);

    mpz_t *d_A;
    d_A=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(d_A[0],5,16);

    mpz_t *d_B;
    d_B=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(d_B[0],5,16);

    mpz_t *d_C;
    d_C=(mpz_t*)malloc(5*sizeof(mpz_t));
    mpz_array_init(d_C[0],5,16);

    cudaMalloc((void**)&d_A,size);
    cudaMemcpy(d_A, h_A, size, cudaMemcpyHostToDevice);
    cudaMalloc((void**)&d_B,size);
    cudaMemcpy(d_B, h_B, size, cudaMemcpyHostToDevice);
    cudaMalloc((void**)&d_C,size);

    vecAdd<<<ceil(N/512.0),512>>>(d_A,d_B,d_C,N);

    cudaMemcpy(h_C, d_C, size, cudaMemcpyDeviceToHost);

    cudaFree(d_A);  
    cudaFree(d_B);  
    cudaFree(d_C);

    for(int i=0;i<5;i++)
    {
       mpz_out_str(stdout,10,h_C[i]);
       printf("\n");
    }

    return 0;
}
Makoto
  • 765
  • 2
  • 17
  • 45
maral
  • 31
  • 1
  • 3
  • 2
    Indent your code please. – Jabberwocky Oct 07 '14 at 11:32
  • @Angew Oh, OK - remembered it wrong. Sorry. – Rup Oct 07 '14 at 11:51
  • 1
    If all you want to do is big-integer addition, then [this question/answer](http://stackoverflow.com/questions/12957116/large-integer-addition-with-cuda) may be of interest. The [CUMP](http://www.hpcs.cs.tsukuba.ac.jp/~nakayama/cump/) library handles extended precision floating point using CUDA. It's primarily a floating-point library, but there may be a big-integer basis in there somewhere. – Robert Crovella Oct 07 '14 at 15:37

1 Answers1

2

You have to understand that functions that may be called from the device have to be compiled to device code. Placing a __device__ in the declaration of the function will make it available from the device side.

However, since mpz_add is from the MPIR library, which was not made with CUDA-compatibility features (as far as I'm aware of), you're out of luck. I suggest you find a GPU implementation of arbitrary precision numbers.

user703016
  • 37,307
  • 8
  • 87
  • 112