You can, but it’s going to require a bunch of work including C/C++ code.


You need render to a texture using pyglet or glumpy. Get the texture ID (an int)


Use the CUDA OpenGL API to register the texture: https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__OPENGL.html 40


Use the CUDA Graphics API to bind the resource to a pointer. https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__INTEROP.html#group__CUDART__INTEROP 19


Either cudaMemcpy that pointer into a Tensor’s data_ptr() or use torch::from_blob to wrap it as a Tensor.


You’ll also need to call the appropriate unregister functions in destruction and make sure that the texture is in a matching format as the Tensor (i.e. float32 vs. int8)