yoyoberenguer / PygameShader

2D Game texture special effects
GNU General Public License v3.0
23 stars 0 forks source link

bloom_gpu gives RuntimeError #9

Open derUli opened 5 months ago

derUli commented 5 months ago

Describe the bug If I call the bloom_gpu method my game freezes for some seconds and then i get a RuntimeError.

To Reproduce Steps to reproduce the behavior:

bloom_gpu(surf, threshold_ = 107, fast_=True, flag_ = pygame.BLEND_RGB_ADD, factor_ = 2)

surf is my display surface.

../../util_ptx.cuh(38): warning: util_type.cuh: [jitify] File not found
../../util_ptx.cuh(41): warning: util_debug.cuh: [jitify] File not found
../../thread/thread_load.cuh(40): warning: ../util_ptx.cuh: [jitify] File not found
---------------------------------------------------
--- JIT compile log for cupy_jitify_exercise ---
---------------------------------------------------
cub/util_cpp_dialect.cuh(143): warning #161-D: unrecognized #pragma
       CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11);
       ^

Remark: The warnings can be suppressed with "-diag-suppress <warning-number>"

std/barrier(16): catastrophic error: #error directive: "CUDA synchronization primitives are only supported for sm_70 and up."
  #  error "CUDA synchronization primitives are only supported for sm_70 and up."
     ^

1 catastrophic error detected in the compilation of "cupy_jitify_exercise".
Compilation terminated.

---------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\uli\Documents\GitHub\grunzi\src\grunzi.py", line 104, in <module>
    game.start(component)
  File "C:\Users\uli\Documents\GitHub\grunzi\src\bootstrap\gamecontainer.py", line 99, in start
    self.mainloop()
  File "C:\Users\uli\Documents\GitHub\grunzi\src\bootstrap\gamecontainer.py", line 157, in mainloop
    self.draw()
  File "C:\Users\uli\Documents\GitHub\grunzi\src\bootstrap\gamecontainer.py", line 208, in draw
    self.current_component.draw(self.screen)
  File "C:\Users\uli\Documents\GitHub\grunzi\src\components\game\maingame.py", line 214, in draw
    col.draw(virtual_screen, x, y)
  File "C:\Users\uli\Documents\GitHub\grunzi\src\sprites\telescope.py", line 78, in draw
    self.player_state.show_detailed = self.draw_telescope_view(
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\Documents\GitHub\grunzi\src\sprites\telescope.py", line 131, in draw_telescope_view
    bloom_gpu(surf, threshold_ = 107, fast_=True, flag_ = pygame.BLEND_RGB_ADD, factor_ = 2)
  File "PygameShader\\shader_gpu.pyx", line 2110, in PygameShader.shader_gpu.bloom_gpu
  File "PygameShader\\shader_gpu.pyx", line 2239, in PygameShader.shader_gpu.bloom_gpu
  File "PygameShader\\shader_gpu.pyx", line 2033, in PygameShader.shader_gpu.gaussian_3x3_c
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupyx\scipy\ndimage\_filters.py", line 77, in convolve
    return _correlate_or_convolve(input, weights, output, mode, cval, origin,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupyx\scipy\ndimage\_filters.py", line 177, in _correlate_or_convolve
    output = _filters_core._call_kernel(kernel, input, weights, output,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupyx\scipy\ndimage\_filters_core.py", line 150, in _call_kernel
    kernel(*args)
  File "cupy\_core\_kernel.pyx", line 920, in cupy._core._kernel.ElementwiseKernel.__call__
  File "cupy\_core\_kernel.pyx", line 945, in cupy._core._kernel.ElementwiseKernel._get_elementwise_kernel
  File "cupy\_util.pyx", line 64, in cupy._util.memoize.decorator.ret
  File "cupy\_core\_kernel.pyx", line 728, in cupy._core._kernel._get_elementwise_kernel
  File "cupy\_core\_kernel.pyx", line 82, in cupy._core._kernel._get_simple_elementwise_kernel_from_code
  File "cupy\_core\core.pyx", line 2254, in cupy._core.core.compile_with_cache
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupy\cuda\compiler.py", line 484, in _compile_module_with_cache
    return _compile_with_cache_cuda(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupy\cuda\compiler.py", line 562, in _compile_with_cache_cuda
    ptx, mapping = compile_using_nvrtc(
                   ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupy\cuda\compiler.py", line 319, in compile_using_nvrtc
    return _compile(source, options, cu_path,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupy\cuda\compiler.py", line 284, in _compile
    options, headers, include_names = _jitify_prep(
                                      ^^^^^^^^^^^^^
  File "C:\Users\uli\AppData\Roaming\Python\Python311\site-packages\cupy\cuda\compiler.py", line 233, in _jitify_prep
    jitify._init_module()
  File "cupy\cuda\jitify.pyx", line 212, in cupy.cuda.jitify._init_module
  File "cupy\cuda\jitify.pyx", line 233, in cupy.cuda.jitify._init_module
  File "cupy\cuda\jitify.pyx", line 209, in cupy.cuda.jitify._init_cupy_headers
  File "cupy\cuda\jitify.pyx", line 192, in cupy.cuda.jitify._init_cupy_headers_from_scratch
  File "cupy\cuda\jitify.pyx", line 264, in cupy.cuda.jitify.jitify
RuntimeError: Runtime compilation failed

Expected behavior It should return a surface with the bloom effect applied.

Some maybe helpful details about my environment:

Windows 11 64-Bit GeForce GT 1030 (2GB VRAM) Python 3.11.6 pygame-ce 2.4.0 PygameShader 1.0.10 cupy-cuda12x 13.0.0

yoyoberenguer commented 4 months ago

Hello and thank you for reporting this, I believe that this issue is related to the cupy-cuda version used (cupy-cuda12x 13.0.0) and possibly some changes around __syncthreads() I will have to reproduce this issue somehow and check.

In the mean time could you please run a small python program with the following lines to have more info about the GPU capabilities.

 import PygameShader
 from PygameShader.shader_gpu import block_grid, cartoon_gpu, \
        get_gpu_info, block_and_grid_info

get_gpu_info()

You should get something similar to:

pygame 2.5.2 (SDL 2.28.3, Python 3.11.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
PygameShader version 1.0.10 
OPENMP True 
THREADS 16 
SCHEDULE static 
CUPY VERSION           : 9.6.0 
GPU MAX GRID PER BLOCK : 32
GPU FREE MEMORY : (mem=3513201460.000000, (3.272G))
GPU MAX MEMORY  : (mem=4294705152.000000, (4.0G ))
GPU PCI BUS ID  : (bus=0000:0F:00.0)
GPU CAPABILITY  : (capa=61   )

Have you tried any of the GPU demo included in the directory DEMO image

Do you have the same issue for all of them?

Kind Regards

derUli commented 4 months ago

pygame-ce 2.4.0 (SDL 2.28.5, Python 3.11.7)
PygameShader version 1.0.10
OPENMP True
THREADS 16
SCHEDULE static
CUPY VERSION           : 13.0.0
GPU MAX GRID PER BLOCK : 32
GPU FREE MEMORY : (mem=1715581543.000000, (1.598G))
GPU MAX MEMORY  : (mem=2147352576.000000, (2.0G ))
GPU PCI BUS ID  : (bus=0000:01:00.0)
GPU CAPABILITY  : (capa=61   )

Works:

Doesn't work

Traceback (most recent call last):
  File "C:\Users\uli\Downloads\PygameShader-main\PygameShader\Demo\GPU_cartoon.py", line 99, in <module>
    image = cartoon_gpu(
            ^^^^^^^^^^^^
  File "PygameShader\\shader_gpu.pyx", line 2395, in PygameShader.shader_gpu.cartoon_gpu
  File "PygameShader\\shader_gpu.pyx", line 2418, in PygameShader.shader_gpu.cartoon_gpu
  File "PygameShader\\shader_gpu.pyx", line 2525, in PygameShader.shader_gpu.cartoon_cupy
ValueError:
Cannot reference source pixels into a 3d array.
 a bytes-like object is required, not 'ndarray'
yoyoberenguer commented 4 months ago

Hi,

I believe that this issue is the version of CUDA toolkit install with your graphic card NVIDIA GT 1030 The cupy-cuda12x library installed mean that you have at least CUDA toolkit version 12.0 or over if not (you need the correct cup-cuda version installed). Example cupy-cuda11x for CUDA version 11.X My card works perfectly with CUDA toolkit version10.2 to 11.2 and I have a GTX 1050 Ti and cupy version 13.0. When I use version 12.0 I start to have problems compiling the shaders. Check your graphic card driver version and check on the web the appropriate CUDA toolkit compatible with your driver. I hope this helps

Kind Regards