Invalid global_argument size for kernel arg, clSetKernelArg() for kernel "(krnl name)", argument index 3

Viewed 14

I got into this error when trying to set args for a cpp kernel. What is said in the title is a type of problem, and the specific error is: Error calling err = krnls[i].setArg(3, dataSize), error code is: -51

I don't know where this question comes from, in fact I don't even know how to ask it for your help effectively. All I can do is paste the code that involves this parameter in order, hope it helps.

First, I defined the variable dataSize in main function:

int main(int argc, char* argv[]) {
    unsigned int dataSize =  256 * 1024 * 1024;
    ......
}

Subsequently, I referenced this one variable in vectors:

    std::vector<uint32_t, aligned_allocator<uint32_t> > source_in1(dataSize);
    std::vector<uint32_t, aligned_allocator<uint32_t> > source_in2(dataSize);
    std::vector<uint32_t, aligned_allocator<uint32_t> > source_sw_results(dataSize);

    std::vector<uint32_t, aligned_allocator<uint32_t> > source_hw_results[2];

    for (int i = 0; i < 2; i++) {
        source_hw_results[i].resize(dataSize);
    }

    std::generate(source_in1.begin(), source_in1.end(), std::rand);
    std::generate(source_in2.begin(), source_in2.end(), std::rand);

    for (size_t i = 0; i < dataSize; i++) {
        source_sw_results[i] = source_in1[i] + source_in2[i];
    }

Then, I also used the dataSize parameter in the process of creating the buffer

    for (int i = 0; i < NUM_BUFFER; i++){
    OCL_CHECK(err, inBufExt1[i] = cl::Buffer(context, CL_MEM_READ_ONLY  | CL_MEM_USE_HOST_PTR,
                                            sizeof(uint32_t) * dataSize, source_in1.data(), &err));
    OCL_CHECK(err, inBufExt2[i] = cl::Buffer(context, CL_MEM_READ_ONLY  | CL_MEM_USE_HOST_PTR,
                                            sizeof(uint32_t) * dataSize, source_in2.data(), &err));         
    OCL_CHECK(err, outBufExt[i]= cl::Buffer(context, CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR,
                                            sizeof(uint32_t) * dataSize, source_hw_results[i].data(), &err));
    }

Then came to the ERROR place:

for (int i = 0; i < NUM_KERNEL; i++) {
    int j = i % NUM_BUFFER;
    OCL_CHECK(err, err = krnls[i].setArg(0, inBufExt1[j]));
    OCL_CHECK(err, err = krnls[i].setArg(1, inBufExt2[j]));
    OCL_CHECK(err, err = krnls[i].setArg(2, outBufExt[j]));
    OCL_CHECK(err, err = krnls[i].setArg(3, dataSize));
    OCL_CHECK(err, err = krnls[i].setArg(4, num_times));
    }

In addition, this dataSize parameter is used in two places, which are to verify whether the calculation results of software and hardware are consistent, and to print the calculation results.


    for (int i = 0; i < NUM_BUFFER; i++) {
        match = verify(source_sw_results, source_hw_results[i], dataSize);
        if (!match) {
            std::cerr << "TEST FAILED" << std::endl;
            return EXIT_FAILURE;
        }
    }
    

    result = 4 * (float)dataSize * num_times * sizeof(uint32_t);

I've been tormented by this error for days, but I don't have any clue why this is happening. Hopefully the information I've provided will help you to help me, and I will appreciate any kind of help immensely.

0 Answers
Related