Clover Git
OpenCL 1.1 software implementation
|
CPU program. More...
#include <program.h>
Public Member Functions | |
CPUProgram (CPUDevice *device, Program *program) | |
Constructor. | |
~CPUProgram () | |
bool | linkStdLib () const |
Linking or not stdlib with this program. | |
void | createOptimizationPasses (llvm::PassManager *manager, bool optimize) |
Create device-specific optimization passes. | |
bool | build (llvm::Module *module) |
Build a device-specific representation of the program. | |
bool | initJIT () |
Initialize an LLVM JIT. | |
llvm::ExecutionEngine * | jit () const |
Current LLVM execution engine. | |
Private Attributes | |
CPUDevice * | p_device |
Program * | p_program |
llvm::ExecutionEngine * | p_jit |
llvm::Module * | p_module |
CPU program.
This class implements the Coal::DeviceProgram
interface for CPU acceleration.
It's main purpose is to initialize a llvm::JIT
object to run LLVM bitcode, in initJIT()
.
Definition at line 59 of file cpu/program.h.
Constructor.
device | CPU device to which this program is attached |
program | Coal::Program that will be run |
Definition at line 54 of file cpu/program.cpp.
CPUProgram::~CPUProgram | ( | ) |
Definition at line 60 of file cpu/program.cpp.
bool CPUProgram::build | ( | llvm::Module * | module | ) | [virtual] |
Build a device-specific representation of the program.
This function is called by Coal::Program::build()
when the module is compiled and linked. It can be used by the device to build a device-specific representation of the program.
module | llvm::Module containing the program's LLVM IR |
Implements Coal::DeviceProgram.
Definition at line 105 of file cpu/program.cpp.
References p_module.
void CPUProgram::createOptimizationPasses | ( | llvm::PassManager * | manager, |
bool | optimize | ||
) | [virtual] |
Create device-specific optimization passes.
This hook allows a device to add LLVM optimization passes to a llvm::PassManager
. This way, devices needing function flattening or special analysis passes can have them run on the mode.
manager | llvm::PassManager to which add the passes |
optimize | false if -cl-opt-disable was given at compilation time. |
Implements Coal::DeviceProgram.
Definition at line 76 of file cpu/program.cpp.
bool CPUProgram::initJIT | ( | ) |
Initialize an LLVM JIT.
This function creates a llvm::JIT
object to run this program on the CPU. A few implementation details :
dlsym()
. This way, a malicious kernel cannot execute arbitrary code on the host by declaring libc
functions and calling them.getBuiltin()
to get native built-in implementations.Definition at line 113 of file cpu/program.cpp.
References getBuiltin(), p_jit, and p_module.
Referenced by Coal::CPUDevice::initEventDeviceData().
llvm::ExecutionEngine * CPUProgram::jit | ( | ) | const |
Current LLVM execution engine.
Definition at line 142 of file cpu/program.cpp.
References p_jit.
Referenced by Coal::CPUKernelWorkGroup::run().
bool CPUProgram::linkStdLib | ( | ) | const [virtual] |
Linking or not stdlib with this program.
stdlib is a LLVM bitcode file containing some implementations of OpenCL C built-ins. This function allows a device to tell Coal::Program::build()
if it wants stdlib to be linked or not.
Linking the library may allow inlining of functions like ceil()
, floor()
, clamp()
, etc. So, if these functions are not better handled by the device itself than by stdlib, it's a good thing to link it.
But if the device provides instructions for these functions, then it could be better not to link stdlib and to replace the LLVM calls to these functions with device-specific instructions.
Coal::CPUDevice
, as it contains host-specific code (LLVM IR is not meant to be portable, pointer size changes for example).Implements Coal::DeviceProgram.
Definition at line 71 of file cpu/program.cpp.
CPUDevice* Coal::CPUProgram::p_device [private] |
Definition at line 92 of file cpu/program.h.
llvm::ExecutionEngine* Coal::CPUProgram::p_jit [private] |
Definition at line 95 of file cpu/program.h.
Referenced by initJIT(), jit(), and ~CPUProgram().
llvm::Module* Coal::CPUProgram::p_module [private] |
Definition at line 96 of file cpu/program.h.
Referenced by build(), initJIT(), and ~CPUProgram().
Program* Coal::CPUProgram::p_program [private] |
Definition at line 93 of file cpu/program.h.