Skip to content
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

CUDA error at Mandelbrot.cpp:916 #229

Open
blastwave opened this issue Sep 23, 2023 · 2 comments
Open

CUDA error at Mandelbrot.cpp:916 #229

blastwave opened this issue Sep 23, 2023 · 2 comments

Comments

@blastwave
Copy link

The sample code for Mandelbrot has a bug at line 916 : 

t$ 
t$ ldd Mandelbrot
        linux-vdso.so.1 (0x00007ffc9f3f9000)
        libGL.so.1 => /usr/lib/x86_64-linux-gnu/libGL.so.1 (0x00007fdbf674e000)
        libglut.so.3 => /usr/lib/x86_64-linux-gnu/libglut.so.3 (0x00007fdbf6701000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fdbf66f7000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fdbf66d5000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fdbf66cf000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fdbf6502000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fdbf64e6000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdbf6312000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fdbf68ba000)
        libGLdispatch.so.0 => /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0 (0x00007fdbf625a000)
        libGLX.so.0 => /usr/lib/x86_64-linux-gnu/libGLX.so.0 (0x00007fdbf6226000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fdbf60e3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fdbf5f9f000)
        libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007fdbf5f8b000)
        libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fdbf5c00000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fdbf5f60000)
        libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fdbf5f4b000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fdbf5f46000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fdbf5800000)
        libbsd.so.0 => /usr/lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fdbf5f2d000)
        libmd.so.0 => /usr/lib/x86_64-linux-gnu/libmd.so.0 (0x00007fdbf5f20000)
t$ 
t$ ./Mandelbrot 
[CUDA Mandelbrot/Julia Set] - Starting...
GPU Device 0: "Pascal" with compute capability 6.0

Data initialization done.
Initializing GLUT...
OpenGL window created.
Creating GL texture...
Texture created.
Creating PBO...
CUDA error at Mandelbrot.cpp:916 code=999(cudaErrorUnknown) "cudaGraphicsGLRegisterBuffer( &cuda_pbo_resource, gl_PBO, cudaGraphicsMapFlagsWriteDiscard)" 
t$ 
t$ 

Seems overly convoluted pile of code just for a trivial Mandelbrot :  

000870
000871  void initOpenGLBuffers(int w, int h) {
000872    // delete old buffers
000873    if (h_Src) {
000874      free(h_Src);
000875      h_Src = 0;
000876    }
000877
000878    if (gl_Tex) {
000879      glDeleteTextures(1, &gl_Tex);
000880      gl_Tex = 0;
000881    }
000882
000883    if (gl_PBO) {
000884      // DEPRECATED: checkCudaErrors(cudaGLUnregisterBufferObject(gl_PBO));
000885      cudaGraphicsUnregisterResource(cuda_pbo_resource);
000886      glDeleteBuffers(1, &gl_PBO);
000887      gl_PBO = 0;
000888    }
000889
000890    // allocate new buffers
000891    h_Src = (uchar4 *)malloc(w * h * 4);
000892
000893    printf("Creating GL texture...\n");
000894    glEnable(GL_TEXTURE_2D);
000895    glGenTextures(1, &gl_Tex);
000896    glBindTexture(GL_TEXTURE_2D, gl_Tex);
000897    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
000898    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
000899    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
000900    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
000901    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
000902                 h_Src);
000903    printf("Texture created.\n");
000904
000905    printf("Creating PBO...\n");
000906    glGenBuffers(1, &gl_PBO);
000907    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, gl_PBO);
000908    glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, w * h * 4, h_Src, GL_STREAM_COPY);
000909    // While a PBO is registered to CUDA, it can't be used
000910    // as the destination for OpenGL drawing calls.
000911    // But in our particular case OpenGL is only used
000912    // to display the content of the PBO, specified by CUDA kernels,
000913    // so we need to register/unregister it only once.
000914
000915    // DEPRECATED: checkCudaErrors( cudaGLRegisterBufferObject(gl_PBO) );
000916    checkCudaErrors(cudaGraphicsGLRegisterBuffer(
000917        &cuda_pbo_resource, gl_PBO, cudaGraphicsMapFlagsWriteDiscard));
000918    printf("PBO created.\n");
000919
000920    // load shader program
000921    gl_Shader = compileASMShader(GL_FRAGMENT_PROGRAM_ARB, shader_code);
000922  }
000923



@shakes76
Copy link

shakes76 commented Mar 5, 2024

Can confirm I get this error for Ubuntu 22.04 and CUDA 12.3. To even get this far I had to hard code default paths for libGL from where the drivers are installed into findlibgl.mk file to build it. Perhaps the correct GL libs are not being used?

@shakes76
Copy link

shakes76 commented Mar 5, 2024

Found my issue. You need to use NVIDIA Graphics mode on your laptop, other modes, even Hybrid will not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants