-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GpuMem() #44
Comments
Hi @Yves33 You can still get raw CUDA device pointer, though it's now available via Please follow VALI documentation on this topic: |
may be stupid, but among these fields, which ones gives me access to raw cuda ptr/buffer?
|
I beg your pardon, that's my bad. Latest VALI relies on That was the point I was trying to explain in my initial reply )) P. S. # 1920x1080 decoded picture form video file
surface_nv12 = decode_surface("/path/to/fullhd/file.mp4")
# Same picture converted to planar RGB
surface_rgb = to_rgb(surface_nv12)
# And the same picture once again, this time converted to YUV420
surface_yuv420 = to_yuv420(surface_nv12)
# Will output 1620
print(surface_nv12.PlanePtr().Height())
# Will output 3240
print(surface_nv12.PlanePtr().Height())
# Will output 1080
print(surface_yuv420.PlanePtr().Height()) It is completely counter-intuitive unless you are very familiar with various pixel formats memory layout and there's no way to verify parameter as simple as picture height without introducing additional API to P. P. S. |
@RomanArzumanyan I definitivelly advocate for getting back GpuMem() in SurfacePlane (As you stated, reintroducing is trivial, but I don't thing it's worth maintaining my own fork for that)
|
Hi @Yves33
Yeah, it was OK 15 years ago. Technology has gone a long way since then. IMO it's no longer a good design if OOP developer has to mess with pixel format and bit depth and CUDA memcpy only to export their picture into OpenGL Surface. Chunks of GPU memory are already there, the whole affair is a weird ritual ! Compare the old school # Export to PyTorch tensor.
surf_plane = rgb24_planar.PlanePtr()
img_tensor = pnvc.makefromDevicePtrUint8(
surf_plane.GpuMem(),
surf_plane.Width(),
surf_plane.Height(),
surf_plane.Pitch(),
surf_plane.ElemSize())
# This step is essential because rgb24_planar.PlanePtr() returns a simple
# 2D CUDA pitched memory allocation. Here we convert it the way
# pytorch expects it's tensor data to be arranged.
img_tensor.resize_(3, target_h, target_w) With DLPack: img_tensor = torch.from_dlpack(rgb24_planar) I don't want to resurrect the pixel format and bit depth mess. Probably, a layer of CUDA <> OpenGL glue hidden within Even better approach would be to implemet
That's not a goal of VALI project. There's no active VPF development going on for quite some time. Sooner or later, the paths will diverge. VALI exists on a shoestring budget, so adding a whole new facet which OpenGL (and graphics in general is) doesn't justify the effort in current circumstances. I have zero experience in it and won't be able to develop and maintain this part of codebase. If there's a strong demand from community backed up by active participation in development, testing and maintenance - that's a different story but so far 99% of user requests are related to everything Video and ML. Within current development resources budget I'll keep maintaining Video and ML requests. |
Hi, not totally convinced, but hey! you're the boss, and surely much more competent than I am regarding video/gpu (and I'm free to re_introduce GpuMem() ) |
Hi @Yves33 I'm not here to insist on my decisions disregarding the common sense. So let's do what: |
I'll try to go with your PR suggestion, although I still don't understand the point with Surface and SurfacePLane dimensions (which makes it difficult to propose some relevant unittest...)
In the meanwhile, found how to get pointer from Surface.PlanePtr(). Posting this simple snippet import ctypes
## wget https://github.com/dmlc/dlpack/blob/main/apps/numpy_dlpack/dlpack/dlpack.py
from dlpack import _c_str_dltensor, DLManagedTensor
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
def GpuMem(plane:SurfacePlane):
'''
retrieves the pointer to SurfacePlane GPU data
briefly adapted from adapted from https://github.com/dlpack/apps/numpy_dlpack/dlpack/to_numpy.py
stripped down version returning only pointer to GPU memory, to be used with pycuda.driver.Memcpy2D().set_src_device(...)
'''
pycapsule=plane.__dlpack__()
dl_managed_tensor = ctypes.pythonapi.PyCapsule_GetPointer(pycapsule, _c_str_dltensor)
dl_managed_tensor_ptr = ctypes.cast(dl_managed_tensor, ctypes.POINTER(DLManagedTensor))
return dl_managed_tensor_ptr.contents.dl_tensor.data |
Hi @Yves33
I don't think so, here's the code of constructor: VALI/src/TC/src/SurfacePlane.cpp Lines 120 to 130 in 820caea
And of the getter: VALI/src/TC/inc/SurfacePlane.hpp Lines 166 to 169 in 820caea
If you think you found a bug, please provide a MVP code snippet.
E. g. your RGB Also please note that for |
Hi, Did not express myself well. What I wanted to say is that, as you stated, SurfacePlane.Width and Height refer to the Buffer shape (depending on pixel format), and not to the size of the image. (I may be imprecise. It seems to me that it may be the case from the beginning...) Made a (very) simple PR to expose GpuMem() in SurfacePlane (and ONLY in surfacePlane). I can invest some more time on unittests, but need some more explanations of what you expect, as the PR does not modify anything to actual VALI behavior. |
Hi @Yves33
Sure thing. When you add Usually it's done by Device To Host memcpy and compare against ethalon. Or you can copy the same information to another data class which is known to be working fine and comparing memory obtained by You can follow this example: VALI/tests/test_PySurfaceConverter.py Line 154 in 820caea
The only difference is you don't need to do the color conversion, just upload your data to |
Thanks,, That's a lot clearer to me. Just have to go for it, now. Y |
Not really comfortable with Git. I think I deleted my previous pull request while trying to adapt to lastest API... |
Just wanted to throw another vote in for having the raw mem pointer exposed. Not all the libraries I use support dlpack, and there are times I also manipulate the memory with pycuda or cuda-python. |
Updated the PR to match with latest API |
Hi,
Trying to port the opengl example from VPF to VALI, it seems that GpuMem() is not accessible from python anymore.
Is it on purpose?
Y33
The text was updated successfully, but these errors were encountered: