error when use clCompileProgram and clLinkProgram
in OpenCL1.2,I try to use clCompileProgram and clLinkProgram instead of using clBuildProgram.
but I failed.
I write a simple kernel of Matrix Multiplication ,and divided it to three parts.
//the original kernel
int f(int x, int y)
{
return x/y ;
}
int g(int x, int y)
{
return x%y ;
}
__kernel void
multiply(__global float* array_A, __global float* array_B, __global float* array_D,int M)
{
int global_id = get_global_id(0);
float buffer =0;
int line = f(global_id ,M);
int col = g(global_id ,M);
for(int i=0;i<M;i++)
{
buffer += array_A[line*M+i] *array_B[i*M+col];
}
array_D[global_id] =buffer;
}
//-------------
it is run ok ,when i use clBuildProgram.
status = clBuildProgram(program,1,&devices,NULL,NULL,NULL);
printf("clBuildProgram status =%d
",status);
if(status != CL_SUCCESS)
{
printf("Error:Building program
(clBuildProgram)
");
return EXIT_FAILURE;
}
//--------------
and i divided the kernel to three parts.
multi.cl multi2.h multi3.h
//multi.cl
#include “multi2.h”
#include “multi3.h”
__kernel void
multiply(__global float* array_A, __global float* array_B, __global float* array_D,int M)
{
int global_id = get_global_id(0);
float buffer =0;
int line = f(global_id ,M);
int col = g(global_id ,M);
for(int i=0;i<M;i++)
{
buffer += array_A[line*M+i] *array_B[i*M+col];
}
array_D[global_id] =buffer;
}
//multi2.h
int f(int x, int y)
{
return x/y ;
}
//multi3.h
int g(int x, int y)
{
return x%y ;
}
//--------------
I use clCreateProgramWithSource to got three program ,
program_multi, program_multi2, program_multi3 corresponding multi.cl ,multi2.h ,multi3.h
cl_program input_headers[2] ={ program_multi2 ,program_multi3};
const char * input_header_names[2] = {"multi2.h" ,"multi3.h" };
status=clCompileProgram(program_multi,
0,
NULL,
0,
2,
input_headers,
input_header_names,
NULL,NULL);
printf("clCompileProgram status =%d
",status);
but it error .the return status is -11 ,means CL_BUILD_PROGRAM_FAILURE
I am trying many times ,but still fail .
the first parameters of clCompileProgram ,is it right .
there are little formation about these two functions ,so I try to get help from this forum .
Thanks !