NVIDIAGameWorks / kaolin-wisp

NVIDIA Kaolin Wisp is a PyTorch library powered by NVIDIA Kaolin Core to work with neural fields (including NeRFs, NGLOD, instant-ngp and VQAD).
Other
1.45k stars 132 forks source link

Is it possible to run APP GUI in WSL? #104

Closed wzy-99 closed 1 year ago

wzy-99 commented 1 year ago

Hello, I tried to run Kaolin-wisp with GUI app in WSL2.

I use X11 server on my Windows11 to display the window.

But it seems not to work.

I run the example as python3 main_demo.py --dataset-path /home/XXX/data/nerf_synthetic/lego.

[i] Using GLFW (GL 2.1)
Traceback (most recent call last):
  File "/home/XXX/codes/kaolin-wisp/examples/latent_nerf/main_demo.py", line 10, in <module>
    setup_cuda_context()  # Must be called before any torch operations take place
  File "/home/XXX/codes/kaolin-wisp/wisp/cuda_guard.py", line 39, in setup_cuda_context
    import pycuda.gl.autoinit
  File "/home/XXX/codes/pycuda/pycuda/gl/autoinit.py", line 10, in <module>
    context = make_default_context(lambda dev: cudagl.make_context(dev))
  File "/home/XXX/codes/pycuda/pycuda/tools.py", line 215, in make_default_context
    return ctx_maker(dev)
  File "/home/XXX/codes/pycuda/pycuda/gl/autoinit.py", line 10, in <lambda>
    context = make_default_context(lambda dev: cudagl.make_context(dev))
pycuda._driver.LogicError: cuGLCtxCreate failed: OS call failed or operation not supported on this OS

I just know the pycuda is used for display and it works at the GPU driver level.

For example, it will copy the RenderBuffer results to the screen buffer.

So, it is impossible to display the app window from WSL2, is right?

(I also tried to run Kaolin-wisp without GUI app in WSL2, and it works well.)

My device is GeForce 4090.

orperel commented 1 year ago

Hi @wzy-99 , I have an experimental PR for replacing pycuda with cuda-python directly. Can you please give this a go and see if it works? https://github.com/NVIDIAGameWorks/kaolin-wisp/pull/105

wzy-99 commented 1 year ago

It doesn't work for me.

loading data: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:04<00:00, 22.62it/s]
/home/XXX/miniconda3/lib/python3.10/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3190.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
2023-01-16 15:54:05,361|    INFO| Active LODs: [5, 6, 7, 8]
2023-01-16 15:54:15,718|    INFO| Built dual octree and trinkets
2023-01-16 15:54:15,718|    INFO| # Feature Vectors: 19431848
2023-01-16 15:54:16,108|    INFO| Pyramid:tensor([       1,        8,       64,      512,     4096,    32768,   262144,
         2097152, 16777216,        0], dtype=torch.int32)
2023-01-16 15:54:16,108|    INFO| Pyramid Dual: tensor([       8,       27,      125,      729,     4913,    35937,   274625,
         2146689, 16974593,        0], dtype=torch.int32)
2023-01-16 15:54:16,181|    INFO| Info: 

2023-01-16 15:54:16,181|    INFO| Training on /home/wzy/data/nerf_synthetic/lego
2023-01-16 15:54:16,181|    INFO| Total number of parameters: 97177430
2023-01-16 15:54:16,181|    INFO| Using NVIDIA GeForce RTX 4090 with CUDA v11.7
[i] Using PYGLFW_IMGUI (GL 2.1)
2023-01-16 15:54:17,022|    INFO| [i] Using PYGLFW_IMGUI (GL 2.1)
[i] Running at 60 frames/second
2023-01-16 15:54:17,079|    INFO| [i] Running at 60 frames/second
Traceback (most recent call last):
  File "/home/wzy/codes/kaolin-wisp/examples/latent_nerf/main_demo.py", line 121, in <module>
    app.run()  # Interactive Mode runs here indefinitely
  File "/home/wzy/codes/kaolin-wisp/wisp/renderer/app/wisp_app.py", line 233, in run
    app.run()   # App clock should always run as frequently as possible (background tasks should not be limited)
  File "/home/wzy/miniconda3/lib/python3.10/site-packages/glumpy/app/__init__.py", line 317, in run
    clock = __init__(clock=clock, framerate=framerate, backend=__backend__)
  File "/home/wzy/miniconda3/lib/python3.10/site-packages/glumpy/app/__init__.py", line 277, in __init__
    window.dispatch_event('on_resize', window._width, window._height)
  File "/home/wzy/miniconda3/lib/python3.10/site-packages/glumpy/app/window/event.py", line 396, in dispatch_event
    if getattr(self, event_type)(*args):
  File "/home/wzy/codes/kaolin-wisp/wisp/renderer/app/wisp_app.py", line 517, in on_resize
    tex, cuda_buffer = self._create_cugl_shared_texture(height, width, self.channel_depth)
  File "/home/wzy/codes/kaolin-wisp/wisp/renderer/app/wisp_app.py", line 308, in _create_cugl_shared_texture
    cuda_buffer = cuda_register_gl_image(image=int(tex.handle), target=tex.target)
  File "/home/wzy/codes/kaolin-wisp/wisp/renderer/core/cuda.py", line 58, in cuda_register_gl_image
    raise RuntimeError('Failed to register GL texture as a CUDA shared resource.')
RuntimeError: Failed to register GL texture as a CUDA shared resource.
Segmentation fault

I also printed the register_result.

(<CUresult.CUDA_ERROR_OPERATING_SYSTEM: 304>, <CUgraphicsResource 0x0>)

And the log of VcXsrv X Server is as the following:

winMultiWindowWMProc - Error code: 8 (Match), ID: 0x00200001, Major opcode: 12 (ConfigureWindow), Minor opcode: 0 ((null))
winMultiWindowWMProc - Error code: 3 (Window), ID: 0x00200007, Major opcode: 18 (ChangeProperty), Minor opcode: 0 ((null))
winMultiWindowWMProc - Error code: 3 (Window), ID: 0x00200007, Major opcode: 19 (DeleteProperty), Minor opcode: 0 ((null))
orperel commented 1 year ago

Thanks, that was helpful! A little research suggests iNGP had a similar issue due to broken cuda-gl interop on WSL: https://github.com/NVlabs/instant-ngp/issues/268

I've implemented a solution that doesn't use interop for WSL, can you please pull the latest from the PR branch and try again? Specifically, in WispApp for WSL we should have blitdevice2device=False (hopefully the is_wsl check is correct, I have no means of testing that): https://github.com/NVIDIAGameWorks/kaolin-wisp/pull/105/files#diff-d13f3ce350b22c0df28a364d45ab84fd0c5f7312f866591151c79ad61dde81eeR118

wzy-99 commented 1 year ago

image

It works! Thank you very much.