vendredi 29 janvier 2016

How to unit test OpenGL on EC2

Both my local computer and EC2 server is on Ubuntu 14.04. Suppose I am testing a cuda opengl interop code as below.

Test.cu

#include <iostream>

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <cuda_gl_interop.h>

__global__ static void CUDAKernelTEST(float *data){
  const int x  = blockIdx.x * blockDim.x + threadIdx.x;
  const int y  = blockIdx.y * blockDim.y + threadIdx.y;
  const int mx = gridDim.x * blockDim.x;

  data[y * mx + x] = 0.5;
}

GLFWwindow *glfw_window_;

void Setup(){
  if (!glfwInit()) exit(EXIT_FAILURE);

  glfwWindowHint(GLFW_VISIBLE, GL_FALSE);

  glfw_window_ = glfwCreateWindow(10, 10, "", NULL, NULL);

  if (!glfw_window_) glfwTerminate();

  glfwMakeContextCurrent(glfw_window_);

  glewExperimental = GL_TRUE;
  if (glewInit() != GLEW_OK) exit(EXIT_FAILURE);
}

void TearDown(){
  glfwDestroyWindow(glfw_window_);
  glfwTerminate();
}

int main(){
  Setup();

  GLuint id;
  glGenBuffers(1, &id);
  glBindBuffer(GL_ARRAY_BUFFER, id);
  glBufferData(GL_ARRAY_BUFFER, 3 * 24 * sizeof(GLfloat), 0, GL_STATIC_DRAW);
  cudaGraphicsResource *vbo_res;
  cudaGraphicsGLRegisterBuffer(&vbo_res, id, cudaGraphicsMapFlagsWriteDiscard);
  cudaGraphicsMapResources(1, &vbo_res, 0);
  float *test;
  size_t size;
  cudaGraphicsResourceGetMappedPointer(
  reinterpret_cast<void **>(&test), &size, vbo_res);
  dim3 blks(1, 1);
  dim3 threads(72, 1);
  CUDAKernelTEST<<<blks, threads>>>(test);
  cudaDeviceSynchronize();
  cudaGraphicsUnmapResources(1, &vbo_res, 0);

  // do some more with OpenGL

  std::cout << "you passed the test" << std::endl;

  TearDown();

  return 0;
}

The current approach is create a hidden window and a context. The code compiles and runs fine on my local machine. However, glfwInit() returns GL_FALSE when run on EC2. If I log the messages sent to the error callback, it shows "X11: The DISPLAY environment variable is missing", which looks like it needs a display monitor to be connected in order for it work.

I tried replacing the Setup and TearDown section from GLFW into SDL or GLX and it returns similar error seemingly also requiring a display monitor attached.

I also try running the code with Xvfb and Xdummy which is supposedly to faked a monitor but I got error message from Xvfb "Xlib: extension "GLX" missing on display ":99", and from Xdummy "Fatal server error: (EE) no screens found(EE)"

I can't be the first one attempting to unit test opengl related code on EC2, but I can't find any solutions after googling around. Please advice, thank you so much.

Aucun commentaire:

Enregistrer un commentaire