From 37831168869ff0b9a97ea0e27edab9e73d0d1a19 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 20 Aug 2018 15:41:10 +0100 Subject: COMPMID-1474: Automatically generate DragonBench benchmarks Change-Id: I428a11ed2242a8fa992a2cebb4168a5e13e2f1e3 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/144877 Reviewed-by: Anthony Barbier Tested-by: Jenkins --- tests/benchmark/CL/DragonBench.cpp | 83 ++++++++++++++++++ tests/benchmark/DragonBenchConfigs.cpp | 43 ++++++++++ tests/benchmark/DragonBenchConfigs.h | 46 ++++++++++ tests/benchmark/NEON/DragonBench.cpp | 82 ++++++++++++++++++ tests/benchmark/fixtures/DragonBenchFixture.h | 118 ++++++++++++++++++++++++++ 5 files changed, 372 insertions(+) create mode 100644 tests/benchmark/CL/DragonBench.cpp create mode 100644 tests/benchmark/DragonBenchConfigs.cpp create mode 100644 tests/benchmark/DragonBenchConfigs.h create mode 100644 tests/benchmark/NEON/DragonBench.cpp create mode 100644 tests/benchmark/fixtures/DragonBenchFixture.h (limited to 'tests/benchmark') diff --git a/tests/benchmark/CL/DragonBench.cpp b/tests/benchmark/CL/DragonBench.cpp new file mode 100644 index 0000000000..6e047a5fa1 --- /dev/null +++ b/tests/benchmark/CL/DragonBench.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 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. + */ +#ifdef INTERNAL_ONLY + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/CL/CLTensor.h" +#include "arm_compute/runtime/CL/CLTensorAllocator.h" +#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h" + +#include "tests/CL/CLAccessor.h" +#include "tests/benchmark/fixtures/DragonBenchFixture.h" +#include "tests/datasets/DragonBenchDataset.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +#include "tests/benchmark/DragonBenchConfigs.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +namespace +{ +// Common DragonBench parameters +auto CommonParams = combine(combine(framework::dataset::make("DataType", { DataType::F16, DataType::F32 }), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), + framework::dataset::make("HasBias", { true, false })); +} // namespace + +using CLDragonBenchConv2DFixture = DragonBenchConv2DFixture; + +TEST_SUITE(CL) +TEST_SUITE(DragonBench) +TEST_SUITE(Conv2D) + +REGISTER_FIXTURE_DATA_TEST_CASE(SilverWing, + CLDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(silverwing_cfgs), CommonParams)); + +REGISTER_FIXTURE_DATA_TEST_CASE(SunFyre, + CLDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(sunfyre_cfgs), CommonParams)); + +REGISTER_FIXTURE_DATA_TEST_CASE(Syrax, + CLDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(syrax_cfgs), CommonParams)); + +TEST_SUITE_END() +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace benchmark +} // namespace test +} // namespace arm_compute + +#endif // INTERNAL_ONLY diff --git a/tests/benchmark/DragonBenchConfigs.cpp b/tests/benchmark/DragonBenchConfigs.cpp new file mode 100644 index 0000000000..88239f2744 --- /dev/null +++ b/tests/benchmark/DragonBenchConfigs.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 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. + */ +#ifdef INTERNAL_ONLY + +#include +#include + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +#include "dragonbench/silverwing/conv2d.hpp" + +#include "dragonbench/silverwing/silverwing_configs.hpp" +#include "dragonbench/sunfyre/sunfyre_configs.hpp" +#include "dragonbench/syrax/syrax_configs.hpp" +} // namespace benchmark +} // namespace test +} // namespace arm_compute +#endif // INTERNAL_ONLY \ No newline at end of file diff --git a/tests/benchmark/DragonBenchConfigs.h b/tests/benchmark/DragonBenchConfigs.h new file mode 100644 index 0000000000..9ebb732c08 --- /dev/null +++ b/tests/benchmark/DragonBenchConfigs.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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. + */ +//FIXME / INTERNAL_ONLY: This file should not be released! +#ifndef __ARM_COMPUTE_DRAGONBENCH_CONFIGS_H__ +#define __ARM_COMPUTE_DRAGONBENCH_CONFIGS_H__ + +#include +#include + +#include "dragonbench/silverwing/conv2d.hpp" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +// Conv 2D benchmarks +extern conv2d_configs silverwing_cfgs; +extern conv2d_configs sunfyre_cfgs; +extern conv2d_configs syrax_cfgs; +} // namespace benchmark +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_DRAGONBENCH_CONFIGS_H__ */ diff --git a/tests/benchmark/NEON/DragonBench.cpp b/tests/benchmark/NEON/DragonBench.cpp new file mode 100644 index 0000000000..a1d826d343 --- /dev/null +++ b/tests/benchmark/NEON/DragonBench.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (c) 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. + */ +#ifdef INTERNAL_ONLY + +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" +#include "arm_compute/runtime/Tensor.h" +#include "arm_compute/runtime/TensorAllocator.h" + +#include "tests/NEON/Accessor.h" +#include "tests/benchmark/fixtures/DragonBenchFixture.h" +#include "tests/datasets/DragonBenchDataset.h" +#include "tests/framework/Macros.h" +#include "tests/framework/datasets/Datasets.h" +#include "utils/TypePrinter.h" + +#include "tests/benchmark/DragonBenchConfigs.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +namespace +{ +// Common DragonBench parameters +auto CommonParams = combine(combine(framework::dataset::make("DataType", { DataType::F32 }), + framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })), + framework::dataset::make("HasBias", { true, false })); +} // namespace + +using NEDragonBenchConv2DFixture = DragonBenchConv2DFixture; + +TEST_SUITE(NEON) +TEST_SUITE(DragonBench) +TEST_SUITE(Conv2D) + +REGISTER_FIXTURE_DATA_TEST_CASE(SilverWing, + NEDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(silverwing_cfgs), CommonParams)); + +REGISTER_FIXTURE_DATA_TEST_CASE(SunFyre, + NEDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(sunfyre_cfgs), CommonParams)); + +REGISTER_FIXTURE_DATA_TEST_CASE(Syrax, + NEDragonBenchConv2DFixture, + framework::DatasetMode::ALL, + combine(datasets::DragonBenchDataset(syrax_cfgs), CommonParams)); + +TEST_SUITE_END() +TEST_SUITE_END() +TEST_SUITE_END() +} // namespace benchmark +} // namespace test +} // namespace arm_compute +#endif // INTERNAL_ONLY diff --git a/tests/benchmark/fixtures/DragonBenchFixture.h b/tests/benchmark/fixtures/DragonBenchFixture.h new file mode 100644 index 0000000000..b9b3a180ac --- /dev/null +++ b/tests/benchmark/fixtures/DragonBenchFixture.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 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. + */ +//FIXME / INTERNAL_ONLY: This file should not be released! +#ifndef ARM_COMPUTE_TEST_DRAGONBENCH_FIXTURE +#define ARM_COMPUTE_TEST_DRAGONBENCH_FIXTURE + +#include "arm_compute/core/Error.h" +#include "arm_compute/core/TensorShape.h" +#include "arm_compute/core/Types.h" +#include "tests/Globals.h" +#include "tests/Utils.h" +#include "tests/framework/Fixture.h" + +namespace arm_compute +{ +namespace test +{ +namespace benchmark +{ +/** Fixture that can be used for NEON and CL */ +template +class DragonBenchConv2DFixture : public framework::Fixture +{ +public: + template + void setup(Conv2DConfig config, DataType data_type, DataLayout data_layout, bool has_bias) + { + // Set tensor shapes in NCHW layout + TensorShape src_shape(config.dim_in_w, config.dim_in_h, config.ch_in, config.ibatch); + TensorShape weights_shape(config.kern_w, config.kern_h, config.ch_in, config.ch_out); + TensorShape biases_shape(config.ch_out); + TensorShape dst_shape(config.dim_out_w, config.dim_out_h, config.ch_out, config.ibatch); + + // Set convolution layer info + PadStrideInfo info(config.stride_w, config.stride_h, 0, 0); + if(config.padding) + { + info = calculate_same_pad(src_shape, weights_shape, info); + } + + // Permute shapes in case of NHWC + if(data_layout == DataLayout::NHWC) + { + permute(src_shape, PermutationVector(2U, 0U, 1U)); + permute(weights_shape, PermutationVector(2U, 0U, 1U)); + permute(dst_shape, PermutationVector(2U, 0U, 1U)); + } + + // Determine bias data type + DataType bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; + + // Create tensors + src = create_tensor(src_shape, data_type, 1, QuantizationInfo(), data_layout); + weights = create_tensor(weights_shape, data_type, 1, QuantizationInfo(), data_layout); + biases = create_tensor(biases_shape, bias_data_type, 1, QuantizationInfo(), data_layout); + dst = create_tensor(dst_shape, data_type, 1, QuantizationInfo(), data_layout); + + // Create and configure function + conv_layer.configure(&src, &weights, has_bias ? &biases : nullptr, &dst, info); + + // Allocate tensors + src.allocator()->allocate(); + weights.allocator()->allocate(); + biases.allocator()->allocate(); + dst.allocator()->allocate(); + } + + void run() + { + conv_layer.run(); + } + + void sync() + { + sync_if_necessary(); + sync_tensor_if_necessary(dst); + } + + void teardown() + { + src.allocator()->free(); + weights.allocator()->free(); + biases.allocator()->free(); + dst.allocator()->free(); + } + +private: + TensorType src{}; + TensorType weights{}; + TensorType biases{}; + TensorType dst{}; + Function conv_layer{}; +}; +} // namespace benchmark +} // namespace test +} // namespace arm_compute +#endif /* ARM_COMPUTE_TEST_DRAGONBENCH_FIXTURE */ -- cgit v1.2.1