Skip to content

Commit

Permalink
move cgroup device check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed Jul 19, 2018
1 parent e68393f commit a51f90d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions renderer/gl/glContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,19 @@ EGLContext::EGLContext(Geometry win_size, int device): GLContext{win_size} {
cerr << "[EGL] Detected " << numDevices << " devices. Using device " << device << endl;
m_assert(device < numDevices);
eglDpy_ = eglGetPlatformDisplayEXT(EGL_PLATFORM_DEVICE_EXT, eglDevs[device], 0);

// cgroup may block our access to /dev/nvidiaX, but eglQueryDevices can still see them.
string dev = ssprintf("/dev/nvidia%d", device);
int ret = open(dev.c_str(), O_RDONLY);
if (ret == -1) {
error_exit(ssprintf("Cannot access %s! See README if you're inside cgroup/container.", dev.c_str()));
}
}

EGLint major, minor;

EGLBoolean succ = eglInitialize(eglDpy_, &major, &minor);
if (!succ) {
// cgroup may block our access to /dev/nvidiaX, but eglQueryDevices can still see them. This can cause a failure at eglInitialize
string dev = ssprintf("/dev/nvidia%d", device);
int ret = open(dev.c_str(), O_RDONLY);
if (ret == -1) {
error_exit(ssprintf("Cannot access %s, failed to initialize EGL display! See README if you're inside cgroup/container.", dev.c_str()));
}
error_exit("Failed to initialize EGL display!");
}
checkError(succ);
Expand Down

0 comments on commit a51f90d

Please sign in to comment.