Compute Library
 21.08
CLKernelLibrary Class Referencefinal

CLKernelLibrary class. More...

#include <CLKernelLibrary.h>

Public Member Functions

void init (std::string kernel_path, cl::Context context, cl::Device device)
 Initialises the kernel library. More...
 
void set_kernel_path (const std::string &kernel_path)
 Sets the path that the kernels reside in. More...
 
std::string get_kernel_path ()
 Gets the path that the kernels reside in. More...
 
std::pair< std::string, bool > get_program (const std::string &program_name) const
 Gets the source of the selected program. More...
 
cl::Context & context ()
 Accessor for the associated CL context. More...
 
const cl::Device & get_device ()
 Gets the CL device for which the programs are created. More...
 
void set_device (cl::Device device)
 Sets the CL device for which the programs are created. More...
 
std::string get_device_version ()
 Return the device version. More...
 
cl_uint get_num_compute_units ()
 Return the maximum number of compute units in the device. More...
 
Kernel create_kernel (const std::string &kernel_name, const std::set< std::string > &build_options_set={}) const
 Creates a kernel from the kernel library. More...
 
size_t max_local_workgroup_size (const cl::Kernel &kernel) const
 Find the maximum number of local work items in a workgroup can be supported for the kernel. More...
 
cl::NDRange default_ndrange () const
 Return the default NDRange for the device. More...
 
void clear_programs_cache ()
 Clear the library's cache of binary programs. More...
 
const std::map< std::string, cl::Program > & get_built_programs () const
 Access the cache of built OpenCL programs. More...
 
void add_built_program (const std::string &built_program_name, const cl::Program &program)
 Add a new built program to the cache. More...
 
bool fp16_supported () const
 Returns true if FP16 is supported by the CL device. More...
 
bool int64_base_atomics_supported () const
 Returns true if int64_base_atomics extension is supported by the CL device. More...
 
std::string get_program_name (const std::string &kernel_name) const
 Returns the program name given a kernel name. More...
 
bool is_wbsm_supported ()
 
void set_context (cl::Context context)
 Sets the CL context used to create programs. More...
 
CLCompileContextget_compile_context ()
 Gets the compile context used. More...
 

Static Public Member Functions

static CLKernelLibraryget ()
 Access the KernelLibrary singleton. More...
 

Detailed Description

CLKernelLibrary class.

Definition at line 38 of file CLKernelLibrary.h.

Member Function Documentation

◆ add_built_program()

void add_built_program ( const std::string &  built_program_name,
const cl::Program &  program 
)

Add a new built program to the cache.

Parameters
[in]built_program_nameName of the program
[in]programBuilt program to add to the cache

Definition at line 93 of file CLKernelLibrary.cpp.

References CLCompileContext::add_built_program().

Referenced by arm_compute::restore_program_cache_from_file().

94 {
95  _compile_context.add_built_program(built_program_name, program);
96 }
void add_built_program(const std::string &built_program_name, const cl::Program &program) const
Add a new built program to the cache.

◆ clear_programs_cache()

void clear_programs_cache ( )

Clear the library's cache of binary programs.

Definition at line 85 of file CLKernelLibrary.cpp.

References CLCompileContext::clear_programs_cache().

Referenced by Framework::run().

86 {
87  _compile_context.clear_programs_cache();
88 }
void clear_programs_cache()
Clear the library&#39;s cache of binary programs.

◆ context()

cl::Context & context ( )

Accessor for the associated CL context.

Returns
A CL context.

Definition at line 65 of file CLKernelLibrary.cpp.

References CLCompileContext::context().

Referenced by ClContext::ClContext(), and CLScheduler::context().

66 {
67  return _compile_context.context();
68 }
cl::Context & context()
Accessor for the associated CL context.

◆ create_kernel()

Kernel create_kernel ( const std::string &  kernel_name,
const std::set< std::string > &  build_options_set = {} 
) const

Creates a kernel from the kernel library.

Parameters
[in]kernel_nameKernel name.
[in]build_options_setKernel build options as a set.
Returns
The created kernel.

Definition at line 44 of file CLKernelLibrary.cpp.

References CLCompileContext::create_kernel(), CLKernelLibrary::get(), ClKernelLibrary::get(), CLKernelLibrary::get_kernel_path(), ClKernelLibrary::program(), and ClKernelLibrary::program_name().

45 {
46  const opencl::ClKernelLibrary &klib = opencl::ClKernelLibrary::get();
47  const std::string program_name = klib.program_name(kernel_name);
48  auto program = klib.program(program_name);
49  const std::string &kernel_path = CLKernelLibrary::get().get_kernel_path();
50  return _compile_context.create_kernel(kernel_name, program_name, program.program, kernel_path, build_options_set, program.is_binary);
51 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
static ClKernelLibrary & get()
Access the KernelLibrary singleton.
Kernel create_kernel(const std::string &kernel_name, const std::string &program_name, const std::string &program_source, const std::string &kernel_path, const StringSet &build_options_set, bool is_binary) const
Creates an OpenCL kernel.
std::string get_kernel_path()
Gets the path that the kernels reside in.
std::string kernel_name

◆ default_ndrange()

cl::NDRange default_ndrange ( ) const

Return the default NDRange for the device.

Definition at line 118 of file CLKernelLibrary.cpp.

References CLCompileContext::default_ndrange().

Referenced by CLArgMinMaxLayerKernel::configure(), and arm_compute::get_default_lws_for_type().

119 {
120  return _compile_context.default_ndrange();
121 }
cl::NDRange default_ndrange() const
Return the default NDRange for the device.

◆ fp16_supported()

bool fp16_supported ( ) const

Returns true if FP16 is supported by the CL device.

Returns
true if the CL device supports FP16

Definition at line 97 of file CLKernelLibrary.cpp.

References CLCompileContext::fp16_supported().

98 {
99  return _compile_context.fp16_supported();
100 }
bool fp16_supported() const
Returns true if FP16 is supported by the CL device.

◆ get()

CLKernelLibrary & get ( )
static

Access the KernelLibrary singleton.

This method has been deprecated and will be removed in future releases

Returns
The KernelLibrary instance.

Definition at line 39 of file CLKernelLibrary.cpp.

Referenced by CLTuner::add_tuning_params(), ClContext::ClContext(), CLRuntimeContext::CLRuntimeContext(), ClGemmDefaultConfigNativeBifrost::configure(), ClGemmDefaultConfigNativeValhall::configure(), ClGemmDefaultConfigReshapedBifrost::configure(), ClGemmDefaultConfigReshapedRhsOnlyBifrost::configure(), CLNormalizePlanarYUVLayer::configure(), CLBitwiseNot::configure(), CLReverse::configure(), CLTile::configure(), CLSynthetizeOperator< ClGemmMatrixMultiplyReshapedOnlyRhsKernel >::configure(), CLMinMaxLayerKernel::configure(), CLReverseKernel::configure(), CLDepthToSpaceLayer::configure(), CLChannelShuffleLayerKernel::configure(), CLFillBorder::configure(), CLDepthToSpaceLayerKernel::configure(), CLBitwiseAnd::configure(), CLBitwiseOr::configure(), CLBitwiseXor::configure(), CLSelect::configure(), CLSpaceToDepthLayerKernel::configure(), CLComputeAllAnchorsKernel::configure(), CLBatchToSpaceLayerKernel::configure(), CLNormalizationLayerKernel::configure(), CLGather::configure(), CLQLSTMLayerNormalizationKernel::configure(), CLReorgLayerKernel::configure(), CLSpaceToBatchLayerKernel::configure(), CLTileKernel::configure(), CLGatherKernel::configure(), CLDeconvolutionLayerUpsampleKernel::configure(), CLMeanStdDevNormalizationLayer::configure(), CLReorgLayer::configure(), CLComparison::configure(), CLFFTScaleKernel::configure(), ClGemmLowpMatrixMultiplyNativeKernel::configure(), CLMeanStdDevNormalizationKernel::configure(), CLComparisonKernel::configure(), CLPadLayerKernel::configure(), CLChannelShuffleLayer::configure(), CLFFTDigitReverseKernel::configure(), CLNormalizePlanarYUVLayerKernel::configure(), CLPriorBoxLayerKernel::configure(), CLReductionOperationKernel::configure(), CLPriorBoxLayer::configure(), CLRangeKernel::configure(), CLBoundingBoxTransformKernel::configure(), ClGemmMatrixMultiplyNativeKernel::configure(), CLL2NormalizeLayerKernel::configure(), CLROIPoolingLayerKernel::configure(), CLFFTRadixStageKernel::configure(), CLStackLayerKernel::configure(), CLROIAlignLayerKernel::configure(), CLUnstack::configure(), CLFuseBatchNormalizationKernel::configure(), CLBatchNormalizationLayerKernel::configure(), CLReduceMean::configure(), CLReshapeLayer::configure(), CLRange::configure(), CLBoundingBoxTransform::configure(), CLArgMinMaxLayerKernel::configure(), ClGemmLowpMatrixMultiplyReshapedKernel::configure(), CLTranspose::configure(), CLFill::configure(), CLFlattenLayer::configure(), CLCopy::configure(), CLFillBorderKernel::configure(), CLROIPoolingLayer::configure(), CLRsqrtLayer::configure(), CLFloor::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLSpaceToDepthLayer::configure(), CLLogicalAnd::configure(), CLLogicalOr::configure(), CLPermute::configure(), CLBatchToSpaceLayer::configure(), CLROIAlignLayer::configure(), CLDeconvolutionLayer::configure(), CLLogicalNot::configure(), CLRNNLayer::configure(), CLPReluLayer::configure(), CLSlice::configure(), ClGemmLowpMatrixMultiplyReshapedOnlyRhsKernel::configure(), CLDequantizationLayer::configure(), CLPoolingLayer::configure(), CLConvertFullyConnectedWeights::configure(), CLCrop::configure(), CLFFT2D::configure(), CLSpaceToBatchLayer::configure(), CLScale::configure(), CLCast::configure(), CLDeconvolutionLayerUpsample::configure(), ClGemmLowpMatrixAReductionKernel::configure(), ClGemmMatrixMultiplyReshapedOnlyRhsKernel::configure(), CLStackLayer::configure(), CLFFT1D::configure(), CLStridedSlice::configure(), CLDepthConvertLayer::configure(), CLQuantizationLayer::configure(), CLPadLayer::configure(), CLSoftmaxLayerGeneric< IS_LOG >::configure(), CLMaxUnpoolingLayer::configure(), CLNormalizationLayer::configure(), CLDirectConvolutionLayer::configure(), CLFuseBatchNormalization::configure(), CLActivationLayer::configure(), CLReductionOperation::configure(), CLL2NormalizeLayer::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLRemap::configure(), CLArithmeticAddition::configure(), CLPixelWiseMultiplication::configure(), CLArgMinMaxLayer::configure(), CLCropResize::configure(), CLInstanceNormalizationLayer::configure(), CLBatchNormalizationLayer::configure(), CLConcatenateLayer::configure(), ClGemmMatrixMultiplyReshapedKernel::configure(), CLWinogradConvolutionLayer::configure(), CLGEMMLowpOutputStage::configure(), CLFullyConnectedLayer::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder< K, bordersize >::configure(), CLFFTConvolutionLayer::configure(), CLDepthwiseConvolutionLayer::configure(), CLGEMMConvolutionLayer::configure(), CLGEMM::configure(), CLComparisonStatic< COP >::configure(), CLLSTMLayerQuantized::configure(), CLGenerateProposalsLayer::configure(), CLDirectDeconvolutionLayer::configure(), CLGEMMDeconvolutionLayer::configure(), CLConvolutionLayer::configure(), CLLSTMLayer::configure(), CLExpLayer::configure(), CLQLSTMLayer::configure(), CLConvertFullyConnectedWeightsManaged::configure(), CLComplexPixelWiseMultiplication::configure(), CLNegLayer::configure(), CLArithmeticSubtraction::configure(), ClSynthetizeOperatorWithBorder< K >::configure(), CLSinLayer::configure(), CLLogLayer::configure(), CLArithmeticDivision::configure(), CLAbsLayer::configure(), CLElementwiseMax::configure(), CLRoundLayer::configure(), CLElementwiseMin::configure(), CLElementwiseSquaredDiff::configure(), CLElementwisePower::configure(), CLScheduler::context(), ClContext::create_activation(), CLKernelLibrary::create_kernel(), arm_compute::test::validation::DATA_TEST_CASE(), CLScheduler::default_init(), CLScheduler::default_init_with_context(), arm_compute::error_on_unsupported_int64_base_atomics(), arm_compute::export_weights_to_cl_image(), arm_compute::get_default_lws_for_type(), ICLKernel::get_max_workgroup_size(), ICLKernel::get_target(), CLRuntimeContext::kernel_library(), main(), arm_compute::restore_program_cache_from_file(), CLDepthwiseConvolutionLayerNativeKernel::run(), Framework::run(), arm_compute::utils::run_example(), ClDirectConv2dKernel::run_op(), ClGemmMatrixMultiplyReshapedOnlyRhsKernel::run_op(), ClGemmMatrixMultiplyReshapedKernel::run_op(), arm_compute::save_program_cache_to_file(), CLScheduler::set_context(), arm_compute::test::validation::TEST_CASE(), OpenCLMemoryUsage::test_measurements(), CLTuner::tune_kernel_dynamic(), examples::gemm_tuner_helpers::update_padding_for_cl_image(), arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(), and arm_compute::opencl::kernels::gemm::validate_image2d_support_on_rhs().

40 {
41  static CLKernelLibrary _kernel_library;
42  return _kernel_library;
43 }

◆ get_built_programs()

const std::map< std::string, cl::Program > & get_built_programs ( ) const

Access the cache of built OpenCL programs.

Definition at line 89 of file CLKernelLibrary.cpp.

References CLCompileContext::get_built_programs().

Referenced by arm_compute::save_program_cache_to_file(), and OpenCLMemoryUsage::test_measurements().

90 {
91  return _compile_context.get_built_programs();
92 }
const std::map< std::string, cl::Program > & get_built_programs() const
Access the cache of built OpenCL programs.

◆ get_compile_context()

CLCompileContext & get_compile_context ( )

Gets the compile context used.

Returns
The used compile context

Definition at line 130 of file CLKernelLibrary.cpp.

Referenced by CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder< K, bordersize >::configure().

131 {
132  return _compile_context;
133 }

◆ get_device()

const cl::Device & get_device ( )

Gets the CL device for which the programs are created.

Definition at line 69 of file CLKernelLibrary.cpp.

References CLCompileContext::get_device().

Referenced by ClContext::ClContext(), arm_compute::test::validation::DATA_TEST_CASE(), arm_compute::export_weights_to_cl_image(), arm_compute::test::validation::TEST_CASE(), and arm_compute::opencl::kernels::gemm::validate_image2d_support_on_rhs().

70 {
71  return _compile_context.get_device();
72 }
const cl::Device & get_device() const
Gets the CL device for which the programs are created.

◆ get_device_version()

std::string get_device_version ( )

Return the device version.

Returns
The content of CL_DEVICE_VERSION

Definition at line 122 of file CLKernelLibrary.cpp.

References CLCompileContext::get_device_version().

123 {
124  return _compile_context.get_device_version();
125 }
std::string get_device_version() const
Return the device version.

◆ get_kernel_path()

std::string get_kernel_path ( )

Gets the path that the kernels reside in.

Definition at line 81 of file CLKernelLibrary.cpp.

References ClKernelLibrary::get(), and ClKernelLibrary::kernel_path().

Referenced by CLKernelLibrary::create_kernel(), and arm_compute::test::validation::TEST_CASE().

82 {
84 }
const std::string & kernel_path() const
Gets the path that the kernels reside in.
static ClKernelLibrary & get()
Access the KernelLibrary singleton.

◆ get_num_compute_units()

cl_uint get_num_compute_units ( )

Return the maximum number of compute units in the device.

Returns
The content of CL_DEVICE_MAX_COMPUTE_UNITS

Definition at line 126 of file CLKernelLibrary.cpp.

References CLCompileContext::get_num_compute_units().

Referenced by CLTuner::tune_kernel_dynamic().

127 {
128  return _compile_context.get_num_compute_units();
129 }
cl_uint get_num_compute_units() const
Return the maximum number of compute units in the device.

◆ get_program()

std::pair< std::string, bool > get_program ( const std::string &  program_name) const

Gets the source of the selected program.

Parameters
[in]program_nameProgram name.
Returns
A pair with the source (false) or the binary (true), of the selected program.

Definition at line 109 of file CLKernelLibrary.cpp.

References ClKernelLibrary::get(), and ClKernelLibrary::program().

Referenced by arm_compute::test::validation::TEST_CASE().

110 {
111  auto program_info = opencl::ClKernelLibrary::get().program(program_name);
112  return std::make_pair(std::move(program_info.program), program_info.is_binary);
113 }
ClProgramInfo program(const std::string &program_name) const
Gets the source of the selected program.
static ClKernelLibrary & get()
Access the KernelLibrary singleton.

◆ get_program_name()

std::string get_program_name ( const std::string &  kernel_name) const

Returns the program name given a kernel name.

Returns
Program name

Definition at line 52 of file CLKernelLibrary.cpp.

References ClKernelLibrary::get(), and ClKernelLibrary::program_name().

Referenced by arm_compute::test::validation::TEST_CASE().

53 {
55 }
std::string program_name(const std::string &kernel_name) const
Returns the program name given a kernel name.
static ClKernelLibrary & get()
Access the KernelLibrary singleton.
std::string kernel_name

◆ init()

void init ( std::string  kernel_path,
cl::Context  context,
cl::Device  device 
)

Initialises the kernel library.

Parameters
[in]kernel_pathPath of the directory from which kernel sources are loaded.
[in]contextCL context used to create programs.
[in]deviceCL device for which the programs are created.

Definition at line 56 of file CLKernelLibrary.cpp.

References ClKernelLibrary::get(), and ClKernelLibrary::set_kernel_path().

Referenced by CLRuntimeContext::CLRuntimeContext(), CLScheduler::default_init(), and CLScheduler::default_init_with_context().

57 {
58  _compile_context = CLCompileContext(context, device);
60 }
static ClKernelLibrary & get()
Access the KernelLibrary singleton.
void set_kernel_path(std::string kernel_path)
Sets the path that the kernels reside in.
cl::Context & context()
Accessor for the associated CL context.

◆ int64_base_atomics_supported()

bool int64_base_atomics_supported ( ) const

Returns true if int64_base_atomics extension is supported by the CL device.

Returns
true if the CL device supports int64_base_atomics extension

Definition at line 101 of file CLKernelLibrary.cpp.

References CLCompileContext::int64_base_atomics_supported().

102 {
103  return _compile_context.int64_base_atomics_supported();
104 }
bool int64_base_atomics_supported() const
Returns true if int64_base_atomics extension is supported by the CL device.

◆ is_wbsm_supported()

bool is_wbsm_supported ( )

Definition at line 105 of file CLKernelLibrary.cpp.

References CLCompileContext::is_wbsm_supported().

Referenced by CLTuner::add_tuning_params().

106 {
107  return _compile_context.is_wbsm_supported();
108 }

◆ max_local_workgroup_size()

size_t max_local_workgroup_size ( const cl::Kernel &  kernel) const

Find the maximum number of local work items in a workgroup can be supported for the kernel.

Definition at line 114 of file CLKernelLibrary.cpp.

References CLCompileContext::max_local_workgroup_size().

Referenced by ICLKernel::get_max_workgroup_size().

115 {
116  return _compile_context.max_local_workgroup_size(kernel);
117 }
size_t max_local_workgroup_size(const cl::Kernel &kernel) const
Find the maximum number of local work items in a workgroup can be supported for the kernel...

◆ set_context()

void set_context ( cl::Context  context)

Sets the CL context used to create programs.

Note
Setting the context also resets the device to the first one available in the new context.
Parameters
[in]contextA CL context.

Definition at line 77 of file CLKernelLibrary.cpp.

References CLCompileContext::set_context().

Referenced by CLScheduler::set_context().

78 {
79  _compile_context.set_context(context);
80 }
void set_context(cl::Context context)
Sets the CL context used to create programs.
cl::Context & context()
Accessor for the associated CL context.

◆ set_device()

void set_device ( cl::Device  device)

Sets the CL device for which the programs are created.

Parameters
[in]deviceA CL device.

Definition at line 73 of file CLKernelLibrary.cpp.

References CLCompileContext::set_device().

74 {
75  _compile_context.set_device(device);
76 }
void set_device(cl::Device device)
Sets the CL device for which the programs are created.

◆ set_kernel_path()

void set_kernel_path ( const std::string &  kernel_path)

Sets the path that the kernels reside in.

Parameters
[in]kernel_pathPath of the kernel.

Definition at line 61 of file CLKernelLibrary.cpp.

References ClKernelLibrary::get(), and ClKernelLibrary::set_kernel_path().

62 {
64 }
static ClKernelLibrary & get()
Access the KernelLibrary singleton.
void set_kernel_path(std::string kernel_path)
Sets the path that the kernels reside in.

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