Using enqueueFillBuffer in openCL 2.0 produce garbage

I used the code below

 cl::Event copyEvent;
  cl::Event prolEvent;
  T value = 0;
   try
  {
    queue.enqueueFillBuffer(intermediateBuffer, &value, 0,
                        distDeviceWidth * distDeviceHeight * distDeviceDepth * sizeof(T),
                        NULL, &copyEvent);
  }catch (const cl::Error& error)
  {
    std::cout << "  -> Prolongation class, Problem in enqueue fill buffer" << std::endl;
    std::cout << "  -> " << getErrorString(error) << std::endl;
    exit(0);
  }

  try
  {
    queue.finish();
  }catch (const cl::Error& error)
  {
    std::cout << "  -> Prolongation class, Problem in finishing fill buffer" << std::endl;
    std::cout << "  -> " << getErrorString(error) << std::endl;
    exit(0);
  }
  copyEvent.wait();

But when I read the data from device and print it on host, The function enqueueFillBuffer generate garbage. I don’t know why. I build the data with openCL 2.0.

Is this correct?

    queue.enqueueFillBuffer(intermediateBuffer, &value, ...

Since enqueueFillBuffer is:

    template<typename PatternType>
    cl_int enqueueFillBuffer(
        const Buffer& buffer,
        PatternType pattern,
        size_type offset,
        size_type size,
        const vector<Event>* events = NULL,
        Event* event = NULL) const

I think you just want to pass value, and not &value?

@bashbaug Thanks for the reply. Yes, I made a mistake and I confused openCL C library with C++ binding.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.