 #include <cuda_runtime_api.h>
 #include <glad/gl.h>
 #include <GLFW/glfw3.h>
+#include <cuda_gl_interop.h>
 
 #include <cmath>
 #include <cassert>

    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    CHECK_GL;


    glfwSwapBuffers(win);
    glfwPollEvents();

  glfwMakeContextCurrent(win);
  gladLoadGL(glfwGetProcAddress);

  unsigned int deviceCount;
  CHECKED_CUDA(cudaGLGetDevices(&deviceCount, nullptr, 0, cudaGLDeviceListAll));
  if (deviceCount == 0) {
    fprintf(stderr, "No CUDA-enabled devices available.");
    return EXIT_FAILURE;
  }
  std::vector<int> devices(deviceCount);
  CHECKED_CUDA(cudaGLGetDevices(&deviceCount, devices.data(), deviceCount, cudaGLDeviceListAll));

  bool found = false;
  for (unsigned k = 0; k < deviceCount; k++) {
    int i = devices[k];
    cudaDeviceProp dev_prop;
    cudaGetDeviceProperties(&dev_prop, i);
    fprintf(stderr, "%c[%i] %s cap=%d.%d\n", i == deviceIndex ? '*' : ' ', i, dev_prop.name, dev_prop.major, dev_prop.minor);
    if (i == deviceIndex) {
      found = true;
    }
  }
  if (!found) {
    fprintf(stderr, "Illegal CUDA device index %d\n", deviceIndex);
    return EXIT_FAILURE;
  }
