'Is it possible to create LLVM Pass for OpenCL Kernel?

I would like to create an LLVM Pass to optimize OpenCL kernel for NVIDIA Cards. I wonder if it is possible.

I have tried followings:

  1. clang -Xclang -load -Xclang lib/simplePass.so main.c

It did not work, cannot alter the kernel code.

  1. Separate compiling then linking.

It also does not work, gave me error that get_global_id is undefined.

  1. Using offline compiler then clCreateProgramWithBinary

I followed Apple's example, It work on the with Intel GPU, however was not able to use an LLVM Pass. When I tried to use it, it gave me error:

LLVM ERROR: Sized aggregate specification in datalayout string

When I tried to adopt it into Xubuntu, it does not work.

Is there any another method that I can tried? I know I can use SPIR-V IR but Nvidia does not support OpenCL 2.2 currently.

Thank you for your time.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source