- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, Simon,
The issue fell thru the cracks. I am getting someone to answer your question, hopefully within a day.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page