Hi,
I'm trying to configure 2 different kernels on 2 different devices in emulator mode. But not able to configure on 2nd device.
I could able to launch kernel1 on device1 properly. When I'm trying to launch 2nd kernel on 2nd device then it is throwing "Error in clEnqueueTask1 45" error.
Error no 45 = CL_INVALID_PROGRAM_EXECUTABLE.


Tried with the following code:


#define DEVICE_ID_1 1
#define DEVICE_ID_0 0

cl_program createProgramFromBinary(cl_context context, const char *binary_file_name, const cl_device_id *devices, unsigned num_devices)
{
// Early exit for potentially the most common way to fail: AOCX does not exist.
if(!fileExists(binary_file_name)) {
printf("AOCX file '%s' does not exist.\n", binary_file_name);
checkError(CL_INVALID_PROGRAM, "Failed to load binary file");
}

// Load the binary.
size_t binary_size;
scoped_array<unsigned char> binary(loadBinaryFile(binary_file_name, &binary_size));
if(binary == NULL) {
checkError(CL_INVALID_PROGRAM, "Failed to load binary file");
}

scoped_array<size_t> binary_lengths(num_devices);
scoped_array<unsigned char *> binaries(num_devices);
for(unsigned i = 0; i < num_devices; ++i) {
binary_lengths[i] = binary_size;
binaries[i] = binary;
}

cl_int status;
scoped_array<cl_int> binary_status(num_devices);

cl_program program = clCreateProgramWithBinary(context, num_devices, devices, binary_lengths,
(const unsigned char **) binaries.get(), binary_status, &status);
checkError(status, "Failed to create program with binary");
for(unsigned i = 0; i < num_devices; ++i) {
checkError(binary_status[i], "Failed to load binary for device");
}

return program;
}


void initOpenCLPlatform_1()
{
cl_int err = CL_SUCCESS;


err = clGetPlatformIDs(0, NULL, &num_platforms);
if (CL_SUCCESS != err) {
printf("Error in clGetPlatformIDs %d\n", err);
exit(-1);
}
if (0 == num_platforms) {
printf("No OpenCL platforms found\n");
exit(-1);
}


std::vector<cl_platform_id> platform(num_platforms);


err = clGetPlatformIDs(num_platforms, &platform[0], 0);
if (CL_SUCCESS != err) {
printf("Error in clGetPlatformIDs %d\n", err);
exit(-1);
}


for (cl_int i = 0; i < num_platforms; i++) {
size_t length = 0;


err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, 0, NULL, &length);
if (CL_SUCCESS != err) {
printf("Error in clGetPlatformInfo %d\n", err);
exit(-1);
}


std::vector<char> platform_name(length);
err = clGetPlatformInfo(platform[i], CL_PLATFORM_NAME, length, &platform_name[0], NULL);
if (CL_SUCCESS != err) {
printf("Error in clGetPlatformInfo %d\n", err);
exit(-1);
}


//if (strstr(&platform_name[0], "Altera")) {
if (strstr(&platform_name[0], "Intel")) {


err = clGetDeviceIDs(platform[i], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices);
if (CL_SUCCESS != err) {
printf("Error in clGetDeviceIDs %d\n", err);
exit(-1);
}


if (numDevices == 0) {
printf("No suitable devices found\n");
exit(-1);
}


cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform[i], 0 };


context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_ALL, NULL, NULL, &err);
if ((CL_SUCCESS != err) || (NULL == context)) {
printf("Error in clCreateContextFromType %d\n", err);
exit(-1);
}




err = clGetContextInfo(context, CL_CONTEXT_DEVICES, 2*sizeof(cl_device_id), deviceId, 0);
if (CL_SUCCESS != err) {
printf("Error in clGetContextInfo %d\n", err);
exit(-1);
}


const cl_command_queue_properties properties[] = { CL_QUEUE_PROPERTIES, CL_QUEUE_PROFILING_ENABLE, 0 };
commandQueue[0] = clCreateCommandQueueWithProperties(context, deviceId[DEVICE_ID_0], properties, &err);
if ((CL_SUCCESS != err) || (NULL == commandQueue[0])) {
printf("Error in clCreateCommandQueue %d\n", err);
exit(-1);
}
commandQueue[1] = clCreateCommandQueueWithProperties(context, deviceId[DEVICE_ID_1], properties, &err);
if ((CL_SUCCESS != err) || (NULL == commandQueue[1])) {
printf("Error in clCreateCommandQueue %d\n", err);
exit(-1);
}





std::string binary_file = getBoardBinaryFile("openclExample_1", deviceId[DEVICE_ID_0]);
printf("Using AOCX: %s\n", binary_file.c_str());
program[0] = createProgramFromBinary(context, binary_file.c_str(), &deviceId[DEVICE_ID_0], 1);


binary_file = getBoardBinaryFile("openclExample_2", deviceId[DEVICE_ID_1]);
printf("Using AOCX: %s\n", binary_file.c_str());
program[1] = createProgramFromBinary(context, binary_file.c_str(), &deviceId[DEVICE_ID_1], 1);
platform_init = 1;
}
}
}

void kernelLaunch()
{
initOpenCLPlatform_1();
/*kernel object creation for 1st kernel*/
kernel[0] = clCreateKernel(program[0], "examaple_kernel_1", &err);
if ((CL_SUCCESS != err) || (kernel[0] == NULL)) {
printf("Error in creating kernel[0] %d\n", err);
exit(-1);
}

//assigning kernel arguments for 1st kernel
...
//1st kernel launch
...
//copying back the output
...

/*kernel object creation for 2nd kernel*/
kernel[1] = clCreateKernel(program[1], "examaple_kernel_2", &err);
if ((CL_SUCCESS != err) || (kernel[1] == NULL)) {
printf("Error in creating kernel[1] %d\n", err);
exit(-1);
}

//assigning kernel arguments for 2nd kernel
...
err = clEnqueueTask(commandQueue[1], kernel[1], 0, NULL, NULL);
if (CL_SUCCESS != err) {
printf("Error in clEnqueueTask1 %d\n", err);
exit(-1);
}
}

int main()
{
kernelLaunch();
}