13 Replies Latest reply: Nov 10, 2013 10:53 PM by himanshu.gautam RSS

Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!

lucasribeiro Newbie
Currently Being Moderated

Hello guys,

 

I can write data to cl::BufferGL variables (on GPU) and use it to draw, but I got wrong values when reading back to host. I have ran a couple examples from AMD SDK, including GL_CL interop, and is all ok. I can read and write cl::Buffer, i.e., copy from host to device and copy from device to host.

 

Code hosted at lucasribeiroufrj/sph-project · GitHub.

 

The program is written using:

- C++

- Ubuntu 12.06 64 bits, kernel 3.2.0-29-generic

- OpenCL 1.2

- Driver 1124.2 (Binary driver from AMD, Catalyst 13.4)

- AMD APPSDK v2.8

- OpenGL Version: 4.2.12217

- Glew

- Freeglut

 

The problematic code:

// Terminates OpenCL commands
cl_int status = 0;
status = clFinish( (cq)() );
if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__); }

// Create Vertex buffer object
GLint number = 5;
GLuint buffer;
CHk_ERR( glGenBuffers( 1, &buffer ));
CHk_ERR( glBindBuffer( GL_ARRAY_BUFFER, buffer ) );

// initialize buffer object
GLsizeiptr size = static_cast<GLsizeiptr>(sizeof(number));
const GLvoid * data = static_cast<const GLvoid *>(&number);
CHk_ERR( glBufferData( GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW) );
CHk_ERR( glBindBuffer(GL_ARRAY_BUFFER, 0) );
glFinish();

if ( glGetError() != GL_NO_ERROR ) { printf("File: %s:%d\n", __FILE__, __LINE__); }

// create OpenCL buffer from GL VBO
cl_mem mem = clCreateFromGLBuffer( (context)(), CL_MEM_READ_WRITE, buffer, &status );
if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__); }

// Acquire OpenCL memory objects that have been created from OpenGL objects
if ( clEnqueueAcquireGLObjects( (cq)(), 1, &(mem), 0, NULL, NULL ) != CL_SUCCESS ){
  std::cout << "ERROR!";
}

// Read buffer
GLint value;
cq.enqueueReadBuffer( mem, CL_TRUE, 0, size, &value );
std::cout << "Value: " << value << std::endl;

 

Any help is appreciated!!

 

Message was edited by: Lucas Azevedo

  • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
    himanshu.gautam Master
    Currently Being Moderated

    Hi could you please provide us the test case/sample code to test here. also you can try executing the same in the latest driver ie catalyst 13.8 and let us know the result. If it is the same result probably will check here.

    Regards

    Himanshu , Bruhaspati

    --------------------------------

    The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied

  • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
    lucasribeiro Newbie
    Currently Being Moderated

    I've created a repository at https://github.com/lucasribeiroufrj/sph-project. I'm going to install the 13.8 driver and test it again. But do i have to install SDK 2.8.1 as well?

     

    Thanks.

  • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
    himanshu.gautam Master
    Currently Being Moderated

    Can you try doing a "clFinish" before doing a ReadBuffer...?

    Regards

    Himanshu , Bruhaspati

    --------------------------------

    The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied

    • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
      himanshu.gautam Master
      Currently Being Moderated

      Lucas,

      I tried compiling code....I have not had success...

      I installed clogs 1.0.3 and then it asked for doxygen, boost and so on..

      This is not going to work.

       

      If you can isolate the problem to simple compilable code fragment, please post it here.

      Use the advanced editor (top right in faded color) to attach files.

      I can test it here and let you know of ...

      Thanks,

      Bruhaspati

      Regards

      Himanshu , Bruhaspati

      --------------------------------

      The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied

      • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
        lucasribeiro Newbie
        Currently Being Moderated

        Hello Bruhaspati

        I could not solve the problem yet. The code was running fine on my old HD6790 and still runs fine on a nvidia video card (video on youtube showing a simulation done with the code). The problem appeared when I updated to a GCN´s architecture.
        In relation to reproducing the problem, It´s gonna take a while for me to isolate the problem. So, as soon as I get it done, I´ll write it down here.


        Thanks,




        • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
          himanshu.gautam Master
          Currently Being Moderated

          Sure, Will wait for your post..

          And, Congrats on your successful youtube demo!

          -

          Bruhaspati

          Regards

          Himanshu , Bruhaspati

          --------------------------------

          The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied

          • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
            lucasribeiro Newbie
            Currently Being Moderated

            Hi Bruhaspati,

             

            Could you please take a look at the code fragment below and point out what is wrong, or at least an insight. I did not have time to isolate the problem yet.

                            // Terminates OpenCL commands

                            cl_int status = 0;

                            status =  clFinish( (cq)() );

                            if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

             

                            // Create Vertex buffer object

                            typedef GLfloat NumType;

                            NumType number = 50;

                            GLuint buffer;

                            CHk_ERR( glGenBuffers( 1, &buffer ));

                            CHk_ERR( glBindBuffer( GL_ARRAY_BUFFER, buffer ) );

             

                            // initialize buffer object

                            GLsizeiptr     size = static_cast<GLsizeiptr>(sizeof(number));

                            const GLvoid * data = static_cast<const GLvoid *>(&number);

                            CHk_ERR( glBufferData( GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW) );

             

                            // Check the size of the created buffer

                            GLint createdDataSize;

                            glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &createdDataSize);

                            if ( glGetError() != GL_NO_ERROR ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

                            if ( createdDataSize != static_cast<NumType>(size) ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

             

                            // Get the  data back just to test if it was really written

                            NumType dataDownloaded = 0;

                            CHk_ERR( glGetBufferSubData( GL_ARRAY_BUFFER, 0, size, &dataDownloaded ) );

                            std::cout << "Value (through GL API): " << dataDownloaded << std::endl;

                            glFinish();

             

                            // create OpenCL buffer from GL VBO

                            cl_mem mem = clCreateFromGLBuffer( (context)(), CL_MEM_READ_WRITE, buffer, &status );

                            if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

             

                            // Acquire OpenCL memory objects that have been created from OpenGL objects

                            status = clEnqueueAcquireGLObjects( (cq)(), 1, &(mem), 0, 0, NULL );

                            if ( status != CL_SUCCESS ){

                                std::cout << "ERROR!";

                            }

                            clFinish((cq)());

             

                            // Write buffer using OpenCL API

                            NumType value = 35;

                            status = clEnqueueWriteBuffer( (cq)(), mem, CL_TRUE, 0, size, &value, 0, 0, NULL);

                            if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

                            clFinish((cq)());

             

                            // Read buffer using OpenCL API

                            value = 4;

                            status = clEnqueueReadBuffer( (cq)(), mem, CL_TRUE, 0, size, &value, 0, 0, NULL );

                            if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__);  }

                            std::cout << "Value (through CL API): " << value << std::endl;

             

                            // Read buffer using OpenGL API

                            CHk_ERR( glGetBufferSubData( GL_ARRAY_BUFFER, 0, size, &dataDownloaded ) );

                            std::cout << "Value (through GL API): " << dataDownloaded << std::endl;

                            glFinish();

             

            Running this code, I get the following output:

            Value (through GL API): 50

            Value (through CL API): -8.8224e+18

            Value (through GL API): 50

             

            Thanks,
            Lucas Ribeiro

            • Re: Getting wrong values returned from  cl::BufferGL after a upgrade from HD6790 to HD7850!!
              himanshu.gautam Master
              Currently Being Moderated

              Hi

              As i seen the sample OpenCL-GL program the flow is fine. but i have doubt inusing CLFinish(). Could you please comment the two clFinish() function mentioned before writing and reading the OpenCL buffer.

              I am not an xpert in OpenGL. I am just doubting.

               

              Check and let me know . If you find any other solutions also please post here.

               

              Thanks

              Regards

              Himanshu , Bruhaspati

              --------------------------------

              The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions and typographical errors. Links to third party sites are for convenience only, and no endorsement is implied

More Like This

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points