ZSA
ZSA

Reputation: 85

Passing output within the kernel in OpenCL

First can i initialize an array inside kernel like "float output[3] = {0}"

Second,I want to use the results that i get from part of kernel and use it in next part( in the same kernel).I wrote given kernel just for example, so i want to use values of output[id] and output1[id] in the next part to get output2[id] and output3[id] but it gives me "PROGRAM FAILED TO BUILD"

Suppose InputA[3]={1, 2, 3}

InputB[3]={1, 2, 3}

InputC[3]={1, 2, 3}

const char *ProgramSource =
"__kernel void add(__global float *inputA, __global float *inputB, __global 
float *inputC, __global float *output2, __global float *output3)\n"\
"{\n"\
"  size_t id = get_global_id(0);\n"\
"float a = 0.0f;\n"\
"float b = 0.0f;\n"\
"float output[3] = {0};\n"\
"float output1 [3] = {0};\n"\
"a = inputB[id] + inputC[id];\n"\
"b = inputA[id] + inputC[id];\n"\
"  output[id] = a;\n"\
"  output1[id] = b;\n"\
"float c = 0.0f;\n"\
"float d = 0.0f;\n"\
"c = inputB[id] + output[id]);\n"\
"d = inputA[id] + output1[id];\n"\
"  output2[id] = c;\n"\
"  output3[id] = d;\n"\
"}\n";

Upvotes: 0

Views: 158

Answers (1)

Andrew Savonichev
Andrew Savonichev

Reputation: 699

You have an extra parenthesis on this line:

"c = inputB[id] + output[id]);\n"\

You can call clGetProgramBuildInfo with CL_PROGRAM_BUILD_LOG to get a human-readable error message if your OpenCL program failed to compile.

Upvotes: 1

Related Questions