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
链接已复制
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,
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.
