Clover Git
OpenCL 1.1 software implementation
Public Member Functions | Private Attributes

Coal::CPUProgram Class Reference

CPU program. More...

#include <program.h>

Inheritance diagram for Coal::CPUProgram:
Collaboration diagram for Coal::CPUProgram:

List of all members.

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

CPUDevicep_device
Programp_program
llvm::ExecutionEngine * p_jit
llvm::Module * p_module

Detailed Description

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 & Destructor Documentation

CPUProgram::CPUProgram ( CPUDevice device,
Program program 
)

Constructor.

Parameters:
deviceCPU device to which this program is attached
programCoal::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.

References p_jit, and p_module.


Member Function Documentation

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.

Parameters:
modulellvm::Module containing the program's LLVM IR
Returns:
true in case of success, false otherwise

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.

Parameters:
managerllvm::PassManager to which add the passes
optimizefalse 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 :

  • The JIT is set not to resolve unknown symbols using dlsym(). This way, a malicious kernel cannot execute arbitrary code on the host by declaring libc functions and calling them.
  • All the unknown function names are passed to getBuiltin() to get native built-in implementations.
Returns:
true if success, false otherwise

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.

Warning:
Stdlib currently only works for Coal::CPUDevice, as it contains host-specific code (LLVM IR is not meant to be portable, pointer size changes for example).
Returns:
true if stdlib must be linked with the program

Implements Coal::DeviceProgram.

Definition at line 71 of file cpu/program.cpp.


Member Data Documentation

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().

Definition at line 93 of file cpu/program.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines