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.

OpenCL compiler flags

Robert_M_3
Beginner
925 Views

Hi all,

I want to influence optimization flags of OpenCL. As I'm not aware of optimization flags, that do not influence correctness, that are available for the online compiler I have decided to use the offline compiler. I have found that Intel OpenCL kernel builder is able to generate llvm code beside IR code. As there is Intel LLVM Optimizer, i.e., oclopt, which could generate bit code, i.e., .bc file, which is not a final binary. This file cannot be used directly in the OpenCL program, i.e., cannot be read with clCreateProgramWithBinary as it returns

Stack dump:
0.	Running pass 'Intel OpenCL DuplicateCalledKernels' on module 'Program'.

followed by segmentation fault.

Now I'm interested in the following:

1. How to generate the binary that can be used with clCreateProgramWithBinary but generated with different optimization switches from llvm optimizer? Does Intel provide missing compiler chain from Optimizer to Binary generation, tool(s) that can take output of llvm optimizer, i.e., bit code, and generate a binary?

2. Are there environment flags or any other mechanism to influence the optimizer with online compilation and/or offline compilation of OpenCL codes?

 

Thank you in advance for your effort.

Looking forward for your response.

Best regards,

Robert

0 Kudos
1 Solution
Robert_I_Intel
Employee
925 Views

I tried the following:

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

oclopt -strip drawbox.bc > drawbox_stripped.bc

You should be able to load both SPIR files (.bc) with clCreateProgramWithBinary.

Try oclopt --help for the list of all available optimization options.

 

View solution in original post

0 Kudos
2 Replies
Robert_I_Intel
Employee
926 Views

I tried the following:

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

oclopt -strip drawbox.bc > drawbox_stripped.bc

You should be able to load both SPIR files (.bc) with clCreateProgramWithBinary.

Try oclopt --help for the list of all available optimization options.

 

0 Kudos
Robert_M_3
Beginner
925 Views

Thank you a lot, this works!

Before I was trying to do it with the following:

ioc64 -cmd=build -input=add.cl -device=cpu -simd=sse42 -llvm
oclopt -o=add_offline add.ll

but unfortunately loading of the file that was returned by oclopt didn't work out.

The binary file was missing some information from the header and the footer, probably ELF information, compared to the bit stream returned by clGetProgramInfo or by offline compiler IR.

I will then in the future generate spir code instead of llvm ir.

Best regards,

Robert

0 Kudos
Reply