aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/validation/CL/MinMaxLocation.cpp300
-rw-r--r--tests/validation/Reference.cpp2
-rw-r--r--tests/validation/Reference.h3
-rw-r--r--tests/validation/ReferenceCPP.cpp2
-rw-r--r--tests/validation/ReferenceCPP.h2
-rw-r--r--tests/validation/TensorOperations.h2
-rw-r--r--tests/validation/TensorVisitors.h14
-rw-r--r--tests/validation/Validation.cpp18
-rw-r--r--tests/validation/Validation.h2
9 files changed, 327 insertions, 18 deletions
diff --git a/tests/validation/CL/MinMaxLocation.cpp b/tests/validation/CL/MinMaxLocation.cpp
new file mode 100644
index 0000000000..0646ad9bbf
--- /dev/null
+++ b/tests/validation/CL/MinMaxLocation.cpp
@@ -0,0 +1,300 @@
+/*
+ * Copyright (c) 2017 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 "AssetsLibrary.h"
+#include "CL/CLAccessor.h"
+#include "Globals.h"
+#include "TypePrinter.h"
+#include "Utils.h"
+#include "validation/Datasets.h"
+#include "validation/Reference.h"
+#include "validation/Validation.h"
+
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/CL/functions/CLMinMaxLocation.h"
+#include "arm_compute/runtime/Tensor.h"
+#include "arm_compute/runtime/TensorAllocator.h"
+
+#include "PaddingCalculator.h"
+#include "boost_wrapper.h"
+
+#include <random>
+#include <string>
+
+using namespace arm_compute;
+using namespace arm_compute::test;
+using namespace arm_compute::test::validation;
+
+namespace
+{
+/** Compute CL MinMaxLocation function.
+*
+* @param[in] shape Shape of the input and output tensors.
+* @param[in] dt_in Data type of first input tensor.
+*
+* @return Computed output tensor.
+*/
+void compute_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max,
+ CLCoordinates2DArray &min_loc, CLCoordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count)
+{
+ // Create tensor
+ CLTensor src = create_tensor<CLTensor>(shape, dt_in);
+ src.info()->set_format((dt_in == DataType::U8) ? Format::U8 : Format::S16);
+
+ // Create and configure min_max_location configure function
+ CLMinMaxLocation min_max_loc;
+ min_max_loc.configure(&src, &min, &max, &min_loc, &max_loc, &min_count, &max_count);
+
+ // Allocate tensors
+ src.allocator()->allocate();
+
+ BOOST_TEST(!src.info()->is_resizable());
+
+ // Fill tensors
+ library->fill_tensor_uniform(CLAccessor(src), 0);
+
+ // Compute function
+ min_max_loc.run();
+}
+
+void validate_configuration(const CLTensor &src, TensorShape shape)
+{
+ BOOST_TEST(src.info()->is_resizable());
+
+ // Create output storage
+ int32_t min;
+ int32_t max;
+ CLCoordinates2DArray min_loc(shape.total_size());
+ CLCoordinates2DArray max_loc(shape.total_size());
+ uint32_t min_count;
+ uint32_t max_count;
+
+ // Create and configure function
+ CLMinMaxLocation min_max_loc;
+ min_max_loc.configure(&src, &min, &max, &min_loc, &max_loc, &min_count, &max_count);
+
+ // Validate valid region
+ const ValidRegion valid_region = shape_to_valid_region(shape);
+ validate(src.info()->valid_region(), valid_region);
+
+ // Validate padding
+ const PaddingSize padding = PaddingCalculator(shape.x(), src.info()->dimension(0)).required_padding();
+ validate(src.info()->padding(), padding);
+}
+} // namespace
+
+#ifndef DOXYGEN_SKIP_THIS
+BOOST_AUTO_TEST_SUITE(CL)
+BOOST_AUTO_TEST_SUITE(MinMaxLocation)
+BOOST_AUTO_TEST_SUITE(U8)
+
+BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
+BOOST_DATA_TEST_CASE(Configuration, (Small2DShapes() + Large2DShapes()),
+ shape)
+{
+ // Create tensor
+ CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
+ src.info()->set_format(Format::U8);
+
+ validate_configuration(src, shape);
+}
+
+BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
+BOOST_DATA_TEST_CASE(RunSmall, Small2DShapes(),
+ shape)
+{
+ // Create output storage
+ int32_t min;
+ int32_t max;
+ CLCoordinates2DArray min_loc(shape.total_size());
+ CLCoordinates2DArray max_loc(shape.total_size());
+ uint32_t min_count;
+ uint32_t max_count;
+
+ int32_t ref_min;
+ int32_t ref_max;
+ CLCoordinates2DArray ref_min_loc(shape.total_size());
+ CLCoordinates2DArray ref_max_loc(shape.total_size());
+ uint32_t ref_min_count;
+ uint32_t ref_max_count;
+
+ // Compute function
+ compute_min_max_location(shape, DataType::U8, min, max, min_loc, max_loc, min_count, max_count);
+
+ // Compute reference
+ ref_min_loc.map();
+ ref_max_loc.map();
+
+ Reference::compute_reference_min_max_location(shape, DataType::U8, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
+
+ min_loc.map();
+ max_loc.map();
+
+ // Validate output
+ validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
+
+ ref_min_loc.unmap();
+ ref_max_loc.unmap();
+ min_loc.unmap();
+ max_loc.unmap();
+}
+
+BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
+BOOST_DATA_TEST_CASE(RunLarge, Large2DShapes(),
+ shape)
+{
+ // Create output storage
+ int32_t min;
+ int32_t max;
+ CLCoordinates2DArray min_loc(shape.total_size());
+ CLCoordinates2DArray max_loc(shape.total_size());
+ uint32_t min_count;
+ uint32_t max_count;
+
+ int32_t ref_min;
+ int32_t ref_max;
+ CLCoordinates2DArray ref_min_loc(shape.total_size());
+ CLCoordinates2DArray ref_max_loc(shape.total_size());
+ uint32_t ref_min_count;
+ uint32_t ref_max_count;
+
+ // Compute function
+ compute_min_max_location(shape, DataType::U8, min, max, min_loc, max_loc, min_count, max_count);
+
+ // Compute reference
+ ref_min_loc.map();
+ ref_max_loc.map();
+
+ Reference::compute_reference_min_max_location(shape, DataType::U8, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
+
+ min_loc.map();
+ max_loc.map();
+
+ // Validate output
+ validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
+
+ ref_min_loc.unmap();
+ ref_max_loc.unmap();
+ min_loc.unmap();
+ max_loc.unmap();
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE(S16)
+BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
+BOOST_DATA_TEST_CASE(Configuration, (Small2DShapes() + Large2DShapes()),
+ shape)
+{
+ // Create tensor
+ CLTensor src = create_tensor<CLTensor>(shape, DataType::S16);
+ src.info()->set_format(Format::S16);
+
+ validate_configuration(src, shape);
+}
+
+BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
+BOOST_DATA_TEST_CASE(RunSmall, Small2DShapes(),
+ shape)
+{
+ // Create output storage
+ int32_t min;
+ int32_t max;
+ CLCoordinates2DArray min_loc(shape.total_size());
+ CLCoordinates2DArray max_loc(shape.total_size());
+ uint32_t min_count;
+ uint32_t max_count;
+
+ int32_t ref_min;
+ int32_t ref_max;
+ CLCoordinates2DArray ref_min_loc(shape.total_size());
+ CLCoordinates2DArray ref_max_loc(shape.total_size());
+ uint32_t ref_min_count;
+ uint32_t ref_max_count;
+
+ // Compute function
+ compute_min_max_location(shape, DataType::S16, min, max, min_loc, max_loc, min_count, max_count);
+
+ // Compute reference
+ ref_min_loc.map();
+ ref_max_loc.map();
+
+ Reference::compute_reference_min_max_location(shape, DataType::S16, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
+
+ min_loc.map();
+ max_loc.map();
+
+ // Validate output
+ validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
+
+ ref_min_loc.unmap();
+ ref_max_loc.unmap();
+ min_loc.unmap();
+ max_loc.unmap();
+}
+
+BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
+BOOST_DATA_TEST_CASE(RunLarge, Large2DShapes(),
+ shape)
+{
+ // Create output storage
+ int32_t min;
+ int32_t max;
+ CLCoordinates2DArray min_loc(shape.total_size());
+ CLCoordinates2DArray max_loc(shape.total_size());
+ uint32_t min_count;
+ uint32_t max_count;
+
+ int32_t ref_min;
+ int32_t ref_max;
+ CLCoordinates2DArray ref_min_loc(shape.total_size());
+ CLCoordinates2DArray ref_max_loc(shape.total_size());
+ uint32_t ref_min_count;
+ uint32_t ref_max_count;
+
+ // Compute function
+ compute_min_max_location(shape, DataType::S16, min, max, min_loc, max_loc, min_count, max_count);
+
+ // Compute reference
+ ref_min_loc.map();
+ ref_max_loc.map();
+
+ Reference::compute_reference_min_max_location(shape, DataType::S16, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
+
+ min_loc.map();
+ max_loc.map();
+
+ // Validate output
+ validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
+
+ ref_min_loc.unmap();
+ ref_max_loc.unmap();
+ min_loc.unmap();
+ max_loc.unmap();
+}
+BOOST_AUTO_TEST_SUITE_END()
+
+BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END()
+#endif /* DOXYGEN_SKIP_THIS */ \ No newline at end of file
diff --git a/tests/validation/Reference.cpp b/tests/validation/Reference.cpp
index b838907320..1db3c3f5fb 100644
--- a/tests/validation/Reference.cpp
+++ b/tests/validation/Reference.cpp
@@ -71,7 +71,7 @@ std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_5x5(const Ten
return std::make_pair(ref_dst_x, ref_dst_y);
}
-void Reference::compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc,
+void Reference::compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc,
uint32_t &min_count, uint32_t &max_count)
{
// Create reference
diff --git a/tests/validation/Reference.h b/tests/validation/Reference.h
index 259afd19cd..c540ec48a1 100644
--- a/tests/validation/Reference.h
+++ b/tests/validation/Reference.h
@@ -72,7 +72,8 @@ public:
*
* @return Computed minimum, maximum values and their locations.
*/
- static void compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count,
+ static void compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc,
+ uint32_t &min_count,
uint32_t &max_count);
/** Compute reference mean and standard deviation.
*
diff --git a/tests/validation/ReferenceCPP.cpp b/tests/validation/ReferenceCPP.cpp
index a1dc4ceeac..07801aba1c 100644
--- a/tests/validation/ReferenceCPP.cpp
+++ b/tests/validation/ReferenceCPP.cpp
@@ -71,7 +71,7 @@ void ReferenceCPP::sobel_5x5(RawTensor &src, RawTensor &dst_x, RawTensor &dst_y,
}
// Minimum maximum location
-void ReferenceCPP::min_max_location(const RawTensor &src, int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count)
+void ReferenceCPP::min_max_location(const RawTensor &src, int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, uint32_t &min_count, uint32_t &max_count)
{
const TensorVariant s = TensorFactory::get_tensor(src);
boost::apply_visitor(tensor_visitors::min_max_location_visitor(min, max, min_loc, max_loc, min_count, max_count), s);
diff --git a/tests/validation/ReferenceCPP.h b/tests/validation/ReferenceCPP.h
index bc9ea476ad..248cdc4cc1 100644
--- a/tests/validation/ReferenceCPP.h
+++ b/tests/validation/ReferenceCPP.h
@@ -74,7 +74,7 @@ public:
* @param[out] min_count Number of minimum values found
* @param[out] max_count Number of maximum values found
*/
- static void min_max_location(const RawTensor &src, int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count);
+ static void min_max_location(const RawTensor &src, int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, uint32_t &min_count, uint32_t &max_count);
/** Function to compute the mean and standard deviation of a tensor.
*
* @param[in] src Input tensor.
diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h
index b8e5a6678c..4d067ac748 100644
--- a/tests/validation/TensorOperations.h
+++ b/tests/validation/TensorOperations.h
@@ -333,7 +333,7 @@ void sobel_5x5(Tensor<T1> &in, Tensor<T2> &out_x, Tensor<T2> &out_y, BorderMode
// Min max location
template <typename T1>
-void min_max_location(const Tensor<T1> &in, int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count)
+void min_max_location(const Tensor<T1> &in, int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, uint32_t &min_count, uint32_t &max_count)
{
// Set min and max to first pixel
min = in[0];
diff --git a/tests/validation/TensorVisitors.h b/tests/validation/TensorVisitors.h
index 168e212a65..223b76faaa 100644
--- a/tests/validation/TensorVisitors.h
+++ b/tests/validation/TensorVisitors.h
@@ -49,7 +49,7 @@ namespace tensor_visitors
struct min_max_location_visitor : public boost::static_visitor<>
{
public:
- explicit min_max_location_visitor(int32_t &min, int32_t &max, Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count)
+ explicit min_max_location_visitor(int32_t &min, int32_t &max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, uint32_t &min_count, uint32_t &max_count)
: _min(min), _max(max), _min_loc(min_loc), _max_loc(max_loc), _min_count(min_count), _max_count(max_count)
{
}
@@ -60,12 +60,12 @@ public:
}
private:
- int32_t &_min;
- int32_t &_max;
- Coordinates2DArray &_min_loc;
- Coordinates2DArray &_max_loc;
- uint32_t &_min_count;
- uint32_t &_max_count;
+ int32_t &_min;
+ int32_t &_max;
+ IArray<Coordinates2D> &_min_loc;
+ IArray<Coordinates2D> &_max_loc;
+ uint32_t &_min_count;
+ uint32_t &_max_count;
};
// Absolute Difference visitor
struct absolute_difference_visitor : public boost::static_visitor<>
diff --git a/tests/validation/Validation.cpp b/tests/validation/Validation.cpp
index e949e3c4f5..14ee98a96b 100644
--- a/tests/validation/Validation.cpp
+++ b/tests/validation/Validation.cpp
@@ -411,7 +411,7 @@ void validate(float target, float ref, float tolerance_abs_error, float toleranc
}
void validate_min_max_loc(int32_t min, int32_t ref_min, int32_t max, int32_t ref_max,
- Coordinates2DArray &min_loc, Coordinates2DArray &ref_min_loc, Coordinates2DArray &max_loc, Coordinates2DArray &ref_max_loc,
+ IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &ref_min_loc, IArray<Coordinates2D> &max_loc, IArray<Coordinates2D> &ref_max_loc,
uint32_t min_count, uint32_t ref_min_count, uint32_t max_count, uint32_t ref_max_count)
{
BOOST_TEST(min == ref_min);
@@ -427,14 +427,22 @@ void validate_min_max_loc(int32_t min, int32_t ref_min, int32_t max, int32_t ref
for(uint32_t i = 0; i < min_count; i++)
{
- BOOST_TEST(min_loc.at(i).x == ref_min_loc.at(i).x);
- BOOST_TEST(min_loc.at(i).y == ref_min_loc.at(i).y);
+ Coordinates2D *same_coords = std::find_if(ref_min_loc.buffer(), ref_min_loc.buffer() + min_count, [&min_loc, i](Coordinates2D coord)
+ {
+ return coord.x == min_loc.at(i).x && coord.y == min_loc.at(i).y;
+ });
+
+ BOOST_TEST(same_coords != ref_min_loc.buffer() + min_count);
}
for(uint32_t i = 0; i < max_count; i++)
{
- BOOST_TEST(max_loc.at(i).x == ref_max_loc.at(i).x);
- BOOST_TEST(max_loc.at(i).y == ref_max_loc.at(i).y);
+ Coordinates2D *same_coords = std::find_if(ref_max_loc.buffer(), ref_max_loc.buffer() + max_count, [&max_loc, i](Coordinates2D coord)
+ {
+ return coord.x == max_loc.at(i).x && coord.y == max_loc.at(i).y;
+ });
+
+ BOOST_TEST(same_coords != ref_max_loc.buffer() + max_count);
}
}
diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h
index e254c9f164..217ec63658 100644
--- a/tests/validation/Validation.h
+++ b/tests/validation/Validation.h
@@ -134,7 +134,7 @@ void validate(float target, float ref, float tolerance_abs_error = std::numeric_
* - All values should match
*/
void validate_min_max_loc(int32_t min, int32_t ref_min, int32_t max, int32_t ref_max,
- Coordinates2DArray &min_loc, Coordinates2DArray &ref_min_loc, Coordinates2DArray &max_loc, Coordinates2DArray &ref_max_loc,
+ IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &ref_min_loc, IArray<Coordinates2D> &max_loc, IArray<Coordinates2D> &ref_max_loc,
uint32_t min_count, uint32_t ref_min_count, uint32_t max_count, uint32_t ref_max_count);
} // namespace validation