Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::flow::interface10::opencl_program< Factory > Class Template Reference

#include <flow_graph_opencl_node.h>

Inheritance diagram for tbb::flow::interface10::opencl_program< Factory >:
Collaboration diagram for tbb::flow::interface10::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 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
 
template<typename DeviceFilter >
class opencl_factory< DeviceFilter >::kernel
 

Detailed Description

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

Definition at line 56 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::interface10::opencl_program< Factory >::kernel_type

Definition at line 1224 of file flow_graph_opencl_node.h.

Constructor & Destructor Documentation

◆ opencl_program() [1/9]

template<typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface10::opencl_program< Factory >::opencl_program ( Factory &  factory,
opencl_program_type  type,
const std::string &  program_name 
)
inline

Definition at line 1226 of file flow_graph_opencl_node.h.

1226 : 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_id __itt_string_handle __itt_metadata_type type

◆ opencl_program() [2/9]

template<typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface10::opencl_program< Factory >::opencl_program ( Factory &  factory,
const char *  program_name 
)
inline

Definition at line 1227 of file flow_graph_opencl_node.h.

1227 : 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::interface10::opencl_program< Factory >::opencl_program ( Factory &  factory,
const std::string &  program_name 
)
inline

Definition at line 1228 of file flow_graph_opencl_node.h.

1228 : 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::interface10::opencl_program< Factory >::opencl_program ( opencl_program_type  type,
const std::string &  program_name 
)
inline

Definition at line 1230 of file flow_graph_opencl_node.h.

1230 : opencl_program( opencl_info::default_factory(), type, 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_id __itt_string_handle __itt_metadata_type type
default_opencl_factory & default_factory()
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::interface10::opencl_program< Factory >::opencl_program ( const char *  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() [6/9]

template<typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface10::opencl_program< Factory >::opencl_program ( const std::string &  program_name)
inline

Definition at line 1232 of file flow_graph_opencl_node.h.

1232 : 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::interface10::opencl_program< Factory >::opencl_program ( opencl_program_type  type)
inline

Definition at line 1233 of file flow_graph_opencl_node.h.

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_id __itt_string_handle __itt_metadata_type type
default_opencl_factory & default_factory()
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::interface10::opencl_program< Factory >::opencl_program ( const opencl_program< Factory > &  src)
inline

Definition at line 1235 of file flow_graph_opencl_node.h.

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

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

◆ opencl_program() [9/9]

template<typename Factory = opencl_info::default_opencl_factory>
tbb::flow::interface10::opencl_program< Factory >::opencl_program ( Factory &  factory,
cl_program  program 
)
inlineprivate

Definition at line 1245 of file flow_graph_opencl_node.h.

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

References tbb::flow::interface10::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::interface10::opencl_program< Factory >::get_cl_kernel ( const std::string &  k) const
inlineprivate

Definition at line 1250 of file flow_graph_opencl_node.h.

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

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

Referenced by tbb::flow::interface10::opencl_program< Factory >::get_kernel(), and tbb::flow::interface10::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::interface10::opencl_program< Factory >::get_kernel ( const std::string &  k) const
inline

Definition at line 1240 of file flow_graph_opencl_node.h.

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

References tbb::flow::interface10::opencl_program< Factory >::get_cl_kernel(), and tbb::flow::interface10::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::interface10::opencl_program< Factory >::init ( const std::string &  ) const
inlineprivate

Definition at line 1333 of file flow_graph_opencl_node.h.

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

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

Referenced by tbb::flow::interface10::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

◆ opencl_factory

template<typename Factory = opencl_info::default_opencl_factory>
template<typename DeviceFilter >
friend class opencl_factory
friend

Definition at line 1399 of file flow_graph_opencl_node.h.

◆ opencl_factory< DeviceFilter >::kernel

template<typename Factory = opencl_info::default_opencl_factory>
template<typename DeviceFilter >
friend class opencl_factory< DeviceFilter >::kernel
friend

Definition at line 1402 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::interface10::opencl_program< Factory >::my_arg_str
private

◆ my_cl_program

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

◆ my_do_once_flag

template<typename Factory = opencl_info::default_opencl_factory>
std::once_flag tbb::flow::interface10::opencl_program< Factory >::my_do_once_flag
mutableprivate

◆ my_factory

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

◆ my_type

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

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

Copyright © 2005-2019 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.