
On Friday, May 9, 2025, Karl Semich <baffo32@gmail.com> wrote:
notes regarding possibly making graphics apis (wgpu?) have interoperable buffers with tensor libraries note: i think i already implemented this some years ago, probably for raw opengl or vulkan. dunno where that is
- i don't immediately see a way in wgpu to get a raw pointer - i heard opengl has a raw pointer function - i think wgpu uses opengl ES and vulkan 1657 1702 - because gles, vulkan, metal, direct3d, and anything else, have handles to their buffers, it's intuitive that they must be interoperable -- the handles would be passed. any underlying transformation of the handles to support interprocess use would be documented in the interprocess importer for the backend.
This gl-cuda interop code is from https://andreask.cs.illinois.edu/PyCuda/Examples/SobelFilter/ pbo_buffer = glGenBuffers(1) # generate 1 buffer reference glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_buffer) # binding to this buffer glBufferData(GL_PIXEL_UNPACK_BUFFER, imWidth*imHeight, pixels, GL_STREAM_DRAW) # Allocate the buffer bsize = glGetBufferParameteriv(GL_PIXEL_UNPACK_BUFFER, GL_BUFFER_SIZE) # Check allocated buffer size assert(bsize == imWidth*imHeight) glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0) # Unbind if ver2011: cuda_pbo_resource = pycuda.gl.RegisteredBuffer(int(pbo_buffer), cuda_gl.graphics_map_flags.WRITE_DISCARD) else: cuda_pbo_resource = cuda_gl.BufferObject(int(pbo_buffer)) # Mapping GLBuffer to cuda_resource