diff options
author | shubham <shub98.gupta@samsung.com> | 2019-01-07 21:37:55 +0530 |
---|---|---|
committer | Georgios Pinitas <georgios.pinitas@arm.com> | 2019-01-08 16:27:21 +0000 |
commit | e1a4e37ac266324de366401f2bda459b011a4869 (patch) | |
tree | 60881f6ce7af53f0286a1313f1998d10643051eb /src/core/CL/kernels | |
parent | d33fe343103edbea4fb1cf6121c49caef36ff379 (diff) | |
download | ComputeLibrary-e1a4e37ac266324de366401f2bda459b011a4869.tar.gz |
Implementation of Permute CL kernel to handle all permutations
This patch will add a generic permute cl-kernel to handle
all permutations available for tensors having rank upto 4.
Change-Id: I50eb555d9d45d5ad5f7fa9b0a3862dd17551d458
Signed-off-by: shubham <shub98.gupta@samsung.com>
Reviewed-on: https://review.mlplatform.org/449
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Manuel Bottini <manuel.bottini@arm.com>
Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
Diffstat (limited to 'src/core/CL/kernels')
-rw-r--r-- | src/core/CL/kernels/CLPermuteKernel.cpp | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/core/CL/kernels/CLPermuteKernel.cpp b/src/core/CL/kernels/CLPermuteKernel.cpp index a9a2c5c97a..6c44199f7a 100644 --- a/src/core/CL/kernels/CLPermuteKernel.cpp +++ b/src/core/CL/kernels/CLPermuteKernel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 ARM Limited. + * Copyright (c) 2018-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -56,16 +56,20 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, c DataType::U16, DataType::S16, DataType::U32, DataType::S32, DataType::F16, DataType::F32); - ARM_COMPUTE_RETURN_ERROR_ON_MSG((perm != PermutationVector{ 2U, 0U, 1U }) - && (perm != PermutationVector{ 1U, 2U, 0U }) - && (perm != PermutationVector{ 3U, 2U, 0U, 1U }), - "Only [2, 0, 1], [1, 2, 0] and [3, 2, 0, 1] permutation is supported"); - const TensorShape output_shape = misc::shape_calculator::compute_permutation_output_shape(*input, perm); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->num_dimensions() < 1 || input->num_dimensions() > 4, + "Permutation upto 4-D input tensor is supported"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(perm.num_dimensions() < 1 || perm.num_dimensions() > 4, + "Permutation vector size should be less than or equal to 4"); + for(const auto &p : perm) + { + ARM_COMPUTE_RETURN_ERROR_ON_MSG(p >= perm.num_dimensions(), "Permutation vector has invalid values"); + } // Validate configured output if(output->total_size() != 0) { + const TensorShape output_shape = misc::shape_calculator::compute_permutation_output_shape(*input, perm); ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape); ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); } @@ -87,30 +91,16 @@ void CLPermuteKernel::configure(const ICLTensor *input, ICLTensor *output, const auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape)); // Create kernel - std::set<std::string> build_opts; - - build_opts.emplace("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); - build_opts.emplace("-DDEPTH_IN=" + support::cpp11::to_string(input->info()->dimension(2))); - - // Run [2, 0, 1] permute - if(_perm == PermutationVector{ 2U, 0U, 1U }) - { - _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("permute_201", build_opts)); - } - // Run [1, 2, 0] permute - else if(_perm == PermutationVector{ 1U, 2U, 0U }) - { - _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("permute_120", build_opts)); - } - // Run [3, 2, 0, 1] permute - else if(_perm == PermutationVector{ 3U, 2U, 0U, 1U }) - { - _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("permute_3201", build_opts)); - } - else - { - ARM_COMPUTE_ERROR("Not supported."); - } + CLBuildOptions build_opts; + build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())); + build_opts.add_option("-DDEPTH_IN=" + support::cpp11::to_string(input->info()->dimension(2))); + // New positions of width(W), height(H), channel(C) and batch(D) based on permutation vector + build_opts.add_option("-DP1=" + support::cpp11::to_string((_perm.num_dimensions() >= 1) ? perm[0] : 0)); + build_opts.add_option("-DP2=" + support::cpp11::to_string((_perm.num_dimensions() >= 2) ? perm[1] : 1)); + build_opts.add_option("-DP3=" + support::cpp11::to_string((_perm.num_dimensions() >= 3) ? perm[2] : 2)); + build_opts.add_option("-DP4=" + support::cpp11::to_string((_perm.num_dimensions() >= 4) ? perm[3] : 3)); + + _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("permute", build_opts.options())); // Configure kernel window Window win = calculate_max_window(*input->info(), Steps()); |