aboutsummaryrefslogtreecommitdiff
path: root/tests/validation
diff options
context:
space:
mode:
Diffstat (limited to 'tests/validation')
-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
5 files changed, 617 insertions, 0 deletions
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__ */