Home ⌂Doc Index ◂Up ▴
Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
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 66 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 1237 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 1239 of file flow_graph_opencl_node.h.

1239 : my_factory( factory ), my_type(type) , my_arg_str( program_name) {}
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

◆ 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 1240 of file flow_graph_opencl_node.h.

1240 : opencl_program( factory, std::string( program_name ) ) {}
opencl_program(Factory &factory, opencl_program_type type, const 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 1241 of file flow_graph_opencl_node.h.

1241 : opencl_program( factory, opencl_program_type::SOURCE, program_name ) {}
opencl_program(Factory &factory, opencl_program_type type, const std::string &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 1243 of file flow_graph_opencl_node.h.

1243 : opencl_program( opencl_info::default_factory(), type, program_name ) {}
default_opencl_factory & default_factory()
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
opencl_program(Factory &factory, opencl_program_type type, const std::string &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 1244 of file flow_graph_opencl_node.h.

1244 : opencl_program( opencl_info::default_factory(), program_name ) {}
default_opencl_factory & default_factory()
opencl_program(Factory &factory, opencl_program_type type, const std::string &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 1245 of file flow_graph_opencl_node.h.

1245 : opencl_program( opencl_info::default_factory(), program_name ) {}
default_opencl_factory & default_factory()
opencl_program(Factory &factory, opencl_program_type type, const std::string &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 1246 of file flow_graph_opencl_node.h.

default_opencl_factory & default_factory()
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
opencl_program(Factory &factory, opencl_program_type type, const std::string &program_name)

◆ 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 1248 of file flow_graph_opencl_node.h.

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

◆ 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 
)
inlineprivate

Definition at line 1258 of file flow_graph_opencl_node.h.

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

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
inlineprivate

Definition at line 1263 of file flow_graph_opencl_node.h.

1263  {
1264  std::call_once( my_do_once_flag, [this, &k](){ this->init( k ); } );
1265  cl_int err;
1266  cl_kernel kernel = clCreateKernel( my_cl_program, k.c_str(), &err );
1267  enforce_cl_retcode( err, std::string( "Failed to create kernel: " ) + k );
1268  return kernel;
1269  }
void enforce_cl_retcode(cl_int err, std::string msg)

References tbb::flow::interface11::enforce_cl_retcode().

Referenced by 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 1253 of file flow_graph_opencl_node.h.

1253  {
1254  return kernel_type( get_cl_kernel(k), my_factory );
1255  }
cl_kernel get_cl_kernel(const std::string &k) const

◆ init()

template<typename Factory = opencl_info::default_opencl_factory>
void tbb::flow::interface11::opencl_program< Factory >::init ( const std::string &  ) const
inlineprivate

Definition at line 1346 of file flow_graph_opencl_node.h.

1346  {
1347  cl_uint num_devices;
1348  enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_NUM_DEVICES, sizeof( num_devices ), &num_devices, NULL ),
1349  "Failed to get OpenCL context info" );
1350  if ( !num_devices )
1351  enforce_cl_retcode( CL_DEVICE_NOT_FOUND, "No supported devices found" );
1352  cl_device_id *device_list = (cl_device_id *)alloca( num_devices*sizeof( cl_device_id ) );
1353  enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_DEVICES, num_devices*sizeof( cl_device_id ), device_list, NULL ),
1354  "Failed to get OpenCL context info" );
1355  const char *options = NULL;
1356  switch ( my_type ) {
1358  file_reader fr( my_arg_str );
1359  const char *s[] = { fr.content() };
1360  const size_t l[] = { fr.length() };
1361  cl_int err;
1362  my_cl_program = clCreateProgramWithSource( my_factory.context(), 1, s, l, &err );
1363  enforce_cl_retcode( err, std::string( "Failed to create program: " ) + my_arg_str );
1364  opencl_device_filter(
1365  num_devices, device_list,
1366  []( const opencl_device& d ) -> bool {
1367  return !d.compiler_available() || !d.linker_available();
1368  }, "No one device supports building program from sources" );
1369  opencl_program_builder(
1370  my_factory, my_arg_str, my_cl_program, num_devices, device_list,
1371  options, /*callback*/ NULL, /*user data*/NULL );
1372  break;
1373  }
1375  options = "-x spir";
1377  file_reader fr( my_arg_str );
1378  std::vector<const unsigned char*> s(
1379  num_devices, reinterpret_cast<const unsigned char*>(fr.content()) );
1380  std::vector<size_t> l( num_devices, fr.length() );
1381  std::vector<cl_int> bin_statuses( num_devices, -1 );
1382  cl_int err;
1383  my_cl_program = clCreateProgramWithBinary( my_factory.context(), num_devices,
1384  device_list, l.data(), s.data(),
1385  bin_statuses.data(), &err );
1386  if( err != CL_SUCCESS ) {
1387  std::string statuses_str;
1388  for (auto st = bin_statuses.begin(); st != bin_statuses.end(); ++st) {
1389  statuses_str += std::to_string((*st));
1390  }
1391 
1392  enforce_cl_retcode( err, std::string( "Failed to create program, error " + std::to_string( err ) + " : " ) + my_arg_str +
1393  std::string( ", binary_statuses = " ) + statuses_str );
1394  }
1395  opencl_program_builder(
1396  my_factory, my_arg_str, my_cl_program, num_devices, device_list,
1397  options, /*callback*/ NULL, /*user data*/NULL );
1398  break;
1399  }
1400  default:
1401  __TBB_ASSERT( false, "Unsupported program type" );
1402  }
1403  }
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 const char const char int ITT_FORMAT __itt_group_sync s
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void enforce_cl_retcode(cl_int err, std::string msg)

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::PRECOMPILED, s, tbb::flow::interface11::SOURCE, and tbb::flow::interface11::SPIR.

Here is the call 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 1414 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 1412 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 1407 of file flow_graph_opencl_node.h.

◆ my_cl_program

template<typename Factory = opencl_info::default_opencl_factory>
cl_program tbb::flow::interface11::opencl_program< Factory >::my_cl_program
mutableprivate

Definition at line 1408 of file flow_graph_opencl_node.h.

◆ 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
mutableprivate

Definition at line 1409 of file flow_graph_opencl_node.h.

◆ my_factory

template<typename Factory = opencl_info::default_opencl_factory>
Factory& tbb::flow::interface11::opencl_program< Factory >::my_factory
private

Definition at line 1405 of file flow_graph_opencl_node.h.

◆ 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 1406 of file flow_graph_opencl_node.h.


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

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.