Compute Library
 23.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.

94 {
95  _compile_context.add_built_program(built_program_name, program);
96 }

Referenced by arm_compute::restore_program_cache_from_file().

◆ clear_programs_cache()

void clear_programs_cache ( )

Clear the library's cache of binary programs.

Definition at line 85 of file CLKernelLibrary.cpp.

86 {
87  _compile_context.clear_programs_cache();
88 }

Referenced by Framework::run().

◆ context()

cl::Context & context ( )

Accessor for the associated CL context.

Returns
A CL context.

Definition at line 65 of file CLKernelLibrary.cpp.

66 {
67  return _compile_context.context();
68 }

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

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

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 }

References kernel_name, ClKernelLibrary::program(), and ClKernelLibrary::program_name().

◆ default_ndrange()

cl::NDRange default_ndrange ( ) const

Return the default NDRange for the device.

Definition at line 118 of file CLKernelLibrary.cpp.

119 {
120  return _compile_context.default_ndrange();
121 }

Referenced by arm_compute::get_default_lws_for_type().

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

98 {
99  return _compile_context.fp16_supported();
100 }

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

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

Referenced by ClContext::ClContext(), CLRuntimeContext::CLRuntimeContext(), CLNormalizePlanarYUVLayer::configure(), CLReverse::configure(), CLBitwiseNot::configure(), CLTile::configure(), CLSynthetizeOperator< ClGemmMatrixMultiplyReshapedOnlyRhsKernel >::configure(), CLReverseKernel::configure(), CLChannelShuffleLayerKernel::configure(), CLDepthToSpaceLayer::configure(), CLDepthToSpaceLayerKernel::configure(), CLSelect::configure(), CLSpaceToDepthLayerKernel::configure(), CLBitwiseAnd::configure(), CLComputeAllAnchorsKernel::configure(), CLBitwiseXor::configure(), CLBitwiseOr::configure(), CLNormalizationLayerKernel::configure(), CLGather::configure(), CLReorgLayerKernel::configure(), CLQLSTMLayerNormalizationKernel::configure(), CLSpaceToBatchLayerKernel::configure(), CLTileKernel::configure(), CLDeconvolutionLayerUpsampleKernel::configure(), CLGatherKernel::configure(), CLMeanStdDevNormalizationLayer::configure(), CLReorgLayer::configure(), CLFFTScaleKernel::configure(), ClGemmLowpMatrixMultiplyNativeKernel::configure(), CLComparison::configure(), CLBatchToSpaceLayerKernel::configure(), CLMeanStdDevNormalizationKernel::configure(), CLComparisonKernel::configure(), CLFFTDigitReverseKernel::configure(), CLNormalizePlanarYUVLayerKernel::configure(), CLPadLayerKernel::configure(), CLReductionOperationKernel::configure(), CLPriorBoxLayerKernel::configure(), CLPriorBoxLayer::configure(), CLChannelShuffleLayer::configure(), CLRangeKernel::configure(), CLBoundingBoxTransformKernel::configure(), ClGemmMatrixMultiplyNativeKernel::configure(), CLL2NormalizeLayerKernel::configure(), CLROIPoolingLayerKernel::configure(), CLFFTRadixStageKernel::configure(), CLStackLayerKernel::configure(), CLROIAlignLayerKernel::configure(), CLArgMinMaxLayerKernel::configure(), CLUnstack::configure(), CLFuseBatchNormalizationKernel::configure(), CLReduceMean::configure(), CLReshapeLayer::configure(), CLRange::configure(), CLTranspose::configure(), CLBatchNormalizationLayerKernel::configure(), ClGemmLowpMatrixMultiplyReshapedKernel::configure(), CLBoundingBoxTransform::configure(), CLFlattenLayer::configure(), CLCopy::configure(), CLFill::configure(), CLFillBorderKernel::configure(), CLFloor::configure(), CLROIPoolingLayer::configure(), CLRsqrtLayer::configure(), CLDeconvolutionReshapeOutputKernel::configure(), CLSpaceToDepthLayer::configure(), CLLogicalAnd::configure(), CLPermute::configure(), CLLogicalOr::configure(), CLROIAlignLayer::configure(), CLConvertFullyConnectedWeights::configure(), CLLogicalNot::configure(), CLRNNLayer::configure(), CLPReluLayer::configure(), CLSlice::configure(), ClGemmLowpMatrixMultiplyReshapedOnlyRhsKernel::configure(), CLDeconvolutionLayer::configure(), CLDequantizationLayer::configure(), CLCrop::configure(), CLBatchToSpaceLayer::configure(), CLFFT2D::configure(), CLPooling3dLayer::configure(), CLScale::configure(), CLSpaceToBatchLayer::configure(), CLStackLayer::configure(), CLStridedSlice::configure(), ClGemmLowpMatrixAReductionKernel::configure(), CLDeconvolutionLayerUpsample::configure(), ClGemmMatrixMultiplyReshapedOnlyRhsKernel::configure(), CLFFT1D::configure(), CLPoolingLayer::configure(), CLIndirectConvolutionLayer::configure(), CLQuantizationLayer::configure(), CLDepthConvertLayer::configure(), CLPadLayer::configure(), CLSoftmaxLayerGeneric< IS_LOG >::configure(), CLCast::configure(), CLMaxUnpoolingLayer::configure(), CLNormalizationLayer::configure(), CLFuseBatchNormalization::configure(), CLDirectConvolutionLayer::configure(), CLReductionOperation::configure(), CLL2NormalizeLayer::configure(), CLActivationLayer::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLArgMinMaxLayer::configure(), CLArithmeticAddition::configure(), CLCropResize::configure(), CLInstanceNormalizationLayer::configure(), CLConv3D::configure(), CLConcatenateLayer::configure(), ClGemmMatrixMultiplyReshapedKernel::configure(), CLPixelWiseMultiplication::configure(), CLWinogradConvolutionLayer::configure(), CLBatchNormalizationLayer::configure(), CLGEMMLowpOutputStage::configure(), CLFullyConnectedLayer::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder< K, bordersize >::configure(), CLFFTConvolutionLayer::configure(), CLMatMul::configure(), CLComparisonStatic< COP >::configure(), CLDepthwiseConvolutionLayer::configure(), CLGEMMConvolutionLayer::configure(), CLGEMM::configure(), CLLSTMLayerQuantized::configure(), CLGenerateProposalsLayer::configure(), CLDirectDeconvolutionLayer::configure(), CLGEMMDeconvolutionLayer::configure(), CLLSTMLayer::configure(), CLExpLayer::configure(), CLConvolutionLayer::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(), arm_compute::create_image2d_from_buffer(), arm_compute::create_image2d_from_tensor(), CLScheduler::default_init(), CLScheduler::default_init_with_context(), arm_compute::error_on_unsupported_int64_base_atomics(), arm_compute::export_to_cl_image(), arm_compute::get_default_lws_for_type(), ICLKernel::get_max_workgroup_size(), CLRuntimeContext::kernel_library(), main(), arm_compute::restore_program_cache_from_file(), CLDepthwiseConvolutionLayerNativeKernel::run(), Framework::run(), ClMatMulNativeKernel::run_op(), ClIndirectConv2dKernel::run_op(), ClGemmMatrixMultiplyReshapedOnlyRhsMMULKernel::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(), examples::gemm_tuner_helpers::update_padding_for_cl_image(), arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(), ClMatMulNativeMMULKernel::validate(), and arm_compute::opencl::kernels::gemm::validate_image2d_support_on_rhs().

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

90 {
91  return _compile_context.get_built_programs();
92 }

Referenced by OpenCLMemoryUsage::test_measurements().

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

131 {
132  return _compile_context;
133 }

Referenced by CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder< K, bordersize >::configure(), and arm_compute::test::validation::TEST_CASE().

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

70 {
71  return _compile_context.get_device();
72 }

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

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

123 {
124  return _compile_context.get_device_version();
125 }

◆ get_kernel_path()

std::string get_kernel_path ( )

Gets the path that the kernels reside in.

Definition at line 81 of file CLKernelLibrary.cpp.

82 {
84 }

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

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

127 {
128  return _compile_context.get_num_compute_units();
129 }

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

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 }

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

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

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

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

57 {
58  _compile_context = CLCompileContext(context, device);
60 }

References arm_compute::test::validation::context.

Referenced by CLRuntimeContext::CLRuntimeContext(), CLScheduler::default_init(), and CLScheduler::default_init_with_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.

102 {
103  return _compile_context.int64_base_atomics_supported();
104 }

◆ is_wbsm_supported()

bool is_wbsm_supported ( )

Definition at line 105 of file CLKernelLibrary.cpp.

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.

115 {
116  return _compile_context.max_local_workgroup_size(kernel);
117 }

Referenced by ICLKernel::get_max_workgroup_size().

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

78 {
79  _compile_context.set_context(context);
80 }

References arm_compute::test::validation::context.

Referenced by CLScheduler::set_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.

74 {
75  _compile_context.set_device(device);
76 }

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

62 {
64 }

The documentation for this class was generated from the following files:
arm_compute::CLKernelLibrary::context
cl::Context & context()
Accessor for the associated CL context.
Definition: CLKernelLibrary.cpp:65
arm_compute::CLCompileContext::fp16_supported
bool fp16_supported() const
Returns true if FP16 is supported by the CL device.
Definition: CLCompileContext.cpp:283
arm_compute::CLCompileContext::default_ndrange
cl::NDRange default_ndrange() const
Return the default NDRange for the device.
Definition: CLCompileContext.cpp:338
arm_compute::CLCompileContext::context
cl::Context & context()
Accessor for the associated CL context.
Definition: CLCompileContext.cpp:322
arm_compute::opencl::ClKernelLibrary::program
ClProgramInfo program(const std::string &program_name) const
Gets the source of the selected program.
Definition: ClKernelLibrary.cpp:1041
arm_compute::CLCompileContext::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: CLCompileContext.cpp:368
arm_compute::CLCompileContext::is_wbsm_supported
bool is_wbsm_supported() const
Definition: CLCompileContext.cpp:363
arm_compute::CLCompileContext::int64_base_atomics_supported
bool int64_base_atomics_supported() const
Returns true if int64_base_atomics extension is supported by the CL device.
Definition: CLCompileContext.cpp:358
arm_compute::CLCompileContext::get_num_compute_units
cl_uint get_num_compute_units() const
Return the maximum number of compute units in the device.
Definition: CLCompileContext.cpp:384
arm_compute::opencl::ClKernelLibrary::set_kernel_path
void set_kernel_path(std::string kernel_path)
Sets the path that the kernels reside in.
Definition: ClKernelLibrary.cpp:1030
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:39
arm_compute::CLCompileContext::set_context
void set_context(cl::Context context)
Sets the CL context used to create programs.
Definition: CLCompileContext.cpp:218
arm_compute::opencl::ClKernelLibrary::program_name
std::string program_name(const std::string &kernel_name) const
Returns the program name given a kernel name.
Definition: ClKernelLibrary.cpp:1015
arm_compute::CLCompileContext::get_device
const cl::Device & get_device() const
Gets the CL device for which the programs are created.
Definition: CLCompileContext.cpp:327
arm_compute::CLCompileContext::clear_programs_cache
void clear_programs_cache()
Clear the library's cache of binary programs.
Definition: CLCompileContext.cpp:311
arm_compute::CLCompileContext::set_device
void set_device(cl::Device device)
Sets the CL device for which the programs are created.
Definition: CLCompileContext.cpp:332
arm_compute::CLCompileContext::get_device_version
std::string get_device_version() const
Return the device version.
Definition: CLCompileContext.cpp:379
arm_compute::opencl::ClKernelLibrary::get
static ClKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: ClKernelLibrary.cpp:1009
arm_compute::CLCompileContext::create_kernel
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.
Definition: CLCompileContext.cpp:159
arm_compute::opencl::ClKernelLibrary::kernel_path
const std::string & kernel_path() const
Gets the path that the kernels reside in.
Definition: ClKernelLibrary.cpp:1036
arm_compute::CLCompileContext::get_built_programs
const std::map< std::string, cl::Program > & get_built_programs() const
Access the cache of built OpenCL programs.
Definition: CLCompileContext.cpp:317
arm_compute::CLKernelLibrary::get_kernel_path
std::string get_kernel_path()
Gets the path that the kernels reside in.
Definition: CLKernelLibrary.cpp:81
arm_compute::CLCompileContext::add_built_program
void add_built_program(const std::string &built_program_name, const cl::Program &program) const
Add a new built program to the cache.
Definition: CLCompileContext.cpp:306
kernel_name
std::string kernel_name
Definition: ClIm2ColKernel.cpp:57