OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

How to build native OpenCL kernel by assembly and load this kernel

Simon_S_1
Beginner
357 Views

Hello,

I want to learn how to build native OpenCL kernel by assembly and load this kernel. I am already able to generate assembly by the OpenCL kernel and compile it then:

ioc64 -cmd=build -input=kernel.cl -device=co -asm=file.s
icc -mmic -c file.s -o kernel

But how do I load this kernel into OpenCL runtime. My current approach did not work:

  FILE *fp;
  std::string fileName = "kernel";
  size_t binarySize;
  unsigned char *binaryBuffer;
 
  /* Load kernel binary */
  fp = fopen(fileName.c_str(), "r");
  binaryBuffer = (unsigned char *) malloc(MAX_BINARY_SIZE);
  binarySize = fread(binaryBuffer, 1, MAX_BINARY_SIZE, fp);
  fclose(fp);
  
  cl::Program::Binaries binaries;
  binaries.push_back( { binaryBuffer, binarySize });
  cl_int *err = new cl_int;

  cl::Program *program = new cl::Program(*context, devices, binaries, CL_SUCCESS, err);

How do I load the kernel file as OpenCL program?

 

Thanks, Simon

0 Kudos
4 Replies
Robert_I_Intel
Employee
357 Views

Simon,

What is the target device you are trying to execute on? CPU? GPU?

If it is GPU, you need to produce either SPIR or IR binary. SPIR is higher level and therefore smaller in size; also should be portable between vendor implementations. If is IR, it is a native (meaning Intel GPU) binary, it is larger in size and not usable by other vendors.

to produce SPIR, use

ioc64 -cmd=build -input=add.cl -device=gpu -spir64=add.bc -bo="-cl-std=CL1.2"

to produce IR, use

ioc64 -cmd=build -input=add.cl -device=gpu -ir=add.ir -bo="-cl-std=CL1.2"

When building SPIR program, you need to add "-x spir" to the build flags. BTW, when loading a binary, you need to use "rb" flags.

Simon_S_1
Beginner
357 Views

Hello Robert,

I targetting CPU/Xeon Phi. Need the steps to produce the binary by a given asm and that load binary kernel in the application.

Thanks, Simon

Robert_I_Intel
Employee
357 Views

Sorry, Simon,

The issue fell thru the cracks. I am getting someone to answer your question, hopefully within a day.

Robert_I_Intel
Employee
357 Views

Simon,

Here is the answer from Xeon Phi expert that I got:

This task (Need the steps to produce the binary by a given asm and that load binary kernel in the application) is not supported by our tools/SDK. You need to use either SPIR or IR. If the your goal is to make some modifications (on a level lower than OpenCL C) then SPIR would be the right choice – it is an open standard.

Reply