2

I was wondering why none of simple Cuda code examples I found in Internet are working for me and I found that even this simplest code cause an error:

#include <stdio.h>

int main(int argc, char ** argv) {
    size_t available, total;
    cudaError_t err = cudaMemGetInfo(&available, &total);
    if (err == cudaErrorMemoryAllocation) {
        printf("cudaErrorMemoryAllocation");
    } else {
        printf("OK or not memory allocation error");
    }
    return 0;
}

The code above always prints out "cudaErrorMemoryAllocation".

Here is the output of cuda-memcheck test for this program:

cudaErrorMemoryAllocation
========= CUDA-MEMCHECK
========= Program hit error 2 on CUDA API call to cudaMemGetInfo 
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:C:\Windows\SYSTEM32\nvcuda.dll (cuD3D11CtxCreate + 0x118a92) [0x137572]
=========     Host Frame:D:\Cuda\a.exe [0x1223]
=========     Host Frame:D:\Cuda\a.exe [0x101c]
=========     Host Frame:D:\Cuda\a.exe [0x901f]
=========     Host Frame:C:\Windows\system32\KERNEL32.DLL (BaseThreadInitThunk + 0x1a) [0x1832]
=========     Host Frame:C:\Windows\SYSTEM32\ntdll.dll (RtlUserThreadStart + 0x21) [0x5d609]
=========
========= ERROR SUMMARY: 1 error

Platform Windows 8 64-bit

Compiler Visual Studio 2008

Compute capability 1.1 (GeForce 8800 GT)

CUDA version 5.5

nalexn
  • 10,615
  • 6
  • 44
  • 48
  • 3
    Are you able to correctly run the CUDA SDK samples, in particular, the deviceQuery sample? – Vitality Jan 24 '14 at 10:39
  • Yes, I'm able to run deviceQuery, it prints out the configuration of my 8800 GT correctly. However a few other samples I've tried to launch failed with "CUDA error code=2 (cudaErrorMemoryAllocation)" – nalexn Jan 24 '14 at 11:46
  • 2
    I hope I'm not driving you in the wrong direction, but I would investigate for a possible driver issue. Are you using the correct driver for your card? What about reinstalling the driver? – Vitality Jan 24 '14 at 12:04
  • There was an update available for my card, so I have installed it. Unfortunately it didn't solve the problem. – nalexn Jan 24 '14 at 12:34
  • Have you tried with a simple system restart? It solved this kind of problems [here](https://devtalk.nvidia.com/default/topic/606400/cuda-setup-and-installation/cuda-bandwidthtest-fails-devicequery-passes/), [here](https://devtalk.nvidia.com/default/topic/605603/error-for-bandwidth-test-after-install-cuda-in-mac-/#3937632) and [here](https://devtalk.nvidia.com/default/topic/605398/cuda-error-at-bandwidthtest-cu-for-geforce-gtx-660m/). – Vitality Jan 24 '14 at 13:44

2 Answers2

1

When creating a CUDA context, a lot of stuff is allocated so it might happen that your available memory isn't enough to intialize it. That might explain the cudaErrorMemoryAllocation error you're getting.

cudaMemGetInfo doesn't throw that specific error so it must be something else:

Note that this function may also return error codes from previous, asynchronous launches.

The cuD3D11CtxCreate in the stack trace also creates a CUDA context so it might be it.

Also: if you have multiple apps running contending your device, that might be the cause as well.

Community
  • 1
  • 1
Marco A.
  • 43,032
  • 26
  • 132
  • 246
  • I think 512 MB should be enough to initialize Cuda environment, there is no other programms running that could consume whole memory. – nalexn Jan 24 '14 at 10:11
  • Have you tried resetting the device prior to do that? cudaDeviceReset – Marco A. Jan 24 '14 at 10:16
  • I have tried just now. cudaDeviceReset() returns cudaSuccess, but no changes for the rest part of the program – nalexn Jan 24 '14 at 10:24
0

The problem was solved. I'm still not sure what caused this, either there was a conflict between old video card driver and a new one installed hiddenly under "Recommended" option in Cuda installer, or a askew installed VS 2008. However I decided to reinstall everything and try VS 2012 instead of VS 2008, and now everything works fine.

nalexn
  • 10,615
  • 6
  • 44
  • 48