Problem with Qt 5.4 and CUDA interoperabilitly

Hi All.

I am trying to implement OpenGL/CUDA interoperability on a Jetson TK1 (R21.3) with QOpenGLWidget and Qt 5.4.1. I use the same approach as described in

By the way, according to the lastest CUDA programming guide the call to cudaGLSetGLDevice() is not needed anymore. But the problem exists either way. Interestingly when using cudaGLSetGLDevice(), also any subsequent cudaMalloc fails with segfault.

In the meantime for testing I have stripped down my initializeGL() to minimal code:


cudaError_t err;
err = cudaSetDevice(0);
if ( err != cudaSuccess ) {
    QMessageBox::critical(NULL, "Error", "cudaSetDevice failed");

glGenBuffers(1, &m_pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 768 * 768 * sizeof(GLubyte) * 4, NULL, GL_DYNAMIC_COPY);

err = cudaGraphicsGLRegisterBuffer(&_pcudagl_pbo_resource, m_pbo, cudaGraphicsMapFlagsNone);

QMessageBox::critical(NULL, "Error", "Here");

I have the following member variables in the class:

GLuint  m_pbo;
cudaGraphicsResource_t _pcudagl_pbo_resource = NULL;

The function cudaGraphicsGLRegisterBuffer() crashes with a segmentation fault. m_pbo gets set to 1 by glGenBuffers();

Does anybody have an idea what causes this issue? Any tips to solve it?

So which of the -opengl option you configure?
-opengl es2 or -opengl desktop (default setting)

I’ve used -opengl es2

I’ve solved it.
The issue was related to the wrong being used. In fact mesa-egl overwrites the tegra-egl in /usr/lib/arm-linux-gnueabihf

See also:

Replacing the link back to tegra-egl version fixed it.

This also happens if you follow the QT5 build from git instructions. apt-get build-dep qt5-defaults overwrites tegra gl files with mesa in arm-linux-gnueabihf

If you don’t use the build-dep method, but install the deps listed manually you should be ok. Or you can just change the symlinks in /usr/lib/arm-linux-gnueabihf so that the files in the tegra folder are linked.