From 5cca9cb852fd6926f90263f343aba39a1a54972c Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Tue, 12 Feb 2019 11:42:33 +0000 Subject: Remove tests/benchmark_examples, tests/validate_examples and corresponding build options Change-Id: I9676dcd3947fc30d182354e3776c17f5f10e1a21 Signed-off-by: Isabella Gottardi --- tests/SConscript | 89 +------ tests/benchmark_examples/RunExample.cpp | 183 --------------- tests/validate_examples/RunExample.cpp | 207 ---------------- tests/validate_examples/ValidateExample.h | 85 ------- tests/validate_examples/cl_gemm.cpp | 378 ------------------------------ 5 files changed, 1 insertion(+), 941 deletions(-) delete mode 100644 tests/benchmark_examples/RunExample.cpp delete mode 100644 tests/validate_examples/RunExample.cpp delete mode 100644 tests/validate_examples/ValidateExample.h delete mode 100644 tests/validate_examples/cl_gemm.cpp diff --git a/tests/SConscript b/tests/SConscript index 41731c2343..94b432c0ff 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -30,9 +30,6 @@ SConscript('./framework/SConscript', duplicate=0) # vars is imported from arm_compute: variables = [ - #FIXME: Remove before release! - BoolVariable("benchmark_examples", "Build benchmark examples programs", True), - BoolVariable("validate_examples", "Build benchmark examples programs", True), #FIXME Switch the following two options to False before releasing BoolVariable("validation_tests", "Build validation test programs", True), BoolVariable("benchmark_tests", "Build benchmark test programs", True), @@ -78,16 +75,10 @@ else: if env['internal_only']: test_env.Append(CPPDEFINES=['INTERNAL_ONLY']) -test_env.Append(CPPPATH = ["#3rdparty/include"]) -test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])]) - common_files = Glob('*.cpp') common_objects = [test_env.StaticObject(f) for f in common_files] files_benchmark = Glob('benchmark/*.cpp') -#FIXME Delete before release -if env['internal_only']: - files_benchmark += Glob('../3rdparty/tests/benchmark/*.cpp') # Add unit tests files_validation = Glob('validation/UNIT/*/*.cpp') @@ -104,9 +95,6 @@ if env['opencl']: files_benchmark += Glob('benchmark/CL/*/' + filter_pattern) files_benchmark += Glob('benchmark/CL/' + filter_pattern) - #FIXME Delete before release - if env['internal_only']: - files_benchmark += Glob('../3rdparty/tests/benchmark/CL/' + filter_pattern) files_validation += Glob('validation/CL/*/' + filter_pattern) files_validation += Glob('validation/CL/' + filter_pattern) @@ -115,9 +103,6 @@ if env['neon']: filter_pattern = test_env['test_filter'] files_benchmark += Glob('benchmark/NEON/*/' + filter_pattern) files_benchmark += Glob('benchmark/NEON/' + filter_pattern) - #FIXME Delete before release - if env['internal_only']: - files_benchmark += Glob('../3rdparty/tests/benchmark/NEON/' + filter_pattern) files_validation += Glob('validation/NEON/*/' + filter_pattern) files_validation += Glob('validation/NEON/' + filter_pattern) @@ -156,76 +141,4 @@ if test_env['validation_tests']: Depends(arm_compute_validation, arm_compute_lib) Default(arm_compute_validation) - Export('arm_compute_validation') - - #FIXME: Remove before release! - if test_env['validate_examples']: - files_validate_examples = [ test_env.Object('validate_examples/RunExample.cpp') ] + [ x for x in common_objects if not "main.o" in str(x)] - arm_compute_validate_examples = [] - if test_env['neon']: - for file in Glob("validate_examples/neon_*.cpp"): - example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) - arm_compute_validate_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, LIBS = [ arm_compute_validation_framework]) ] - if test_env['opencl']: - cl_examples = [] - files = Glob("validate_examples/cl_*.cpp") - if test_env['neon']: - files += Glob("validate_examples/neoncl_*.cpp") - for file in files: - example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) - cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_validate_examples, LIBS = test_env["LIBS"] + [ arm_compute_validation_framework ]) ] - arm_compute_validate_examples += cl_examples - if test_env['opencl'] and test_env['neon']: - graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") - for file in Glob("validate_examples/graph_*.cpp"): - example = "validate_" + os.path.basename(os.path.splitext(str(file))[0]) - if env['os'] in ['android', 'bare_metal'] or env['standalone']: - prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + [ arm_compute_validation_framework ], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',arm_compute_lib,'-Wl,--no-whole-archive']) - arm_compute_validate_examples += [ prog ] - else: - #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies - prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils]+ files_validate_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph", arm_compute_validation_framework], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) - arm_compute_validate_examples += [ prog ] - arm_compute_validate_examples = install_bin(arm_compute_validate_examples) - Depends(arm_compute_validate_examples, arm_compute_validation_framework) - Depends(arm_compute_validate_examples, arm_compute_test_framework) - Depends(arm_compute_validate_examples, arm_compute_lib) - Default(arm_compute_validate_examples) - Export('arm_compute_validate_examples') - -#FIXME: Remove before release! -if test_env['benchmark_examples']: - files_benchmark_examples = test_env.Object('benchmark_examples/RunExample.cpp') - graph_utils = test_env.Object(source="../utils/GraphUtils.cpp", target="GraphUtils") - graph_params = test_env.Object(source="../utils/CommonGraphOptions.cpp", target="CommonGraphOptions") - arm_compute_benchmark_examples = [] - for examples_folder in [ "../examples", "../3rdparty/examples"]: - if test_env['neon']: - for file in Glob("%s/neon_*.cpp" % examples_folder): - example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) - arm_compute_benchmark_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples) ] - if test_env['opencl']: - cl_examples = [] - files = Glob("%s/cl_*.cpp" % examples_folder) - if test_env['neon']: - files += Glob("%s/neoncl_*.cpp" % examples_folder) - for file in files: - example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) - cl_examples += [ test_env.Program(example, [ test_env.Object(source=file, target=example) ] + files_benchmark_examples, LIBS = test_env["LIBS"]) ] - arm_compute_benchmark_examples += cl_examples - - # Graph examples - for file in Glob("%s/graph_*.cpp" % examples_folder ): - example = "benchmark_" + os.path.basename(os.path.splitext(str(file))[0]) - if env['os'] in ['android', 'bare_metal'] or env['standalone']: - prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils, graph_params]+ files_benchmark_examples, LIBS = test_env["LIBS"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--whole-archive',arm_compute_lib,'-Wl,--no-whole-archive']) - arm_compute_benchmark_examples += [ prog ] - else: - #-Wl,--allow-shlib-undefined: Ignore dependencies of dependencies - prog = test_env.Program(example, [ test_env.Object(source=file, target=example), graph_utils, graph_params]+ files_benchmark_examples, LIBS = test_env["LIBS"] + ["arm_compute_graph"], LINKFLAGS=test_env["LINKFLAGS"]+['-Wl,--allow-shlib-undefined'] ) - arm_compute_benchmark_examples += [ prog ] - arm_compute_benchmark_examples = install_bin(arm_compute_benchmark_examples) - Depends(arm_compute_benchmark_examples, arm_compute_test_framework) - Depends(arm_compute_benchmark_examples, arm_compute_lib) - Default(arm_compute_benchmark_examples) - Export('arm_compute_benchmark_examples') + Export('arm_compute_validation') \ No newline at end of file diff --git a/tests/benchmark_examples/RunExample.cpp b/tests/benchmark_examples/RunExample.cpp deleted file mode 100644 index a7a8be01cc..0000000000 --- a/tests/benchmark_examples/RunExample.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2018-2019 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 "utils/Utils.h" -//FIXME / INTERNAL_ONLY: This file should not be released! - -#define BENCHMARK_EXAMPLES -#include "utils/Utils.cpp" - -#include "arm_compute/runtime/Scheduler.h" -#include "tests/framework/Framework.h" -#include "tests/framework/Macros.h" -#include "tests/framework/command_line/CommonOptions.h" -#include "tests/framework/instruments/Instruments.h" -#include "utils/command_line/CommandLineParser.h" - -#ifdef ARM_COMPUTE_CL -#include "arm_compute/runtime/CL/CLHelpers.h" -#include "arm_compute/runtime/CL/CLScheduler.h" -#endif /* ARM_COMPUTE_CL */ -#ifdef ARM_COMPUTE_GC -#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" -#endif /* ARM_COMPUTE_GC */ - -#include - -using namespace arm_compute; -using namespace arm_compute::test; - -namespace -{ -std::string command_line(int argc, char **argv) -{ - std::stringstream ss; - for(int i = 0; i < argc; i++) - { - ss << argv[i] << " "; - } - return ss.str(); -} -} // namespace -namespace arm_compute -{ -namespace utils -{ -static std::unique_ptr g_example = nullptr; -static std::vector g_example_argv = {}; -class ExampleTest : public arm_compute::test::framework::TestCase -{ -public: - ExampleTest() = default; - void do_setup() override - { - ARM_COMPUTE_ERROR_ON_NULLPTR(g_example.get()); - _is_setup = g_example->do_setup(g_example_argv.size(), &g_example_argv[0]); - } - void do_run() override - { - if(_is_setup) - { - g_example->do_run(); - } - } - void do_teardown() override - { - if(_is_setup) - { - g_example->do_teardown(); - } - g_example = nullptr; - } - -private: - bool _is_setup{ false }; -}; - -int run_example(int argc, char **argv, std::unique_ptr example) -{ - utils::CommandLineParser parser; - framework::CommonOptions options(parser); - auto example_args = parser.add_option>("example_args"); - example_args->set_help("Arguments to pass to the example separated by commas (e.g: arg0,arg1,arg2)"); - framework::Framework &framework = framework::Framework::get(); - - parser.parse(argc, argv); - - if(options.help->is_set() && options.help->value()) - { - parser.print_help(argv[0]); - return 0; - } - - std::vector> printers = options.create_printers(); - g_example = std::move(example); - g_example_argv.clear(); - g_example_argv.emplace_back(argv[0]); - for(auto &arg : example_args->value()) - { - g_example_argv.emplace_back(const_cast(arg.c_str())); // NOLINT - } - - if(options.log_level->value() > framework::LogLevel::NONE) - { - for(auto &p : printers) - { - p->print_global_header(); - } - } - -#ifdef ARM_COMPUTE_CL - if(opencl_is_available()) - { - auto ctx_dev_err = create_opencl_context_and_device(); - ARM_COMPUTE_ERROR_ON_MSG(std::get<2>(ctx_dev_err) != CL_SUCCESS, "Failed to create OpenCL context"); - CLScheduler::get() - .default_init_with_context(std::get<1>(ctx_dev_err), std::get<0>(ctx_dev_err)); - } -#endif /* ARM_COMPUTE_CL */ - - if(options.log_level->value() >= framework::LogLevel::CONFIG) - { - for(auto &p : printers) - { - p->print_entry("Version", build_information()); - p->print_entry("CommandLine", command_line(argc, argv)); -#ifdef ARM_COMPUTE_CL - if(opencl_is_available()) - { - p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version()); - } - else - { - p->print_entry("CL_DEVICE_VERSION", "Unavailable"); - } -#endif /* ARM_COMPUTE_CL */ - p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value())); - } - } - - framework.init(options.instruments->value(), options.iterations->value(), framework::DatasetMode::ALL, "", "", options.log_level->value()); - for(auto &p : printers) - { - framework.add_printer(p.get()); - } - framework.set_throw_errors(options.throw_errors->value()); - arm_compute::test::framework::detail::TestSuiteRegistrar suite{ "Examples" }; - framework.add_test_case(basename(argv[0]), framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE); - - //func(argc, argv); - bool success = framework.run(); - if(options.log_level->value() > framework::LogLevel::NONE) - { - for(auto &p : printers) - { - p->print_global_footer(); - } - } - - return (success ? 0 : 1); -} - -} // namespace utils -} // namespace arm_compute diff --git a/tests/validate_examples/RunExample.cpp b/tests/validate_examples/RunExample.cpp deleted file mode 100644 index 41ed85138e..0000000000 --- a/tests/validate_examples/RunExample.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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. - */ -#include "utils/Utils.h" -//FIXME / INTERNAL_ONLY: This file should not be released! - -#define BENCHMARK_EXAMPLES -#include "utils/Utils.cpp" - -#include "ValidateExample.h" -#include "arm_compute/runtime/Scheduler.h" -#include "tests/AssetsLibrary.h" -#include "tests/Globals.h" -#include "tests/framework/Framework.h" -#include "tests/framework/Macros.h" -#include "tests/framework/command_line/CommonOptions.h" -#include "tests/framework/instruments/Instruments.h" -#include "utils/command_line/CommandLineParser.h" - -#ifdef ARM_COMPUTE_CL -#include "arm_compute/runtime/CL/CLScheduler.h" -#endif /* ARM_COMPUTE_CL */ -#ifdef ARM_COMPUTE_GC -#include "arm_compute/runtime/GLES_COMPUTE/GCScheduler.h" -#endif /* ARM_COMPUTE_GC */ - -#include - -using namespace arm_compute; -using namespace arm_compute::test; - -namespace arm_compute -{ -namespace test -{ -std::unique_ptr library; -} // namespace test -namespace utils -{ -static std::unique_ptr g_example = nullptr; -static std::vector g_example_argv = {}; - -namespace -{ -std::string command_line(int argc, char **argv) -{ - std::stringstream ss; - for(int i = 0; i < argc; i++) - { - ss << argv[i] << " "; - } - return ss.str(); -} - -template -class ExampleTest : public arm_compute::test::framework::TestCase -{ -public: - ExampleTest() = default; - void do_setup() override - { - ARM_COMPUTE_ERROR_ON_NULLPTR(g_example.get()); - _is_setup = g_example->do_setup(g_example_argv.size(), &g_example_argv[0]); - } - void do_run() override - { - if(_is_setup) - { - g_example->do_run(); - } - } - void do_teardown() override - { - if(_is_setup) - { - if(validate) - { - g_example->do_validate(); - } - g_example->do_teardown(); - } - g_example = nullptr; - } - -private: - bool _is_setup{ false }; -}; - -} // namespace -int run_example(int argc, char **argv, std::unique_ptr example) -{ - utils::CommandLineParser parser; - framework::CommonOptions options(parser); - auto example_args = parser.add_option>("example_args"); - example_args->set_help("Arguments to pass to the example separated by commas (e.g: arg0,arg1,arg2)"); - auto seed = parser.add_option>("seed", std::random_device()()); - seed->set_help("Global seed for random number generation"); - auto validate = parser.add_option>("validate", 1); - validate->set_help("Enable / disable output validation (0/1)"); - - framework::Framework &framework = framework::Framework::get(); - - parser.parse(argc, argv); - - if(options.help->is_set() && options.help->value()) - { - parser.print_help(argv[0]); - return 0; - } - - std::vector> printers = options.create_printers(); - g_example = std::move(example); - g_example_argv.clear(); - g_example_argv.emplace_back(argv[0]); - for(auto &arg : example_args->value()) - { - g_example_argv.emplace_back(const_cast(arg.c_str())); // NOLINT - } - - library = support::cpp14::make_unique("." /* Only using random values */, seed->value()); - - if(options.log_level->value() > framework::LogLevel::NONE) - { - for(auto &p : printers) - { - p->print_global_header(); - } - } - - if(options.log_level->value() >= framework::LogLevel::CONFIG) - { - for(auto &p : printers) - { - p->print_entry("Version", build_information()); - p->print_entry("CommandLine", command_line(argc, argv)); - p->print_entry("Seed", support::cpp11::to_string(seed->value())); -#ifdef ARM_COMPUTE_CL - if(opencl_is_available()) - { - if(!CLScheduler::get().is_initialised()) - { - CLScheduler::get().default_init(); - } - p->print_entry("CL_DEVICE_VERSION", CLKernelLibrary::get().get_device_version()); - } - else - { - p->print_entry("CL_DEVICE_VERSION", "Unavailable"); - } -#endif /* ARM_COMPUTE_CL */ - p->print_entry("Iterations", support::cpp11::to_string(options.iterations->value())); - g_example->print_parameters(*p); - } - } - - framework.init(options.instruments->value(), options.iterations->value(), framework::DatasetMode::ALL, "", "", options.log_level->value()); - for(auto &p : printers) - { - framework.add_printer(p.get()); - } - - framework.set_throw_errors(options.throw_errors->value()); - arm_compute::test::framework::detail::TestSuiteRegistrar suite{ "Examples" }; - if(validate->value() != 0) - { - framework.add_test_case>(basename(argv[0]), framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE); - } - else - { - framework.add_test_case>(basename(argv[0]), framework::DatasetMode::ALL, arm_compute::test::framework::TestCaseFactory::Status::ACTIVE); - } - - //func(argc, argv); - bool success = framework.run(); - if(options.log_level->value() > framework::LogLevel::NONE) - { - for(auto &p : printers) - { - p->print_global_footer(); - } - } - - return (success ? 0 : 1); -} - -} // namespace utils -} // namespace arm_compute diff --git a/tests/validate_examples/ValidateExample.h b/tests/validate_examples/ValidateExample.h deleted file mode 100644 index 2721508336..0000000000 --- a/tests/validate_examples/ValidateExample.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2016-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 __VALIDATE_EXAMPLE_H__ -#define __VALIDATE_EXAMPLE_H__ - -#include "utils/Utils.h" -namespace arm_compute -{ -namespace test -{ -namespace framework -{ -class Printer; -} // namespace framework -} // namespace test -namespace utils -{ -/** Abstract ValidateExample class. - * - * All examples with a validation stage have to inherit from this class. - */ -class ValidateExample -{ -public: - /** Setup the example. - * - * @param[in] argc Argument count. - * @param[in] argv Argument values. - */ - virtual bool do_setup(int argc, char **argv) - { - return true; - }; - /** Run the example. */ - virtual void do_run() {}; - /** Run reference implementation and validate against the target output - */ - virtual void do_validate() - { - } - /** Teardown the example. */ - virtual void do_teardown() {}; - /** Print the example parameters - * - * @param[in,out] printer Printer to use to print the parameters - */ - virtual void print_parameters(test::framework::Printer &printer) - { - } - - /** Default destructor */ - virtual ~ValidateExample() = default; -}; -/** Run an example and handle the potential exceptions it throws - * - * @param[in] argc Number of command line arguments - * @param[in] argv Command line arguments - * @param[in] example Example to run - */ -int run_example(int argc, char **argv, std::unique_ptr example); - -} // namespace utils -} // namespace arm_compute -#endif /* __VALIDATE_EXAMPLE_H__ */ diff --git a/tests/validate_examples/cl_gemm.cpp b/tests/validate_examples/cl_gemm.cpp deleted file mode 100644 index 8b3a103db7..0000000000 --- a/tests/validate_examples/cl_gemm.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - * 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_CL /* Needed by Utils.cpp to handle OpenCL exceptions properly */ -#error "This example needs to be built with -DARM_COMPUTE_CL" -#endif /* ARM_COMPUTE_CL */ - -#include "arm_compute/core/Types.h" -#include "arm_compute/core/utils/quantization/AsymmHelpers.h" -#include "arm_compute/runtime/CL/CLFunctions.h" -#include "arm_compute/runtime/CL/CLScheduler.h" - -#include "tests/AssetsLibrary.h" -#include "tests/CL/CLAccessor.h" -#include "tests/Globals.h" -#include "tests/IAccessor.h" -#include "tests/SimpleTensor.h" -#include "tests/validation/Validation.h" -#include "tests/validation/reference/GEMM.h" -#include "tests/validation/reference/GEMMLowp.h" - -#include "ValidateExample.h" - -#include "utils/Utils.h" - -#include - -using namespace arm_compute; -using namespace utils; -using namespace arm_compute::test; -using namespace arm_compute::test::validation; - -constexpr float abs_tolerance_f32(0.0001f); /**< F32 Absolute tolerance value for comparing reference's output against implementation's output for - * floating point data types in case using relative tolerance fails because of small values */ -RelativeTolerance tolerance_f32(0.001f); /**< F32 Tolerance value for comparing reference's output against implementation's output for floating point data types */ -RelativeTolerance tolerance_f16(half(0.2)); /**< F16 Tolerance value for comparing reference's output against implementation's output for floating point data types */ -constexpr float tolerance_num_f16 = 0.02f; /**< F16 Tolerance number */ - -class CLGEMMValidateExample : public ValidateExample -{ -public: - bool do_setup(int argc, char **argv) override - { - //TODO(antbar01): Update to use command line interface ? - CLScheduler::get().default_init(); - if(argc == 2) - { - size_t dt = strtol(argv[1], nullptr, 10); - switch(dt) - { - case 1: - { - data_type = DataType::F16; - std::cout << "Usage: " << argv[0] << "1 M N K [alpha = 1.0f] [beta = 0.0f]\n"; - std::cout << "Using default values: Datatype=FP16 M=7, N=3, K=5, alpha=1.0f and beta=0.0f\n"; - break; - } - case 2: - { - data_type = DataType::QASYMM8; - std::cout << "Usage: " << argv[0] << "2 M N K [scale_src0 = 0.1f] [offset_scr0 = f] [scale_scr1 = 0.1f] [offset_scr1 = 10] [scale_dst = 0.1f] [offset_dst = 10] [bias = 1]\n"; - std::cout << - "Using default values: Datatype=QASYMM8 M=7, N=3, K=5, scale_src0 =(1.0f/255), offset_src0 = 10, scale_src1 =(1.0f/255), offset_src1 = 10, scale_dst =(1.0f/255), offset_dst = 10, bias=1\n\n"; - break; - } - case 0: - default: - { - data_type = DataType::F32; - std::cout << "Usage: " << argv[0] << "0 M N K [alpha = 1.0f] [beta = 0.0f]\n"; - std::cout << "Using default values: Datatype=FP32 M=7, N=3, K=5, alpha=1.0f and beta=0.0f\n"; - } - } - } - else if(argc < 5) - { - // Print help - std::cout << "Usage with datatype = FP32 : " << argv[0] << "0 M N K [alpha = 1.0f] [beta = 0.0f]\n"; - std::cout << " datatype = FP16 : " << argv[0] << "1 M N K [alpha = 1.0f] [beta = 0.0f]\n"; - std::cout << " datatype = QASYMM8 : " << argv[0] << "2 M N K [scale_src0 = 0.1f] [offset_scr0 = f] [scale_scr1 = 0.1f] [offset_scr1 = 10] [scale_dst = 0.1f] [offset_dst = 10] [bias = 1]\n"; - std::cout << "Too few or no arguments provided.\n"; - std::cout << "Using default values: Datatype=FP32 M=7, N=3, K=5, alpha=1.0f and beta=0.0f\n"; - } - else - { - size_t dt = strtol(argv[1], nullptr, 10); - switch(dt) - { - case 1: - { - data_type = DataType::F16; - break; - } - case 2: - { - data_type = DataType::QASYMM8; - break; - } - case 0: - default: - data_type = DataType::F32; - } - M = strtol(argv[2], nullptr, 10); - N = strtol(argv[3], nullptr, 10); - K = strtol(argv[4], nullptr, 10); - } - - switch(data_type) - { - case DataType::F16: - case DataType::F32: - { - if(argc > 5) - { - alpha = strtof(argv[5], nullptr); - if(argc > 6) - { - beta = strtof(argv[6], nullptr); - } - } - break; - } - case DataType::QASYMM8: - { - if(argc > 5) - { - scale_src0 = strtof(argv[5], nullptr); - if(argc > 6) - { - offset_src0 = strtol(argv[6], nullptr, 10); - if(argc > 7) - { - scale_src1 = strtof(argv[7], nullptr); - if(argc > 8) - { - offset_src1 = strtol(argv[8], nullptr, 10); - if(argc > 9) - { - scale_dst = strtof(argv[9], nullptr); - if(argc > 10) - { - offset_dst = strtol(argv[10], nullptr, 10); - if(argc > 11) - { - add_bias = (strtol(argv[11], nullptr, 10) == 1); - } - } - } - } - } - } - } - float multiplier = scale_src0 * scale_src1 / scale_dst; - quantization::calculate_quantized_multiplier_less_than_one(multiplier, &dst_multiplier, &dst_shift); - break; - } - default: - break; - } - - src0.allocator()->init(TensorInfo(TensorShape(K, M), 1, data_type)); - src1.allocator()->init(TensorInfo(TensorShape(N, K), 1, data_type)); - src2.allocator()->init(TensorInfo(TensorShape(N, M), 1, data_type)); - init_sgemm_output(dst, src0, src1, data_type); - - // Configure function - if(data_type == DataType::QASYMM8) - { - src0.info()->set_quantization_info(QuantizationInfo(scale_src0, offset_src0)); - src1.info()->set_quantization_info(QuantizationInfo(scale_src1, offset_src1)); - dst.info()->set_quantization_info(QuantizationInfo(scale_dst, offset_dst)); - biases.allocator()->init(TensorInfo(TensorShape(N), 1, DataType::S32)); - init_sgemm_output(tmp_dst, src0, src1, DataType::S32); - - // Configure GEMMlowp matrix multiply function - mm_gemmlowp.configure(&src0, &src1, nullptr, &tmp_dst); - - // Configure GEMMlowp output stage - mm_gemmlowp_output_stage.configure(&tmp_dst, add_bias ? &biases : nullptr, &dst, dst_multiplier, dst_shift, offset_dst); - tmp_dst.allocator()->allocate(); - biases.allocator()->allocate(); - fill(CLAccessor(biases), 3); - } - else - { - // Configure matrix multiply function - mm_gemm.configure(&src0, &src1, &src2, &dst, alpha, beta); - } - - // Allocate all the tensors - src0.allocator()->allocate(); - src1.allocator()->allocate(); - dst.allocator()->allocate(); - src2.allocator()->allocate(); - - fill(CLAccessor(src0), 0); - fill(CLAccessor(src1), 1); - fill(CLAccessor(src2), 2); - - return true; - } - - void print_parameters(framework::Printer &printer) override - { - printer.print_entry("Datatype", string_from_data_type(data_type)); - printer.print_entry("M", support::cpp11::to_string(M)); - printer.print_entry("N", support::cpp11::to_string(N)); - printer.print_entry("K", support::cpp11::to_string(K)); - if(data_type == DataType::QASYMM8) - { - printer.print_entry("Scale_Src0", support::cpp11::to_string(scale_src0)); - printer.print_entry("Offset_Src0", support::cpp11::to_string(offset_src0)); - printer.print_entry("Scale_Scr1", support::cpp11::to_string(scale_src1)); - printer.print_entry("Offset_Src1", support::cpp11::to_string(offset_src1)); - printer.print_entry("Scale_Dst", support::cpp11::to_string(scale_dst)); - printer.print_entry("Offset_Dst", support::cpp11::to_string(offset_dst)); - printer.print_entry("Bias", support::cpp11::to_string(add_bias)); - } - else - { - printer.print_entry("Alpha", support::cpp11::to_string(alpha)); - printer.print_entry("Beta", support::cpp11::to_string(beta)); - } - } - - void do_validate() override - { - switch(data_type) - { - case DataType::F16: - { - SimpleTensor ref_src0 = { TensorShape(K, M), data_type, 1 }; - SimpleTensor ref_src1 = { TensorShape(N, K), data_type, 1 }; - SimpleTensor ref_src2 = { TensorShape(N, M), data_type, 1 }; - - fill(ref_src0, 0); - fill(ref_src1, 1); - fill(ref_src2, 2); - - SimpleTensor ref_dst = reference::gemm(ref_src0, ref_src1, ref_src2, alpha, beta); - validate(CLAccessor(dst), ref_dst, tolerance_f16, tolerance_num_f16); - break; - } - case DataType::F32: - { - SimpleTensor ref_src0 = { TensorShape(K, M), data_type, 1 }; - SimpleTensor ref_src1 = { TensorShape(N, K), data_type, 1 }; - SimpleTensor ref_src2 = { TensorShape(N, M), data_type, 1 }; - - fill(ref_src0, 0); - fill(ref_src1, 1); - fill(ref_src2, 2); - - SimpleTensor ref_dst = reference::gemm(ref_src0, ref_src1, ref_src2, alpha, beta); - validate(CLAccessor(dst), ref_dst, tolerance_f32, 0.f, abs_tolerance_f32); - break; - } - case DataType::QASYMM8: - { - SimpleTensor ref_src0{ TensorShape(K, M), data_type, 1 }; - SimpleTensor ref_src1{ TensorShape(N, K), data_type, 1 }; - SimpleTensor ref_dst; - - // Fill reference - fill(ref_src0, 0); - fill(ref_src1, 1); - - SimpleTensor ref_tmp_dst = reference::gemmlowp_matrix_multiply_core(ref_src0, ref_src1, TensorShape(N, M), offset_src0, offset_src1); - - if(add_bias) - { - SimpleTensor biases{ TensorShape(N), DataType::S32, 1 }; - // Fill bias - fill(biases, 3); - ref_dst = reference::gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(ref_tmp_dst, biases, dst_multiplier, dst_shift, offset_dst); - } - else - { - ref_dst = reference::gemmlowp_quantize_down_int32_to_uint8_scale_by_fixedpoint(ref_tmp_dst, dst_multiplier, dst_shift, offset_dst); - } - validate(CLAccessor(dst), ref_dst); - break; - } - default: - break; - } - } - void do_run() override - { - // Execute the function - if(data_type == DataType::QASYMM8) - { - // Run gemmlowp - mm_gemmlowp.run(); - // Run output stage - mm_gemmlowp_output_stage.run(); - } - else - { - // Run gemm - mm_gemm.run(); - } - - // Make sure all the OpenCL jobs are done executing: - CLScheduler::get().sync(); - } - -private: - template - void fill(U &&tensor, int i) - { - switch(tensor.data_type()) - { - case DataType::F16: - case DataType::F32: - { - std::uniform_real_distribution<> distribution(-1.0f, 1.0f); - library->fill(tensor, distribution, i); - break; - } - case DataType::S32: - case DataType::QASYMM8: - { - std::uniform_int_distribution<> distribution(-6000, 6000); - library->fill(tensor, distribution, i); - break; - } - default: - library->fill_tensor_uniform(tensor, i); - } - } - - CLTensor src0{}, src1{}, src2{}, dst{}; - CLTensor tmp_dst{}, biases{}; - - CLGEMM mm_gemm{}; - CLGEMMLowpMatrixMultiplyCore mm_gemmlowp{}; - CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint mm_gemmlowp_output_stage{}; - - size_t M{ 7 }, N{ 3 }, K{ 5 }; - DataType data_type{ DataType::F32 }; - float alpha{ 1.0 }, beta{ 0.0 }; - int offset_src0{ 10 }, offset_src1{ 10 }, offset_dst{ 10 }; - float scale_src0{ 1.0f / 255 }, scale_src1{ 1.0f / 255 }, scale_dst{ 1.0f / 255 }; - int32_t dst_multiplier{ 0 }, dst_shift{ 0 }; - bool add_bias{ true }; -}; - -/** Main program for gemm test - * - * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] datatype, [optional] M, [optional] N, [optional] K, [optional] scale_src0, [optional] offset_src0, [optional] scale_src1, [optional] offset_src1, [optional] scale_dst, [optional] offset_dst, [optional] bias, [optional] alpha, [optional] beta ) - * - */ -int main(int argc, char **argv) -{ - return utils::run_example(argc, argv); -} -- cgit v1.2.1