Hello!

I'm trying to learn CUDA to supplement R.  

However, I'm running into a snag.

Here is my code:

    #include<R.h>

//Matrix multiplication kernel - thread specification
    __global__ void MatrixMulKernel(float *Md, float *Nd, float *Pd, int Width) {
    int j;
    int i = (blockIdx.x + threadIdx.x);
    float t = 0.0f;
    for (j=0; j<Width; j++) {
    t += Md[i + j * Width] * Nd[j];
    }
    Pd[i] = t;
    }


    extern "C" {
      void MatrixMultiplication(float *M, float *N, float *P) {
      const int Width= 128;
      int size = Width*Width*sizeof(float);
      float *Md, *Nd, *Pd;

    //Transfer M and N to device memory

      cudaMalloc((void**)&Md, size);
      cudaMemcpy(Md,M,size,cudaMemcpyHostToDevice);
      cudaMalloc((void**)&Nd, size);
      cudaMemcpy(Nd,N,size,cudaMemcpyHostToDevice);

    //Allocate P on the device
      cudaMalloc((void**)&Pd,size);

    //Setup the execution configuration

      dim3 dimBlock(1,1);
      dim3 dimThread(1,1);
    

    //Launch the device computation threads!
      MatrixMulKernel<<<Width,1>>>(Md,Nd,Pd,Width);
      cudaThreadSynchronize();
    //Transfer P from device to host
      cudaMemcpy(P,Pd,size,cudaMemcpyDeviceToHost);



    //Free device matrices
      cudaFree(Md);
      cudaFree(Nd);
      cudaFree(Pd);


  }

  }

and it works fine up to Width of 128.

Then I get a "Memory not Mapped"  error from R.

Does that sound familiar, please?

Thanks,
Sincerely,
Erin


Erin M. Hodgess, PhD
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: hodgesse@uhd.edu


	[[alternative HTML version deleted]]

