I have verified that the problem is that the app is running inside of a Docker image. The program below reports CUDA_SUCCESS outside of Docker and CUDA_ERROR_OPERATING_SYSTEM inside of Docker.
Is there any way to register an OpenGL texture so it can be accessed by CUDA inside of desktop Docker??
cuGraphicsEGLRegisterImage
does not work on desktop. And, cuGraphicsGLRegisterImage
doesn’t work in Docker. So, what’s left? I’m stuck with CUDA 10.2 because my primary platform is Xavier.
//usr/bin/g++ $0 -I /usr/local/cuda/include -L/usr/local/cuda/lib64 -lcuda -lEGL -lGLESv2 && ./a.out && exit
#include "cuda.h"
#include "cuda_runtime.h"
#include "cudaEGL.h"
#include "cudaGL.h"
#include <GLES3/gl32.h>
#include <GLES2/gl2ext.h>
#include <EGL/eglext.h>
#include <stdio.h>
int main() {
cuInit(0);
CUdevice device;
cuDeviceGet(&device, 0);
CUcontext cudaContext;
cuDevicePrimaryCtxRetain(&cudaContext, device);
cuCtxPushCurrent(cudaContext);
EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(eglDisplay, nullptr, nullptr);
EGLContext eglContext;
{
EGLint configAttributes[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
EGLConfig config;
EGLint numConfigs;
eglChooseConfig(eglDisplay, configAttributes, &config, 1, &numConfigs);
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION, 3,
EGL_CONTEXT_MINOR_VERSION, 2,
EGL_NONE
};
eglContext = eglCreateContext(eglDisplay, config, EGL_NO_CONTEXT, contextAttributes);
}
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
GLenum oglError = glGetError();
if (oglError != GL_NO_ERROR) fprintf(stderr, "OGL Error %x\n", oglError);
CUgraphicsResource resource;
CUresult cudaError = cuGraphicsGLRegisterImage(&resource, texture, GL_TEXTURE_2D, 0); // CU_GRAPHICS_REGISTER_FLAGS_READ_ONLY
if (cudaError == CUDA_ERROR_OPERATING_SYSTEM) fprintf(stderr, "CUDA_ERROR_OPERATING_SYSTEM\n");
else if (cudaError == CUDA_SUCCESS) fprintf(stderr, "CUDA_SUCCESS\n");
else fprintf(stderr, "Other CUDA Error %d\n", cudaError);
return 0;
}