Skip to content
Prev 46253 / 63458 Next

question about Makeconf and nvcc/CUDA

Hi again:

Here is another problem that I am having.  Hope this will be the last one.  I really want to see if I can put it together.  Sorry for belaboring the issue.

Well, here is my story:

c:\Program Files\R\R-3.0.1\bin\i386>R CMD build cudasize
R CMD build cudasize
* checking for file 'cudasize/DESCRIPTION' ... OK
* preparing 'cudasize':
* checking DESCRIPTION meta-information ... OK
* cleaning src
Warning: C:/Users/erin/AppData/Local/Temp/RtmpOKsfga/Rbuild22e066bf13fb/cudasize/man/f1.Rd:33: unexpected '{'
Warning: C:/Users/erin/AppData/Local/Temp/RtmpOKsfga/Rbuild22e066bf13fb/cudasize/man/f1.Rd:37: unexpected '}'
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'cudasize_1.0.tar.gz'


c:\Program Files\R\R-3.0.1\bin\i386>R CMD INSTALL --no-multiarch cudasize_1.0.tar.gz 
R CMD INSTALL --no-multiarch cudasize_1.0.tar.gz 
* installing to library 'c:/myRlib'
* installing *source* package 'cudasize' ...
** libs
nvcc -m32 --shared -o cuda4.dll cuda4.cu
cuda4.cu
tmpxft_000012fc_00000000-5_cuda4.cudafe1.gpu
tmpxft_000012fc_00000000-10_cuda4.cudafe2.gpu
cuda4.cu
tmpxft_000012fc_00000000-5_cuda4.cudafe1.cpp
tmpxft_000012fc_00000000-15_cuda4.ii
installing to c:/myRlib/cudasize/libs/i386
** R
** preparing package for lazy loading
** help
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:33: unexpected '{'
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:37: unexpected '}'
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:31: All text must be in a section
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:32: All text must be in a section
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:34: All text must be in a section
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:35: All text must be in a section
Warning: C:/Users/erin/AppData/Local/Temp/RtmpKSm696/R.INSTALL7fc517f4e58/cudasize/man/f1.Rd:36: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (cudasize)

c:\Program Files\R\R-3.0.1\bin\i386>R --vanilla
R --vanilla

R version 3.0.1 (2013-05-16) -- "Good Sport"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: i386-w64-mingw32/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
library(cudasize)
f1
function (x) 
{
    y <- .Call("cuda4", as.character(x))
    return(y)
}
<environment: namespace:cudasize>
f1(2)
Error in .Call("cuda4", as.character(x)) : 
  "cuda4" not resolved from current namespace (cudasize)
Calls: f1 -> .Call
Execution halted

Here is the Makevars.win file

cuda4.dll:
	nvcc -m32 --shared -o cuda4.dll cuda4.cu

And finally, the program itself:


#include <stdio.h>
#include <cuda.h>
 
// Kernel that executes on the CUDA device
__global__ void square_array(float *a, int N)
{
  int idx = blockIdx.x * blockDim.x + threadIdx.x;
  if (idx<N) a[idx] = a[idx] * a[idx];
}
 
// main routine that executes on the host
void  stuff(int argc, char **argv)
{
  float *a_h, *a_d;  // Pointer to host & device arrays
  int N = atoi(argv[1]);
//  const int N = 10;   Number of elements in arrays
  size_t size = N * sizeof(float);
  a_h = (float *)malloc(size);        // Allocate array on host
  cudaMalloc((void **) &a_d, size);   // Allocate array on device
  // Initialize host array and copy it to CUDA device
  for (int i=0; i<N; i++) a_h[i] = (float)i;
  cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
  // Do calculation on device:
  int block_size = 4;
  int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
  square_array <<< n_blocks, block_size >>> (a_d, N);
  // Retrieve result from device and store it in host array
  cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
  // Print results
  for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
  // Cleanup
  free(a_h); cudaFree(a_d);
}

Any suggestions would be appreciated.

Thanks,
Erin