0

I cannot allocate even only 4 bytes of memory with cudaMallocHost() because of 'out of memory' error. I tried cudaSetDevice(0), cudaDeviceSynchronize(), cudaThreadSynchronize(), and cudaFree(0) at the very first of my code for initializing, but they don't work.

I think this link : cudaMalloc always gives out of memory - has the answer what I want but I cannot understand it. How can I solve this problem?

Here is my full code.

/* test.cu */
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include <assert.h>

inline cudaError_t checkCuda(cudaError_t result)
{
    if (result != cudaSuccess) {
        fprintf(stderr, "CUDA Runtime Error: %s\n", cudaGetErrorString(result));
        assert(result == cudaSuccess);
    }
    return result;
}

int main()
{
    cudaSetDevice(0);
    cudaDeviceSynchronize();
    cudaThreadSynchronize();
    cudaFree(0);

    int *test_ptr;
    checkCuda( cudaMallocHost((void **)&test_ptr, sizeof(int)) );
    cudaFreeHost(test_ptr);
    printf("Test Success.\n");
    return 0;
}

I compiled with this instruction:

nvcc test.cu -o test

and when I execute this:

me@me:~$ ./test
CUDA Runtime Error: out of memory
test: test.cu:10: cudaError_t checkCuda(cudaError_t): Assertion `result == cudaSuccess' failed.
Aborted

My cuda version is 5.0, I'll post more specific device information if you need.

Community
  • 1
  • 1
user3910910
  • 79
  • 1
  • 6
  • Are you running a multi-threaded app? If not, I don't think the other question you linked covers your problem. You should provide a short, *complete* code that demonstrates the problem you are having. Something that someone else can copy, paste, compile, and run to see the issue, without adding anything or changing anything. This should only require a few lines of code. SO expects [this](http://stackoverflow.com/help/mcve). You should also provide the compile command you are using, and describe the platform (OS, CUDA version, GPU). – Robert Crovella Aug 23 '14 at 01:45
  • What Robert said. Check all status returns and all relevant error logs. From your description it seems that the CUDA runtime cannot initialize. Possible causes include: (1) your driver is too old for the version of the CUDA runtime you are running. (2) You don't have an NVIDIA GPU in the system that is supported by CUDA (3) No CUDA-capable GPU is available because they in use by other processes that run in exclusive mode (4) you are on Linux and the device files have not been created, e.g. due to lack of permission – njuffa Aug 23 '14 at 02:23
  • @RobertCrovella Thank you for your reply. I added my simplified full code on my post. – user3910910 Aug 23 '14 at 02:35
  • @njuffa Thank you for your reply, I added my code on my question. I have 5.0 version cuda, I think it's not old. and I have the root privilege on my system. – user3910910 Aug 23 '14 at 02:38
  • 1
    @user3910910 What happens when you check the return status of _every_ CUDA API call? Are you able to allocate GPU memory with `cudaMalloc`? What OS are you running on? What GPU do you have in the system? What is your driver version? A current driver for Windows would be 340.52, for example. – njuffa Aug 23 '14 at 03:47
  • @njuffa I just checked it, it's weird.. every CUDA API calls, including `cudaMalloc`, are returning 'out of memory' error except `cudaSetDevice(0)`. I'm working on Ubuntu14.04, my GPU is GeForce GTX 580, driver version is 304.54. – user3910910 Aug 23 '14 at 04:34
  • @njuffa Oh sorry, my OS version is Debian GNU/Linux 6.0, not Ubuntu. – user3910910 Aug 23 '14 at 04:46
  • @user3910910 Do you see the `/dev/nvidia*` device files? Does `nvidia-smi -q` report the GPU? – njuffa Aug 23 '14 at 04:54
  • @njuffa I see /dev/nvidia0 and /dev/nvidiact1, nvidia-smi -q works. – user3910910 Aug 23 '14 at 05:28

1 Answers1

3

I just rebooted my system, and the error changed :

me@me:~$ nvidia-smi -q
NVIDIA: could not open the device file /dev/nvidiactl (No such file or directory).
NVIDIA-SMI has failed because it couldn't communicate with NVIDIA driver. Make sure that latest NVIDIA driver is installed and running.

Sorry for my unconsciousness, I'll finish this thread because it became another problem. Thank you for your replies.

user3910910
  • 79
  • 1
  • 6
  • 1
    run `nvidia-smi` as root. It should clear up this issue you are showing now. Perhaps you should read the [linux getting started guide](http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html#abstract). – Robert Crovella Aug 23 '14 at 13:09