I'm kind of new to OpenCL programming and am trying to run a simple vector addition code in VS 2019. However, I can't get the .cl code to compile. It's showing these 6 errors when trying to build the program:
Error C2144 syntax error: 'void' should be preceded by ';'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
Error C2065 '__global': undeclared identifier
Error C2146 syntax error: missing ')' before identifier 'float4'
Error C2143 syntax error: missing ';' before '{'
Error C2447 '{': missing function header (old-style formal list?)
This is my kernel code:
__kernel void add_numbers(__global float4* data,
__local float* local_result, __global float* group_result) {
float sum;
float4 input1, input2, sum_vector;
uint global_addr, local_addr;
global_addr = get_global_id(0) * 2;
input1 = data[global_addr];
input2 = data[global_addr + 1];
sum_vector = input1 + input2;
local_addr = get_local_id(0);
local_result[local_addr] = sum_vector.s0 + sum_vector.s1 +
sum_vector.s2 + sum_vector.s3;
barrier(CLK_LOCAL_MEM_FENCE);
if (get_local_id(0) == 0) {
sum = 0.0f;
for (int i = 0; i < get_local_size(0); i++) {
sum += local_result[i];
}
group_result[get_group_id(0)] = sum;
}
}
I have added the include and lib directories and linked them properly. I couldn't find many fixes for this error after googling. Please help me out...
UPDATE : I fixed it
Hello everyone, I found the solution to this problem. I removed the .cl file from VS projects and then re-added it (optional). I also changed file open option to have "rb" instead of "r" ( fopen(filename,"rb") ). Now I'm able to run it!