Chris Uchytil
2016-08-15 19:09:13 UTC
I am brand new to CUDA and OpenGL and I have found that tutorials and
resources on a lot of this material is rather scares or not straight
forward so I am hoping I can get some assistance here. I am working on a
project attempting to convert some CUDA and OpenGL C++ code over to Python.
The code is a basic Kernal that computes distance from a point (To emulate
light on a wall from a flashlight) and sends the calculated array to OpenGL
to display the light intensity. You can move your mouse/"Flashlight" around
to move the light around on the screen. I have been successful in
converting the Kernal code over to Python using the Numba python package.
What I am having trouble with is the Open GL Interoperability stuff. I
can't really find an info that describes the process of interop in a simple
fashion so I'm not really even sure what the setup process is. It sounds
like you need to create something called a pixel buffer and send that to
the kernal. From what I can tell the C++ code uses this simple function to
do this.
// texture and pixel objects
GLuint pbo = 0;
GLuint tex = 0
struct cudaGraphicsResource * cuda_pbo_resource;
void render() {
unchar4 *d_out = 0;
cudaGraphicsMapResources(1, &cuda_pbo_resource, 0);
cudaGraphicsResourceGetMappedPointer((void**)&d_out, NULL,
cuda_pbo_resource);
kernelLauncher(d_out, W, H, loc);
cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0);
}
I can't find any info that describes the python equivalent of
cudaGraphicsMapResources, cudaGraphicsResourceGetMappedPointer, and
cudaGraphicsUnmapResources. I've found a GL interop example by by Peter
Berrington (https://wiki.tiker.net/PyCuda/Examples/GlInterop) but it seems
to me to be overly complicated in how it creates PBO's and textures and
such when compared to the C++ code.
resources on a lot of this material is rather scares or not straight
forward so I am hoping I can get some assistance here. I am working on a
project attempting to convert some CUDA and OpenGL C++ code over to Python.
The code is a basic Kernal that computes distance from a point (To emulate
light on a wall from a flashlight) and sends the calculated array to OpenGL
to display the light intensity. You can move your mouse/"Flashlight" around
to move the light around on the screen. I have been successful in
converting the Kernal code over to Python using the Numba python package.
What I am having trouble with is the Open GL Interoperability stuff. I
can't really find an info that describes the process of interop in a simple
fashion so I'm not really even sure what the setup process is. It sounds
like you need to create something called a pixel buffer and send that to
the kernal. From what I can tell the C++ code uses this simple function to
do this.
// texture and pixel objects
GLuint pbo = 0;
GLuint tex = 0
struct cudaGraphicsResource * cuda_pbo_resource;
void render() {
unchar4 *d_out = 0;
cudaGraphicsMapResources(1, &cuda_pbo_resource, 0);
cudaGraphicsResourceGetMappedPointer((void**)&d_out, NULL,
cuda_pbo_resource);
kernelLauncher(d_out, W, H, loc);
cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0);
}
I can't find any info that describes the python equivalent of
cudaGraphicsMapResources, cudaGraphicsResourceGetMappedPointer, and
cudaGraphicsUnmapResources. I've found a GL interop example by by Peter
Berrington (https://wiki.tiker.net/PyCuda/Examples/GlInterop) but it seems
to me to be overly complicated in how it creates PBO's and textures and
such when compared to the C++ code.