tbb::flow::interface11::opencl_program< Factory > Class Template Reference

`#include <flow_graph_opencl_node.h>`

Inheritance diagram for tbb::flow::interface11::opencl_program< Factory >:
Collaboration diagram for tbb::flow::interface11::opencl_program< Factory >:

## Classes

class | file_reader
class | opencl_device_filter
class | opencl_program_builder

## Public Types

typedef Factory::kernel_type | kernel_type

## Public Member Functions

| opencl_program (Factory &factory, opencl_program_type type, const std::string &program_name)
| opencl_program (Factory &factory, const char *program_name)
| opencl_program (Factory &factory, const std::string &program_name)
| opencl_program (opencl_program_type type, const std::string &program_name)
| opencl_program (const char *program_name)
| opencl_program (const std::string &program_name)
| opencl_program (opencl_program_type type)
| opencl_program (const opencl_program &src)
kernel_type | get_kernel (const std::string &k) const

## Private Member Functions

| opencl_program (Factory &factory, cl_program program)
cl_kernel | get_cl_kernel (const std::string &k) const
void | init (const std::string &) const
Private Member Functions inherited from tbb::internal::no_assign
void | operator= (const no_assign &)=delete
| no_assign (const no_assign &)=default
| no_assign ()=default

## Private Attributes

Factory & | my_factory
opencl_program_type | my_type
std::string | my_arg_str
cl_program | my_cl_program
std::once_flag | my_do_once_flag

## Friends

template<typename DeviceFilter >
class | opencl_factory
class | Factory::kernel

## Detailed Description

### template<typename Factory = opencl_info::default_opencl_factory>
class tbb::flow::interface11::opencl_program< Factory >

Definition at line 55 of file flow_graph_opencl_node.h.

## Member Typedef Documentation

## kernel_type

template<typename Factory = opencl_info::default_opencl_factory>

typedef Factory::kernel_type tbb::flow::interface11::opencl_program< Factory >::kernel_type

Definition at line 1223 of file flow_graph_opencl_node.h.

## Constructor & Destructor Documentation

## opencl_program() [1/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | Factory & | factory,
|  | opencl_program_type | type,
|  | const std::string & | program_name
| ) |  |

inline

Definition at line 1225 of file flow_graph_opencl_node.h.

: my_factory( factory ), my_type(type) , my_arg_str( program_name) {}

## opencl_program() [2/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | Factory & | factory,
|  | const char * | program_name
| ) |  |

inline

Definition at line 1226 of file flow_graph_opencl_node.h.

: opencl_program( factory, std::string( program_name ) ) {}

## opencl_program() [3/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | Factory & | factory,
|  | const std::string & | program_name
| ) |  |

inline

Definition at line 1227 of file flow_graph_opencl_node.h.

: opencl_program( factory, opencl_program_type::SOURCE, program_name ) {}

## opencl_program() [4/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | opencl_program_type | type,
|  | const std::string & | program_name
| ) |  |

inline

Definition at line 1229 of file flow_graph_opencl_node.h.

: opencl_program( opencl_info::default_factory(), type, program_name ) {}

## opencl_program() [5/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | const char * | program_name | ) |

inline

Definition at line 1230 of file flow_graph_opencl_node.h.

: opencl_program( opencl_info::default_factory(), program_name ) {}

## opencl_program() [6/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | const std::string & | program_name | ) |

inline

Definition at line 1231 of file flow_graph_opencl_node.h.

: opencl_program( opencl_info::default_factory(), program_name ) {}

## opencl_program() [7/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | opencl_program_type | type | ) |

inline

Definition at line 1232 of file flow_graph_opencl_node.h.

: opencl_program( opencl_info::default_factory(), type ) {}

## opencl_program() [8/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | const opencl_program< Factory > & | src | ) |

inline

Definition at line 1234 of file flow_graph_opencl_node.h.

: my_factory( src.my_factory ), my_type( src.type ), my_arg_str( src.my_arg_str ), my_cl_program( src.my_cl_program ) {
// Set my_do_once_flag to the called state.
std::call_once( my_do_once_flag, [](){} );
}

References tbb::flow::interface11::opencl_program< Factory >::my_do_once_flag.

## opencl_program() [9/9]

template<typename Factory = opencl_info::default_opencl_factory>

tbb::flow::interface11::opencl_program< Factory >::opencl_program | ( | Factory & | factory,
|  | cl_program | program
| ) |  |

inline private

Definition at line 1244 of file flow_graph_opencl_node.h.

: my_factory( factory ), my_cl_program( program ) {
// Set my_do_once_flag to the called state.
std::call_once( my_do_once_flag, [](){} );
}

References tbb::flow::interface11::opencl_program< Factory >::my_do_once_flag.

## Member Function Documentation

## get_cl_kernel()

template<typename Factory = opencl_info::default_opencl_factory>

cl_kernel tbb::flow::interface11::opencl_program< Factory >::get_cl_kernel | ( | const std::string & | k | ) | const

inline private

Definition at line 1249 of file flow_graph_opencl_node.h.

{
std::call_once( my_do_once_flag, [this, &k](){ this->init( k ); } );
cl_int err;
cl_kernel kernel = clCreateKernel( my_cl_program, k.c_str(), &err );
enforce_cl_retcode( err, std::string( "Failed to create kernel: " ) + k );
return kernel;
}

References tbb::flow::interface11::enforce_cl_retcode(), tbb::flow::interface11::opencl_program< Factory >::init(), tbb::flow::interface11::opencl_program< Factory >::my_cl_program, and tbb::flow::interface11::opencl_program< Factory >::my_do_once_flag.

Referenced by tbb::flow::interface11::opencl_program< Factory >::get_kernel(), and tbb::flow::interface11::opencl_factory< DeviceFilter >::kernel::kernel().

Here is the call graph for this function:
Here is the caller graph for this function:

## get_kernel()

template<typename Factory = opencl_info::default_opencl_factory>

kernel_type tbb::flow::interface11::opencl_program< Factory >::get_kernel | ( | const std::string & | k | ) | const

inline

Definition at line 1239 of file flow_graph_opencl_node.h.

{
return kernel_type( get_cl_kernel(k), my_factory );
}

References tbb::flow::interface11::opencl_program< Factory >::get_cl_kernel(), and tbb::flow::interface11::opencl_program< Factory >::my_factory.

Here is the call graph for this function:

## init()

template<typename Factory = opencl_info::default_opencl_factory>

void tbb::flow::interface11::opencl_program< Factory >::init | ( | const std::string & |  | ) | const

inline private

Definition at line 1332 of file flow_graph_opencl_node.h.

{
cl_uint num_devices;
enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_NUM_DEVICES, sizeof( num_devices ), &num_devices, NULL ),
"Failed to get OpenCL context info" );
if ( !num_devices )
enforce_cl_retcode( CL_DEVICE_NOT_FOUND, "No supported devices found" );
cl_device_id *device_list = (cl_device_id *)alloca( num_devices*sizeof( cl_device_id ) );
enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_DEVICES, num_devices*sizeof( cl_device_id ), device_list, NULL ),
"Failed to get OpenCL context info" );
const char *options = NULL;
switch ( my_type ) {
case opencl_program_type::SOURCE: {
file_reader fr( my_arg_str );
const char *s[] = { fr.content() };
const size_t l[] = { fr.length() };
cl_int err;
my_cl_program = clCreateProgramWithSource( my_factory.context(), 1, s, l, &err );
enforce_cl_retcode( err, std::string( "Failed to create program: " ) + my_arg_str );
opencl_device_filter(
num_devices, device_list,
[]( const opencl_device& d ) -> bool {
return !d.compiler_available() || !d.linker_available();
}, "No one device supports building program from sources" );
opencl_program_builder(
my_factory, my_arg_str, my_cl_program, num_devices, device_list,
options, /*callback*/ NULL, /*user data*/NULL );
break;
}
case opencl_program_type::SPIR:
options = "-x spir";
case opencl_program_type::PRECOMPILED: {
file_reader fr( my_arg_str );
std::vector<const unsigned char*> s(
num_devices, reinterpret_cast<const unsigned char*>(fr.content()) );
std::vector<size_t> l( num_devices, fr.length() );
std::vector<cl_int> bin_statuses( num_devices, -1 );
cl_int err;
my_cl_program = clCreateProgramWithBinary( my_factory.context(), num_devices,
device_list, l.data(), s.data(),
bin_statuses.data(), &err );
if( err != CL_SUCCESS ) {
std::string statuses_str;
for (auto st = bin_statuses.begin(); st != bin_statuses.end(); ++st) {
statuses_str += std::to_string((*st));
}
enforce_cl_retcode( err, std::string( "Failed to create program, error " + std::to_string( err ) + " : " ) + my_arg_str +
std::string( ", binary_statuses = " ) + statuses_str );
}
opencl_program_builder(
my_factory, my_arg_str, my_cl_program, num_devices, device_list,
options, /*callback*/ NULL, /*user data*/NULL );
break;
}
default:
__TBB_ASSERT( false, "Unsupported program type" );
}
}

References __TBB_ASSERT, tbb::flow::interface11::opencl_program< Factory >::file_reader::content(), d, tbb::flow::interface11::enforce_cl_retcode(), tbb::flow::interface11::opencl_program< Factory >::file_reader::length(), tbb::flow::interface11::opencl_program< Factory >::my_arg_str, tbb::flow::interface11::opencl_program< Factory >::my_cl_program, tbb::flow::interface11::opencl_program< Factory >::my_factory, tbb::flow::interface11::opencl_program< Factory >::my_type, tbb::flow::interface11::PRECOMPILED, s, tbb::flow::interface11::SOURCE, and tbb::flow::interface11::SPIR.

Referenced by tbb::flow::interface11::opencl_program< Factory >::get_cl_kernel().

Here is the call graph for this function:
Here is the caller graph for this function:

## Friends And Related Function Documentation

## Factory::kernel

template<typename Factory = opencl_info::default_opencl_factory>

friend class Factory::kernel

friend

Definition at line 1400 of file flow_graph_opencl_node.h.

## opencl_factory

template<typename Factory = opencl_info::default_opencl_factory>
template<typename DeviceFilter >

friend class opencl_factory

friend

Definition at line 1398 of file flow_graph_opencl_node.h.

## Member Data Documentation

## my_arg_str

template<typename Factory = opencl_info::default_opencl_factory>

std::string tbb::flow::interface11::opencl_program< Factory >::my_arg_str

private

Definition at line 1393 of file flow_graph_opencl_node.h.

Referenced by tbb::flow::interface11::opencl_program< Factory >::init().

## my_cl_program

template<typename Factory = opencl_info::default_opencl_factory>

cl_program tbb::flow::interface11::opencl_program< Factory >::my_cl_program

mutable private

Definition at line 1394 of file flow_graph_opencl_node.h.

Referenced by tbb::flow::interface11::opencl_program< Factory >::get_cl_kernel(), and tbb::flow::interface11::opencl_program< Factory >::init().

## my_do_once_flag

template<typename Factory = opencl_info::default_opencl_factory>

std::once_flag tbb::flow::interface11::opencl_program< Factory >::my_do_once_flag

mutable private

Definition at line 1395 of file flow_graph_opencl_node.h.

Referenced by tbb::flow::interface11::opencl_program< Factory >::get_cl_kernel(), and tbb::flow::interface11::opencl_program< Factory >::opencl_program().

## my_factory

template<typename Factory = opencl_info::default_opencl_factory>

Factory& tbb::flow::interface11::opencl_program< Factory >::my_factory

private

Definition at line 1391 of file flow_graph_opencl_node.h.

Referenced by tbb::flow::interface11::opencl_program< Factory >::get_kernel(), and tbb::flow::interface11::opencl_program< Factory >::init().

## my_type

template<typename Factory = opencl_info::default_opencl_factory>

opencl_program_type tbb::flow::interface11::opencl_program< Factory >::my_type

private

Definition at line 1392 of file flow_graph_opencl_node.h.

Referenced by tbb::flow::interface11::opencl_program< Factory >::init().

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

- flow_graph_opencl_node.h

tbb::flow::interface11::opencl_program::init
void init(const std::string &) const
Definition: flow_graph_opencl_node.h:1332
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::flow::interface11::opencl_info::default_factory
default_opencl_factory & default_factory()
Definition: flow_graph_opencl_node.h:1203
tbb::flow::interface11::opencl_program::kernel_type
Factory::kernel_type kernel_type
Definition: flow_graph_opencl_node.h:1223
d
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d
Definition: ittnotify_static.h:109
tbb::flow::interface11::opencl_program::my_factory
Factory & my_factory
Definition: flow_graph_opencl_node.h:1391
tbb::flow::interface11::opencl_program::my_cl_program
cl_program my_cl_program
Definition: flow_graph_opencl_node.h:1394
tbb::flow::interface11::opencl_program::my_arg_str
std::string my_arg_str
Definition: flow_graph_opencl_node.h:1393
tbb::flow::interface11::opencl_program::my_do_once_flag
std::once_flag my_do_once_flag
Definition: flow_graph_opencl_node.h:1395
tbb::flow::interface11::enforce_cl_retcode
void enforce_cl_retcode(cl_int err, std::string msg)
Definition: flow_graph_opencl_node.h:57
tbb::flow::interface11::opencl_program::opencl_program
opencl_program(Factory &factory, opencl_program_type type, const std::string &program_name)
Definition: flow_graph_opencl_node.h:1225
tbb::flow::interface11::opencl_program_type::SOURCE
tbb::flow::interface11::opencl_program::my_type
opencl_program_type my_type
Definition: flow_graph_opencl_node.h:1392
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb::flow::interface11::opencl_program_type::SPIR
tbb::flow::interface11::opencl_program::get_cl_kernel
cl_kernel get_cl_kernel(const std::string &k) const
Definition: flow_graph_opencl_node.h:1249
type
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type type
Definition: ittnotify_static.h:198
tbb::flow::interface11::opencl_program_type::PRECOMPILED

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.