0
votes

I use OpenCL 2.0 on AMD. The code is pretty simple. If I use 1 printf, the work is good. But if i add a second printf, then there will be crooked data. My Code in host C++:

cl_int errcode;
// Get available platforms
vector<Platform> platforms;
Platform::get(&platforms);
// Select the default platform and create a context using this platform and the GPU
cl_context_properties cps[3] = {
    CL_CONTEXT_PLATFORM,
    (cl_context_properties)(platforms[0])(),
    0
};
Context context(CL_DEVICE_TYPE_GPU, cps);


vector<Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();

CommandQueue queue = CommandQueue(context, devices[0]);

// Read source file
string name;
name += "CalcN.cl";
std::ifstream sourceFile(name);
std::string sourceCode(
    std::istreambuf_iterator<char>(sourceFile),
    (std::istreambuf_iterator<char>()));
Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));


Program program = Program(context, source);

errcode = program.build(devices);
if (errcode != CL_SUCCESS)
{
    cout << "There were error during build kernel code. Please, check program code. Errcode = " << errcode << "\n";
    cout << "BUILD LOG: " + program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[0]) + "\n";
    getchar();
}


// Make kernel
Kernel kernel(program, "Optimization");

NDRange global(1);
queue.enqueueNDRangeKernel(kernel, 0, global);

My Code in kernel:

__kernel void Optimization() 
{
   for(int i = 0;i<100;i++)
   {
       printf("%d",i);
       printf("%d",i);
   }
}

Console with One printf

enter image description here

And console with Two printf:

enter image description here

I’ve already asked about this problem more than once, but no one knows.

3
have you tried "ignore();" in between both the printf statements? - Aqeel Ahmad

3 Answers

0
votes

Your output prints new lines after each printf while there isn't a \n in your code. My system wouldn't do that; it would print 112233... in one line. You could try printf("%i\n",i);.

0
votes

The problem was with the video card drivers. Today they released an update that fixes this bug.

-1
votes

Just use setbuf(stdout,NULL);. Write it under the declaration.