In my OptiX program, I added many printf statements in .cu file for debugging. When the program runs, there’s a 20%-30% chance of encountering the following error:
CUDAOutputBuffer destructor caught exception: CUDA call (cudaFree( reinterpret_cast<void*>( m_device_pixels ) ) ) failed with error: 'an illegal memory access was encountered' (D:\GPUProject\SDK\sutil/CUDAOutputBuffer.h:139)
Caught exception: CUDA error on synchronize with error 'an illegal memory access was encountered'
However, if I comment out all the printf statements, this error never occurs. Does OptiX has certain restrictions on the use of printf? For example, does it allow only a certain number of printf statements?
OptiX is subject to the CUDA limits, and CUDA does have restrictions on printf, described here: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#formatted-output. There is a fixed buffer size for printf data, currently defaulting to 1 MB according to that link. To increase the size you can look into using cudaDeviceSetLimit(cudaLimitPrintfFifoSize, size_t size).
Usually exceeding that buffer only results in output being truncated, and your error looks like out of bounds memory access. That might be caused by something more subtle than exceeding the printf buffer size, perhaps too many arguments or arguments that are different sizes than printf understands.