cudaMalloc always gives out of memory

2019-07-07 10:03发布

I'm facing a simple problem, where all my calls to cudaMalloc fail, giving me an out of memory error, even if its just a single byte I'm allocating.

The cuda device is available and there is also a lot of memory available (bot checked with the corresponding calls).

Any idea what the problem could be?

2条回答
萌系小妹纸
2楼-- · 2019-07-07 10:32

Thank you everybody for your help.

The problem was not really with the cudaMalloc itself but it shadowed the real problem which was due to the initialisation of cuda which seemed to fail.

Because the first call to cuda was in a separate Thread I did'nt have a GLContext available, leading to failures. I needed to make sure that I initialised cuda by a dummy malloc in the main thread after the initialisation of the context.

查看更多
贪生不怕死
3楼-- · 2019-07-07 10:38

Please try to call cudaSetDevice(), then cudaDeviceSynchronize() and then cudaThreadSynchronize() at the beginning of the code itself.

cudaSetDevice(0) if there is only one device. by default the CUDA run time will initialize the device 0.

cudaSetDevice(0);
cudaDeviceSynchronize();
cudaThreadSynchronize();

Please reply back your observation. If still it is getting failed, please specify the OS, architecture, CUDA SDK version, CUDA driver version. if possible please provide the code/code snippet which is being failed.

查看更多
登录 后发表回答