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

1225 : 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 1226 of file flow_graph_opencl_node.h.

1226 : 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 1227 of file flow_graph_opencl_node.h.

1227 : 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 1229 of file flow_graph_opencl_node.h.

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

1230 : 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 1231 of file flow_graph_opencl_node.h.

1231 : 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 1232 of file flow_graph_opencl_node.h.

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

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

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

Definition at line 1244 of file flow_graph_opencl_node.h.

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

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
inlineprivate

Definition at line 1249 of file flow_graph_opencl_node.h.

1249  {
1250  std::call_once( my_do_once_flag, [this, &k](){ this->init( k ); } );
1251  cl_int err;
1252  cl_kernel kernel = clCreateKernel( my_cl_program, k.c_str(), &err );
1253  enforce_cl_retcode( err, std::string( "Failed to create kernel: " ) + k );
1254  return kernel;
1255  }
void enforce_cl_retcode(cl_int err, std::string msg)

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.

1239  {
1240  return kernel_type( get_cl_kernel(k), my_factory );
1241  }
cl_kernel get_cl_kernel(const std::string &k) const

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
inlineprivate

Definition at line 1332 of file flow_graph_opencl_node.h.

1332  {
1333  cl_uint num_devices;
1334  enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_NUM_DEVICES, sizeof( num_devices ), &num_devices, NULL ),
1335  "Failed to get OpenCL context info" );
1336  if ( !num_devices )
1337  enforce_cl_retcode( CL_DEVICE_NOT_FOUND, "No supported devices found" );
1338  cl_device_id *device_list = (cl_device_id *)alloca( num_devices*sizeof( cl_device_id ) );
1339  enforce_cl_retcode( clGetContextInfo( my_factory.context(), CL_CONTEXT_DEVICES, num_devices*sizeof( cl_device_id ), device_list, NULL ),
1340  "Failed to get OpenCL context info" );
1341  const char *options = NULL;
1342  switch ( my_type ) {
1344  file_reader fr( my_arg_str );
1345  const char *s[] = { fr.content() };
1346  const size_t l[] = { fr.length() };
1347  cl_int err;
1348  my_cl_program = clCreateProgramWithSource( my_factory.context(), 1, s, l, &err );
1349  enforce_cl_retcode( err, std::string( "Failed to create program: " ) + my_arg_str );
1350  opencl_device_filter(
1351  num_devices, device_list,
1352  []( const opencl_device& d ) -> bool {
1353  return !d.compiler_available() || !d.linker_available();
1354  }, "No one device supports building program from sources" );
1355  opencl_program_builder(
1356  my_factory, my_arg_str, my_cl_program, num_devices, device_list,
1357  options, /*callback*/ NULL, /*user data*/NULL );
1358  break;
1359  }
1361  options = "-x spir";
1363  file_reader fr( my_arg_str );
1364  std::vector<const unsigned char*> s(
1365  num_devices, reinterpret_cast<const unsigned char*>(fr.content()) );
1366  std::vector<size_t> l( num_devices, fr.length() );
1367  std::vector<cl_int> bin_statuses( num_devices, -1 );
1368  cl_int err;
1369  my_cl_program = clCreateProgramWithBinary( my_factory.context(), num_devices,
1370  device_list, l.data(), s.data(),
1371  bin_statuses.data(), &err );
1372  if( err != CL_SUCCESS ) {
1373  std::string statuses_str;
1374  for (auto st = bin_statuses.begin(); st != bin_statuses.end(); ++st) {
1375  statuses_str += std::to_string((*st));
1376  }
1377 
1378  enforce_cl_retcode( err, std::string( "Failed to create program, error " + std::to_string( err ) + " : " ) + my_arg_str +
1379  std::string( ", binary_statuses = " ) + statuses_str );
1380  }
1381  opencl_program_builder(
1382  my_factory, my_arg_str, my_cl_program, num_devices, device_list,
1383  options, /*callback*/ NULL, /*user data*/NULL );
1384  break;
1385  }
1386  default:
1387  __TBB_ASSERT( false, "Unsupported program type" );
1388  }
1389  }
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::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

◆ my_cl_program

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

◆ 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

◆ my_factory

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

◆ my_type

template<typename Factory = opencl_info::default_opencl_factory>
opencl_program_type tbb::flow::interface11::opencl_program< Factory >::my_type
private

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.