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 52 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 1220 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 1222 of file flow_graph_opencl_node.h.

1222 : 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 1223 of file flow_graph_opencl_node.h.

1223 : 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 1224 of file flow_graph_opencl_node.h.

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

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

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

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

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

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

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

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

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

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

1246  {
1247  std::call_once( my_do_once_flag, [this, &k](){ this->init( k ); } );
1248  cl_int err;
1249  cl_kernel kernel = clCreateKernel( my_cl_program, k.c_str(), &err );
1250  enforce_cl_retcode( err, std::string( "Failed to create kernel: " ) + k );
1251  return kernel;
1252  }
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

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

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

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