0

I get access to CUDA 6 RC as register developer and I want try to use new feature of CUDA 6: Unified Memory. So, I created simple example when I try use this feature: Here is me example:

#include <stdio.h>
#include <cuda_runtime.h>

int
main(void)
{
    int numElements = 5000;
    size_t size = numElements * sizeof(float);
    float *a;
    cudaMallocManaged(&a, numElements);

    for (int i = 0; i < numElements; ++i)
     {
         a[i] = rand()/(float)RAND_MAX;
    }


    return 0;
}

I tried run it example, but I got segmentation fault error:

Segmentation fault: 11

Question - what I doing wrong?

1 Answers1

10

Whenever you are having trouble with cuda code, you should always implement proper cuda error checking

If you do so, I'm pretty sure you'll see the error "operation not supported" as the return code from your cudaMallocManaged call.

Unified Memory support is only available (at this time) on Kepler GPUs. Refer to appendix J "Unified Memory Programming" in the CUDA_C_Programming_Guide.pdf document which will be in the /usr/local/cuda/doc/pdf directory on a standard linux install:

J.1.4. System Requirements

Unified Memory has three basic requirements:

•a GPU with SM architecture 3.0 or higher (Kepler class or newer)

•a 64-bit host application and operating system, except on Android

•Linux or Windows

So switch to a Kepler GPU if you are not already using one, use 64 bit linux or windows (i.e. not MacOS) and be sure to compile your code with an appropriate Kepler architecture specified, e.g. -arch=sm_30

Since your cudaMallocManaged call is failing, the a pointer never gets set, and any subsequent operations with it will result in a seg fault.

And as @talonmies pointed out, change your allocation size from numElements to your computed size variable.

Community
  • 1
  • 1
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257