From a8a7c1d2691fc688dabc275d8b68e5a1267f00af Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Tue, 12 May 2020 22:01:23 +0100 Subject: COMPMID-3295: Static input for ActivationLayer test suite - A member function added to AssetsLibrary to fill tensors with static values. - ActivationLayerFixture has been modified use the new function. - Redundant nightly tests are removed. Change-Id: Ib2a1103a1e438e808183170dc9d097599523c6ec Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3188 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- tests/AssetsLibrary.h | 68 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 7 deletions(-) (limited to 'tests/AssetsLibrary.h') diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 84653ed089..16ebff7ec0 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -392,6 +392,19 @@ public: template void fill_tensor_value(T &&tensor, D value) const; + /** Fill a tensor with a given vector with static values. + * + * @param[in, out] tensor To be filled tensor. + * @param[in] values A vector containing values + * + * To cope with various size tensors, the vector size doens't have to be + * the same as tensor's size. If the size of the tensor is larger than the vector, + * the iterator the vector will keep iterating and wrap around. If the vector is + * larger, values located after the required size won't be used. + */ + template + void fill_static_values(T &&tensor, const std::vector &values) const; + private: // Function prototype to convert between image formats. using Converter = void (*)(const RawTensor &src, RawTensor &dst); @@ -399,6 +412,9 @@ private: using Extractor = void (*)(const RawTensor &src, RawTensor &dst); // Function prototype to load an image file. using Loader = RawTensor (*)(const std::string &path); + // Function type to generate a number to fill tensors. + template + using GeneratorFunctionType = std::function; const Converter &get_converter(Format src, Format dst) const; const Converter &get_converter(DataType src, Format dst) const; @@ -443,6 +459,14 @@ private: */ const RawTensor &find_or_create_raw_tensor(const std::string &name, Format format, Channel channel) const; + /** Fill a tensor with a value generator function. + * + * @param[in, out] tensor To be filled tensor. + * @param[in] generate_value A function that generates values. + */ + template + void fill_with_generator(T &&tensor, const GeneratorFunctionType &generate_value) const; + mutable TensorCache _cache{}; mutable arm_compute::Mutex _format_lock{}; mutable arm_compute::Mutex _channel_lock{}; @@ -556,13 +580,9 @@ void AssetsLibrary::fill(std::vector &vec, D &&distribution, std::random_devi } } -template -void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const +template +void AssetsLibrary::fill_with_generator(T &&tensor, const GeneratorFunctionType &generate_value) const { - using ResultType = typename std::remove_reference::type::result_type; - - std::mt19937 gen(_seed + seed_offset); - const bool is_nhwc = tensor.data_layout() == DataLayout::NHWC; TensorShape shape(tensor.shape()); @@ -587,16 +607,50 @@ void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::resul // Iterate over all channels for(int channel = 0; channel < tensor.num_channels(); ++channel) { - const ResultType value = distribution(gen); + const ResultType value = generate_value(); ResultType &target_value = reinterpret_cast(tensor(id))[channel]; store_value_with_data_type(&target_value, value, tensor.data_type()); } } +} +template +void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const +{ + using ResultType = typename std::remove_reference::type::result_type; + std::mt19937 gen(_seed + seed_offset); + + GeneratorFunctionType number_generator = [&]() + { + const ResultType value = distribution(gen); + return value; + }; + + fill_with_generator(tensor, number_generator); fill_borders_with_garbage(tensor, distribution, seed_offset); } +template +void AssetsLibrary::fill_static_values(T &&tensor, const std::vector &values) const +{ + auto it = values.begin(); + GeneratorFunctionType get_next_value = [&]() + { + const DataType value = *it; + ++it; + + if(it == values.end()) + { + it = values.begin(); + } + + return value; + }; + + fill_with_generator(tensor, get_next_value); +} + template void AssetsLibrary::fill(RawTensor &raw, D &&distribution, std::random_device::result_type seed_offset) const { -- cgit v1.2.1