aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIoan-Cristian Szabo <ioan-cristian.szabo@arm.com>2017-10-27 17:35:40 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit91d20d95df35961d3eb5de497007d98576118d19 (patch)
tree13042e212d65fbf5bd7425079bb72b6bd1e2e84d /tests
parent19835e591cb0b66a0f5000ae1505bf299e50337d (diff)
downloadComputeLibrary-91d20d95df35961d3eb5de497007d98576118d19.tar.gz
COMPMID-582: Add validation to channel_extract kernels.
Change-Id: I6413a05f6870a0d04f12d7348269b15297ae8493 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114696 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/AssetsLibrary.h28
-rw-r--r--tests/SimpleTensor.h23
-rw-r--r--tests/Utils.h18
-rw-r--r--tests/validation/CL/ChannelExtract.cpp153
-rw-r--r--tests/validation/NEON/ChannelExtract.cpp153
-rw-r--r--tests/validation/fixtures/ChannelExtractFixture.h192
-rw-r--r--tests/validation/reference/ChannelExtract.cpp76
-rw-r--r--tests/validation/reference/ChannelExtract.h43
8 files changed, 668 insertions, 18 deletions
diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h
index 9c93ee0757..afdf714ff1 100644
--- a/tests/AssetsLibrary.h
+++ b/tests/AssetsLibrary.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -416,22 +416,24 @@ void AssetsLibrary::fill_borders_with_garbage(T &&tensor, D &&distribution, std:
template <typename T, typename D>
void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
{
- Window window;
- for(unsigned int d = 0; d < tensor.shape().num_dimensions(); ++d)
- {
- window.set(d, Window::Dimension(0, tensor.shape()[d], 1));
- }
+ using ResultType = typename std::remove_reference<D>::type::result_type;
std::mt19937 gen(_seed + seed_offset);
- //FIXME: Replace with normal loop
- execute_window_loop(window, [&](const Coordinates & id)
+ // Iterate over all elements
+ for(int element_idx = 0; element_idx < tensor.num_elements(); ++element_idx)
{
- using ResultType = typename std::remove_reference<D>::type::result_type;
- const ResultType value = distribution(gen);
- void *const out_ptr = tensor(id);
- store_value_with_data_type(out_ptr, value, tensor.data_type());
- });
+ const Coordinates id = index2coord(tensor.shape(), element_idx);
+
+ // Iterate over all channels
+ for(int channel = 0; channel < tensor.num_channels(); ++channel)
+ {
+ const ResultType value = distribution(gen);
+ ResultType &target_value = reinterpret_cast<ResultType *const>(tensor(id))[channel];
+
+ store_value_with_data_type(&target_value, value, tensor.data_type());
+ }
+ }
fill_borders_with_garbage(tensor, distribution, seed_offset);
}
diff --git a/tests/SimpleTensor.h b/tests/SimpleTensor.h
index 902f5b51b5..f3155ffeab 100644
--- a/tests/SimpleTensor.h
+++ b/tests/SimpleTensor.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -297,18 +297,33 @@ int SimpleTensor<T>::num_channels() const
switch(_format)
{
case Format::U8:
- case Format::S16:
case Format::U16:
- case Format::S32:
+ case Format::S16:
case Format::U32:
+ case Format::S32:
+ case Format::F16:
case Format::F32:
return 1;
+ // Because the U and V channels are subsampled
+ // these formats appear like having only 2 channels:
+ case Format::YUYV422:
+ case Format::UYVY422:
+ return 2;
+ case Format::UV88:
+ return 2;
case Format::RGB888:
return 3;
+ case Format::RGBA8888:
+ return 4;
case Format::UNKNOWN:
return _num_channels;
+ //Doesn't make sense for planar formats:
+ case Format::NV12:
+ case Format::NV21:
+ case Format::IYUV:
+ case Format::YUV444:
default:
- ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ return 0;
}
}
diff --git a/tests/Utils.h b/tests/Utils.h
index 750d907778..27e0397b6b 100644
--- a/tests/Utils.h
+++ b/tests/Utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -500,6 +500,22 @@ inline T create_tensor(const TensorShape &shape, Format format)
return tensor;
}
+/** Create and initialize a multi-image of the given type.
+ *
+ * @param[in] shape Tensor shape.
+ * @param[in] format Format type.
+ *
+ * @return Initialized tensor of given type.
+ */
+template <typename T>
+inline T create_multi_image(const TensorShape &shape, Format format)
+{
+ T multi_image;
+ multi_image.init(shape.x(), shape.y(), format);
+
+ return multi_image;
+}
+
/** Create and initialize a HOG (Histogram of Oriented Gradients) of the given type.
*
* @param[in] cell_size Cell size in pixels
diff --git a/tests/validation/CL/ChannelExtract.cpp b/tests/validation/CL/ChannelExtract.cpp
new file mode 100644
index 0000000000..1248a2072d
--- /dev/null
+++ b/tests/validation/CL/ChannelExtract.cpp
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017-2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CL/CLMultiImage.h"
+#include "arm_compute/runtime/CL/CLTensor.h"
+#include "arm_compute/runtime/CL/CLTensorAllocator.h"
+#include "arm_compute/runtime/CL/functions/CLChannelExtract.h"
+#include "tests/CL/CLAccessor.h"
+#include "tests/PaddingCalculator.h"
+#include "tests/datasets/ConvertPolicyDataset.h"
+#include "tests/datasets/ShapeDatasets.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "tests/validation/fixtures/ChannelExtractFixture.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+// Input data sets
+const auto ChannelExtractRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }),
+ framework::dataset::make("ChannelType", { Channel::R, Channel::G, Channel::B, Channel::A }));
+const auto ChannelExtractYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }),
+ framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V }));
+const auto ChannelExtractYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::YUV444, Format::NV12, Format::NV21 }),
+ framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V }));
+
+inline void validate_configuration(const TensorShape &shape, Format format, Channel channel)
+{
+ const unsigned int num_planes = num_planes_from_format(format);
+
+ TensorShape dst_shape = adjust_odd_shape(shape, format);
+ dst_shape = calculate_subsampled_shape(dst_shape, format, channel);
+
+ // Create tensors
+ CLMultiImage ref_src = create_multi_image<CLMultiImage>(shape, format);
+ CLTensor dst = create_tensor<CLTensor>(dst_shape, Format::U8);
+
+ // Create and Configure function
+ CLChannelExtract channel_extract;
+
+ if(1U == num_planes)
+ {
+ const CLTensor *plane_src = ref_src.cl_plane(0);
+
+ channel_extract.configure(plane_src, channel, &dst);
+ }
+ else
+ {
+ channel_extract.configure(&ref_src, channel, &dst);
+ }
+
+ // TODO(bsgcomp): Add validation for padding and shape (COMPMID-659)
+}
+} // namespace
+
+TEST_SUITE(CL)
+TEST_SUITE(ChannelExtract)
+
+template <typename T>
+using CLChannelExtractFixture = ChannelExtractValidationFixture<CLMultiImage, CLTensor, CLAccessor, CLChannelExtract, T>;
+
+TEST_SUITE(Configuration)
+DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractRGBADataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVDataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+
+DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVPlanarDataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(RGBA)
+FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractRGBADataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractRGBADataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(YUV)
+FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVDataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVDataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(YUVPlanar)
+FIXTURE_DATA_TEST_CASE(RunSmall, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVPlanarDataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, CLChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVPlanarDataset))
+{
+ // Validate output
+ validate(CLAccessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE_END()
+TEST_SUITE_END()
+
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/NEON/ChannelExtract.cpp b/tests/validation/NEON/ChannelExtract.cpp
new file mode 100644
index 0000000000..4d8599a21d
--- /dev/null
+++ b/tests/validation/NEON/ChannelExtract.cpp
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017-2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/MultiImage.h"
+#include "arm_compute/runtime/NEON/functions/NEChannelExtract.h"
+#include "arm_compute/runtime/Tensor.h"
+#include "arm_compute/runtime/TensorAllocator.h"
+#include "tests/NEON/Accessor.h"
+#include "tests/PaddingCalculator.h"
+#include "tests/datasets/ConvertPolicyDataset.h"
+#include "tests/datasets/ShapeDatasets.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "tests/validation/fixtures/ChannelExtractFixture.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+// Input data sets
+const auto ChannelExtractRGBADataset = combine(framework::dataset::make("FormatType", { Format::RGBA8888 }),
+ framework::dataset::make("ChannelType", { Channel::R, Channel::G, Channel::B, Channel::A }));
+const auto ChannelExtractYUVDataset = combine(framework::dataset::make("FormatType", { Format::YUYV422, Format::UYVY422 }),
+ framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V }));
+const auto ChannelExtractYUVPlanarDataset = combine(framework::dataset::make("FormatType", { Format::IYUV, Format::YUV444, Format::NV12, Format::NV21 }),
+ framework::dataset::make("ChannelType", { Channel::Y, Channel::U, Channel::V }));
+
+inline void validate_configuration(const TensorShape &shape, Format format, Channel channel)
+{
+ const unsigned int num_planes = num_planes_from_format(format);
+
+ TensorShape dst_shape = adjust_odd_shape(shape, format);
+ dst_shape = calculate_subsampled_shape(dst_shape, format, channel);
+
+ // Create tensors
+ MultiImage ref_src = create_multi_image<MultiImage>(shape, format);
+ Tensor dst = create_tensor<Tensor>(dst_shape, Format::U8);
+
+ // Create and Configure function
+ NEChannelExtract channel_extract;
+
+ if(1U == num_planes)
+ {
+ const Tensor *plane_src = ref_src.plane(0);
+
+ channel_extract.configure(plane_src, channel, &dst);
+ }
+ else
+ {
+ channel_extract.configure(&ref_src, channel, &dst);
+ }
+
+ // TODO(bsgcomp): Add validation for padding and shape (COMPMID-659)
+}
+} // namespace
+
+TEST_SUITE(NEON)
+TEST_SUITE(ChannelExtract)
+
+template <typename T>
+using NEChannelExtractFixture = ChannelExtractValidationFixture<MultiImage, Tensor, Accessor, NEChannelExtract, T>;
+
+TEST_SUITE(Configuration)
+DATA_TEST_CASE(RGBA, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractRGBADataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+DATA_TEST_CASE(YUV, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVDataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+
+DATA_TEST_CASE(YUVPlanar, framework::DatasetMode::ALL, combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), ChannelExtractYUVPlanarDataset),
+ shape, format, channel)
+{
+ validate_configuration(shape, format, channel);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(RGBA)
+FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractRGBADataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractRGBADataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(YUV)
+FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVDataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVDataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE(YUVPlanar)
+FIXTURE_DATA_TEST_CASE(RunSmall, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small2DShapes(), ChannelExtractYUVPlanarDataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+FIXTURE_DATA_TEST_CASE(RunLarge, NEChannelExtractFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::Large2DShapes(), ChannelExtractYUVPlanarDataset))
+{
+ // Validate output
+ validate(Accessor(_target), _reference);
+}
+TEST_SUITE_END()
+
+TEST_SUITE_END()
+TEST_SUITE_END()
+
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/fixtures/ChannelExtractFixture.h b/tests/validation/fixtures/ChannelExtractFixture.h
new file mode 100644
index 0000000000..c3c2e17d09
--- /dev/null
+++ b/tests/validation/fixtures/ChannelExtractFixture.h
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2017-2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE
+#define ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE
+
+#include "arm_compute/core/TensorShape.h"
+#include "arm_compute/core/Types.h"
+#include "tests/AssetsLibrary.h"
+#include "tests/Globals.h"
+#include "tests/IAccessor.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Fixture.h"
+#include "tests/validation/Helpers.h"
+#include "tests/validation/reference/ChannelExtract.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+template <typename MultiImageType, typename TensorType, typename AccessorType, typename FunctionType, typename T>
+class ChannelExtractValidationFixture : public framework::Fixture
+{
+public:
+ template <typename...>
+ void setup(TensorShape shape, Format format, Channel channel)
+ {
+ shape = adjust_odd_shape(shape, format);
+
+ _target = compute_target(shape, format, channel);
+ _reference = compute_reference(shape, format, channel);
+ }
+
+protected:
+ template <typename U>
+ void fill(U &&tensor, int i)
+ {
+ library->fill_tensor_uniform(tensor, i);
+ }
+
+ std::vector<SimpleTensor<T>> create_tensor_planes_reference(const TensorShape &shape, Format format)
+ {
+ TensorShape input = adjust_odd_shape(shape, format);
+
+ std::vector<SimpleTensor<T>> tensor_planes;
+
+ switch(format)
+ {
+ case Format::RGB888:
+ case Format::RGBA8888:
+ case Format::YUYV422:
+ case Format::UYVY422:
+ {
+ tensor_planes.emplace_back(input, format);
+ break;
+ }
+ case Format::NV12:
+ case Format::NV21:
+ {
+ const TensorShape shape_uv88 = calculate_subsampled_shape(shape, Format::UV88);
+
+ tensor_planes.emplace_back(input, Format::U8);
+ tensor_planes.emplace_back(shape_uv88, Format::UV88);
+ break;
+ }
+ case Format::IYUV:
+ {
+ const TensorShape shape_sub2 = calculate_subsampled_shape(shape, Format::IYUV);
+
+ tensor_planes.emplace_back(input, Format::U8);
+ tensor_planes.emplace_back(shape_sub2, Format::U8);
+ tensor_planes.emplace_back(shape_sub2, Format::U8);
+ break;
+ }
+ case Format::YUV444:
+ tensor_planes.emplace_back(input, Format::U8);
+ tensor_planes.emplace_back(input, Format::U8);
+ tensor_planes.emplace_back(input, Format::U8);
+ break;
+ default:
+ ARM_COMPUTE_ERROR("Not supported");
+ break;
+ }
+
+ return tensor_planes;
+ }
+
+ TensorType compute_target(const TensorShape &shape, Format format, Channel channel)
+ {
+ const unsigned int num_planes = num_planes_from_format(format);
+
+ TensorShape dst_shape = calculate_subsampled_shape(shape, format, channel);
+
+ // Create tensors
+ MultiImageType ref_src = create_multi_image<MultiImageType>(shape, format);
+ TensorType dst = create_tensor<TensorType>(dst_shape, Format::U8);
+
+ // Create and configure function
+ FunctionType channel_extract;
+
+ if(1U == num_planes)
+ {
+ const TensorType *plane_src = static_cast<TensorType *>(ref_src.plane(0));
+
+ channel_extract.configure(plane_src, channel, &dst);
+ }
+ else
+ {
+ channel_extract.configure(&ref_src, channel, &dst);
+ }
+
+ for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
+ {
+ const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx));
+
+ ARM_COMPUTE_EXPECT(src_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
+ }
+
+ ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Allocate tensors
+ ref_src.allocate();
+ dst.allocator()->allocate();
+
+ for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
+ {
+ const TensorType *src_plane = static_cast<const TensorType *>(ref_src.plane(plane_idx));
+
+ ARM_COMPUTE_EXPECT(!src_plane->info()->is_resizable(), framework::LogLevel::ERRORS);
+ }
+
+ ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
+
+ // Fill tensor planes
+ for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
+ {
+ TensorType *src_plane = static_cast<TensorType *>(ref_src.plane(plane_idx));
+
+ fill(AccessorType(*src_plane), plane_idx);
+ }
+
+ // Compute function
+ channel_extract.run();
+
+ return dst;
+ }
+
+ SimpleTensor<T> compute_reference(const TensorShape &shape, Format format, Channel channel)
+ {
+ const unsigned int num_planes = num_planes_from_format(format);
+
+ // Create reference
+ std::vector<SimpleTensor<T>> ref_src = create_tensor_planes_reference(shape, format);
+
+ // Fill references
+ for(unsigned int plane_idx = 0; plane_idx < num_planes; ++plane_idx)
+ {
+ fill(ref_src[plane_idx], plane_idx);
+ }
+
+ return reference::channel_extract<T>(shape, ref_src, format, channel);
+ }
+
+ TensorType _target{};
+ SimpleTensor<T> _reference{};
+};
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_TEST_CHANNEL_EXTRACT_FIXTURE */
diff --git a/tests/validation/reference/ChannelExtract.cpp b/tests/validation/reference/ChannelExtract.cpp
new file mode 100644
index 0000000000..595bb13098
--- /dev/null
+++ b/tests/validation/reference/ChannelExtract.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2017-2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "ChannelExtract.h"
+
+#include "arm_compute/core/Types.h"
+#include "tests/validation/FixedPoint.h"
+#include "tests/validation/Helpers.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel)
+{
+ // Find plane and channel index
+ const unsigned int plane_idx = plane_idx_from_channel(format, channel);
+ const unsigned int channel_idx = channel_idx_from_format(format, channel);
+
+ // Create dst and get src tensor
+ SimpleTensor<T> src = tensor_planes[plane_idx];
+ SimpleTensor<T> dst{ calculate_subsampled_shape(shape, format, channel), Format::U8 };
+
+ // Single planar formats with subsampling require a double horizontal step
+ const int step_x = ((Format::YUYV422 == format || Format::UYVY422 == format) && Channel::Y != channel) ? 2 : 1;
+ const int width = dst.shape().x();
+ const int height = dst.shape().y();
+
+ // Loop over each pixel and extract channel
+ for(int y = 0; y < height; ++y)
+ {
+ for(int x = 0; x < width; ++x)
+ {
+ const Coordinates src_coord{ x * step_x, y };
+ const Coordinates dst_coord{ x, y };
+
+ const auto *src_pixel = reinterpret_cast<const T *>(src(src_coord));
+ auto *dst_pixel = reinterpret_cast<T *>(dst(dst_coord));
+
+ dst_pixel[0] = src_pixel[channel_idx];
+ }
+ }
+
+ return dst;
+}
+
+template SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<uint8_t>> &tensor_planes, Format format, Channel channel);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation/reference/ChannelExtract.h b/tests/validation/reference/ChannelExtract.h
new file mode 100644
index 0000000000..ac7aefbdee
--- /dev/null
+++ b/tests/validation/reference/ChannelExtract.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017-2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__
+#define __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__
+
+#include "tests/SimpleTensor.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace reference
+{
+template <typename T>
+SimpleTensor<uint8_t> channel_extract(const TensorShape &shape, const std::vector<SimpleTensor<T>> &tensor_planes, Format format, Channel channel);
+} // namespace reference
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_TEST_CHANNEL_EXTRACT_H__ */