Compute Library
 21.08
Program Class Referencefinal

Program class. More...

#include <CLCompileContext.h>

Public Member Functions

 Program ()
 Default constructor. More...
 
 Program (cl::Context context, std::string name, std::string source)
 Construct program from source file. More...
 
 Program (cl::Context context, cl::Device device, std::string name, std::vector< unsigned char > binary)
 Construct program from binary file. More...
 
 Program (const Program &)=default
 Default Copy Constructor. More...
 
 Program (Program &&)=default
 Default Move Constructor. More...
 
Programoperator= (const Program &)=default
 Default copy assignment operator. More...
 
Programoperator= (Program &&)=default
 Default move assignment operator. More...
 
std::string name () const
 Returns program name. More...
 
const std::vector< unsigned char > & binary () const
 Returns program binary data. More...
 
 operator cl::Program () const
 User-defined conversion to the underlying CL program. More...
 
cl::Program build (const std::string &build_options="") const
 Build the underlying CL program. More...
 

Static Public Member Functions

static bool build (const cl::Program &program, const std::string &build_options="")
 Build the given CL program. More...
 

Detailed Description

Program class.

Definition at line 85 of file CLCompileContext.h.

Constructor & Destructor Documentation

◆ Program() [1/5]

Program ( )

Default constructor.

Definition at line 77 of file CLCompileContext.cpp.

78  : _context(), _device(), _is_binary(false), _name(), _source(), _binary()
79 {
80 }

◆ Program() [2/5]

Program ( cl::Context  context,
std::string  name,
std::string  source 
)

Construct program from source file.

Parameters
[in]contextCL context used to create the program.
[in]nameProgram name.
[in]sourceProgram source.

Definition at line 82 of file CLCompileContext.cpp.

83  : _context(std::move(context)), _device(), _is_binary(false), _name(std::move(name)), _source(std::move(source)), _binary()
84 {
85 }
std::string name() const
Returns program name.

◆ Program() [3/5]

Program ( cl::Context  context,
cl::Device  device,
std::string  name,
std::vector< unsigned char >  binary 
)

Construct program from binary file.

Parameters
[in]contextCL context used to create the program.
[in]deviceCL device for which the programs are created.
[in]nameProgram name.
[in]binaryProgram binary.

Definition at line 87 of file CLCompileContext.cpp.

88  : _context(std::move(context)), _device(std::move(device)), _is_binary(true), _name(std::move(name)), _source(), _binary(std::move(binary))
89 {
90 }
const std::vector< unsigned char > & binary() const
Returns program binary data.
std::string name() const
Returns program name.

◆ Program() [4/5]

Program ( const Program )
default

Default Copy Constructor.

◆ Program() [5/5]

Program ( Program &&  )
default

Default Move Constructor.

Member Function Documentation

◆ binary()

const std::vector<unsigned char>& binary ( ) const
inline

Returns program binary data.

Returns
Program's binary data.

Definition at line 125 of file CLCompileContext.h.

References build_options.

126  {
127  return _binary;
128  }

◆ build() [1/2]

bool build ( const cl::Program &  program,
const std::string &  build_options = "" 
)
static

Build the given CL program.

Parameters
[in]programThe CL program to build.
[in]build_optionsOptions to build the CL program.
Returns
True if the CL program builds successfully.

Definition at line 104 of file CLCompileContext.cpp.

Referenced by Program::build(), and CLCompileContext::create_kernel().

105 {
106  try
107  {
108  return program.build(build_options.c_str()) == CL_SUCCESS;
109  }
110  catch(const cl::Error &e)
111  {
112  cl_int err = CL_SUCCESS;
113  const auto build_info = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&err);
114 
115  for(auto &pair : build_info)
116  {
117  std::cerr << pair.second << std::endl;
118  }
119 
120  return false;
121  }
122 }
std::set< std::string > build_options

◆ build() [2/2]

cl::Program build ( const std::string &  build_options = "") const

Build the underlying CL program.

Parameters
[in]build_optionsOptions used to build the CL program.
Returns
A reference to itself.

Definition at line 124 of file CLCompileContext.cpp.

References Program::build().

125 {
126  cl::Program cl_program = static_cast<cl::Program>(*this);
127  build(cl_program, build_options);
128  return cl_program;
129 }
std::set< std::string > build_options
static bool build(const cl::Program &program, const std::string &build_options="")
Build the given CL program.

◆ name()

std::string name ( ) const
inline

Returns program name.

Returns
Program's name.

Definition at line 117 of file CLCompileContext.h.

118  {
119  return _name;
120  }

◆ operator cl::Program()

operator cl::Program ( ) const
explicit

User-defined conversion to the underlying CL program.

Returns
The CL program object.

Definition at line 92 of file CLCompileContext.cpp.

93 {
94  if(_is_binary)
95  {
96  return cl::Program(_context, { _device }, { _binary });
97  }
98  else
99  {
100  return cl::Program(_context, _source, false);
101  }
102 }

◆ operator=() [1/2]

Program& operator= ( const Program )
default

Default copy assignment operator.

◆ operator=() [2/2]

Program& operator= ( Program &&  )
default

Default move assignment operator.


The documentation for this class was generated from the following files: