// Initialize the ARM Compute Library and OpenCL voidinitialize_acl_opencl(){ // Set up OpenCL scheduler (initializes OpenCL context and queue) arm_compute::CLScheduler::get().default_init(); }
// Perform a convolution operation using OpenCL voidperform_convolution(){ // Define and allocate input/output tensors arm_compute::CLTensor input, output, weights; input.allocator()->init(arm_compute::TensorInfo(...)); // Specify tensor shape & format output.allocator()->init(arm_compute::TensorInfo(...)); weights.allocator()->init(arm_compute::TensorInfo(...));
// Configure convolution layer arm_compute::CLConvolutionLayer conv; conv.configure(&input, &weights, nullptr, &output, ...); // Configure with your parameters
// Allocate memory for tensors input.allocator()->allocate(); output.allocator()->allocate(); weights.allocator()->allocate();
* @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], * while every optional dimension from 4and above represent a batch of inputs. * Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32. * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. * Data type supported: Same as @p input, also could be QSYMM8_PER_CHANNEL if input is QASYMM8/QASYMM8_SIGNED. * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. * Data type supported: Same as @p input, except for input of QASYMM8/QASYMM8_SIGNED type where biases should be of S32 type. * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. * Data types supported: Same as @p input. * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. * @param[in] weights_info Specifies if the weights tensor has been reshaped with CLWeightsReshapeKernel. Data type supported: Same as @p input. * @param[in] dilation (Optional) Dilation, in elements, across x and y. Defaults to(1, 1). * @param[in] act_info(Optional) Activation layer information in case of a fused activation. * @param[in] enable_fast_math(Optional) Enable fast math computation. In casethis flag were set, the function could dispatch the fastest implementation * available which may introduce a drop of accuracy as well. Default is false * @param[in] num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is only supported for NCHW data layout */ voidconfigure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, const WeightsInfo &weights_info = WeightsInfo(), const Size2D &dilation = Size2D(1U, 1U), const ActivationLayerInfo &act_info = ActivationLayerInfo(), bool enable_fast_math = false, unsignedint num_groups = 1);
/** Constructor * * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1. * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1. * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0. * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0. * @param[in] round (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR. */
可以看到对于卷积层,我们有 stride,表示每隔多少元素进行一次卷积,有 pad 表示图像的边缘补上 0。
WeightsInfo
1 2 3 4 5 6 7 8 9
/** Constructor * * @param[in] are_reshaped True if the weights have been reshaped * @param[in] kernel_width Kernel width. * @param[in] kernel_height Kernel height. * @param[in] num_kernels Number of convolution kernels. * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false. * @param[in] weight_format (Optional) arm_gemm:WeightFormat enumeration requested by the user. Default is arm_compute::WeightFormat::UNSPECIFIED. */
可以看到有 基础的 kernel 信息,kernel 个数(获取最后的输出深度)等等。
Size2D
就是基础的 WH:
1 2 3 4 5
/** Constructor. Initializes "width" and "height" respectively with "w" and "h" * * @param[in] w Width of the image or rectangle * @param[in] h Height of the image or rectangle */
ActivationLayerInfo
可以主要是 activation func:
1 2 3 4 5 6 7
/** Default Constructor * * @param[in] f The activation function to use. * @param[in] a (Optional) The alpha parameter used by some activation functions * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH). * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH). */