AnsweredAssumed Answered

clEnqueueMigrateMemObjects vs cl::CommandQueue::enqueueMigrateMemObjects

Question asked by Meteorhead on Jan 3, 2013
Latest reply on Jan 8, 2013 by Meteorhead

Hi!

 

I have been tweaking the code I recently attached in another topic, and have come cross a problem where the C API works perfectly fine, whereas the C++ wrapper always fails. The error code is -38 which corresponds to CL_INVALID_COMMAND_QUEUE, and the spec says:

CL_INVALID_COMMAND_QUEUE if command_queue is not a valid command_queue.

 

Now, I know for sure that the command_queue is alright, otherwise everything else would fail afterwards. Since there is a finish on the queue right after the command is issued, no such problem can occur, where something gets deleted on the stack while the operation is still in progress. Everything that is in memory stays there until the operation finishes. If I obtain all the C handlers from the warpper objects, and call the old C API, everything works fine, but the wrapper function corresponding to the same functionality fails. I checked cl.hpp to see what it does differently, but I could not find my mistake. It seems to do the correct stuff, so the problem must be on my side. What am I doing wrong?

 

    std::vector<cl::Buffer> input1_buffs(devices.size()), input2_buffs(devices.size()), output_buffs(devices.size());
    for(unsigned int i = 0 ; i < devices.size() ; ++i)
    {
        cl_buffer_region region;
        region.origin = i*batch_size;
        region.size = batch_size;
        try
        {
            input1_buffs.at(i) = input1_buffer.createSubBuffer(CL_MEM_READ_ONLY, CL_BUFFER_CREATE_TYPE_REGION, &region);
            input2_buffs.at(i) = input2_buffer.createSubBuffer(CL_MEM_READ_ONLY, CL_BUFFER_CREATE_TYPE_REGION, &region);
            output_buffs.at(i) = output_buffer.createSubBuffer(CL_MEM_WRITE_ONLY,CL_BUFFER_CREATE_TYPE_REGION, &region);

            // A little C API (dunno why the wrapper does not work)
            cl_mem send[3] = {input1_buffs.at(i)(), input2_buffs.at(i)(), output_buffs.at(i)()};
            cl_int error = CL_SUCCESS;
            clEnqueueMigrateMemObjects(queues.at(i)(), 3, send, NULL, 0, NULL, NULL);
            clFinish(queues.at(i)());
            if(error != CL_SUCCESS) {std::cerr << "clEnqueueMigrateMemObjects(" << error << ")" << std::endl; return EXIT_FAILURE;}
            
            // C++ wrapper that does not seem to work
            std::vector<cl::Memory> send(3);
            send.push_back(input1_buffs.at(i));
            send.push_back(input2_buffs.at(i));
            send.push_back(output_buffs.at(i));
            queues.at(i).enqueueMigrateMemObjects(send, NULL, NULL, NULL);
            queues.at(i).finish();
            
        }
        catch(cl::Error err) {std::cerr << err.what() << "(" << err.err() << ")" << std::endl; return EXIT_FAILURE;}
    }

 

A little help would be apreciated. (Naturally not both parts of the code are present at the same time)

Outcomes