-1

I am trying to allocate a large amount of memory on GPU using cudaMalloc: cudaMalloc((void**)&count_d, N*sizeof(long)); with

unsigned long N = 999999999L;

I got an error message an that place so the question is if I am allocating too much memory or am doing something else wrong.

The error message what I get :

CUDA error : an illegal memory access was encountered (77)
talonmies
  • 70,661
  • 34
  • 192
  • 269
Monica
  • 1,030
  • 3
  • 17
  • 37
  • 1
    Depends, do you have 4 GB of space on your GPU? – alter_igel Sep 23 '18 at 01:39
  • 1
    Probably worth a read: [What is the canonical way to check for errors using the CUDA runtime API?](https://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api) – alter_igel Sep 23 '18 at 01:40
  • @alter igel. Indeed, thre is 4GB space on GPU. I have used an illegal memory access was encountered (77). I have used the API function to check it: cudaSuccess != cudaMalloc( &count_d, N*sizeof(long), but the error was: an illegal memory access was encountered (77). Do you know how I can check how much memory I'm allocating in bytes? – Monica Sep 23 '18 at 02:01
  • More useful to post the exact error message than only describe it. – chux - Reinstate Monica Sep 23 '18 at 02:06
  • @chux Just added – Monica Sep 23 '18 at 02:08
  • 2
    Please take the time to read some documentation https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__MEMORY.html#group__CUDART__MEMORY_1g37d37965bfb4803b6d4e59ff26856356 . That error doesn't come from cudaMalloc, it comes from something earlier in your code, probably a kernel – talonmies Sep 23 '18 at 03:26

1 Answers1

1

As @talonmies said, and as the cudaMalloc() documentation tells you, calling cudaMalloc() cannot trigger an "illegal memory access" error - that's about an illegal access by device code. (Host-side code making illegal memory accesses results in a SIGSEGV signal on Unix or a Protection Fault on Windows).

So how is it possible you're seeing this error after your cudaMalloc()? Simple: It happened earlier, and you simply weren't checking for errors before; or you weren't synchronizing your streams to have pending kernels executed.

Finally, consider following the link @alterIgel posted as a comment, to read about proper error checking of CUDA API calls.

einpoklum
  • 118,144
  • 57
  • 340
  • 684