aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-01-05 10:59:12 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:33 +0000
commit6db0ff5b4bb49f834c7caa532a7feab228df10f9 (patch)
tree36c32ab3e94a86752d6b73c4a3503b191431d586 /utils
parentfde97fb84943d0328c2c532d117e9b875149f27e (diff)
downloadComputeLibrary-6db0ff5b4bb49f834c7caa532a7feab228df10f9.tar.gz
COMPMID-771 Allow examples to be profiled
Change-Id: I180281e796e1670b9ad391d82d66ecde0119ef78 Note: this is for internal use only which is why I think the hackiness of RunExample.cpp is acceptable. Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115154 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/Utils.cpp43
-rw-r--r--utils/Utils.h48
2 files changed, 81 insertions, 10 deletions
diff --git a/utils/Utils.cpp b/utils/Utils.cpp
index f6aff6f92d..c2f5449a28 100644
--- a/utils/Utils.cpp
+++ b/utils/Utils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017, 2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -66,7 +66,8 @@ void discard_comments_and_spaces(std::ifstream &fs)
}
} // namespace
-int run_example(int argc, const char **argv, example &func)
+//FIXME: Delete once tests have been ported (COMPMID-782)
+int run_example(int argc, char **argv, example &func)
{
std::cout << "\n"
<< argv[0] << "\n\n";
@@ -100,6 +101,44 @@ int run_example(int argc, const char **argv, example &func)
return -1;
}
+#ifndef BENCHMARK_EXAMPLES
+int run_example(int argc, char **argv, Example &example)
+{
+ std::cout << "\n"
+ << argv[0] << "\n\n";
+
+ try
+ {
+ example.do_setup(argc, argv);
+ example.do_run();
+ example.do_teardown();
+
+ std::cout << "\nTest passed\n";
+ return 0;
+ }
+#ifdef ARM_COMPUTE_CL
+ catch(cl::Error &err)
+ {
+ std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+ std::cerr << std::endl
+ << "ERROR " << err.what() << "(" << err.err() << ")" << std::endl;
+ std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+ }
+#endif /* ARM_COMPUTE_CL */
+ catch(std::runtime_error &err)
+ {
+ std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+ std::cerr << std::endl
+ << "ERROR " << err.what() << " " << (errno ? strerror(errno) : "") << std::endl;
+ std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+ }
+
+ std::cout << "\nTest FAILED\n";
+
+ return -1;
+}
+#endif /* BENCHMARK_EXAMPLES */
+
void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b)
{
ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(tensor, Format::RGB888);
diff --git a/utils/Utils.h b/utils/Utils.h
index eb4e846e80..9b5d0c4aa9 100644
--- a/utils/Utils.h
+++ b/utils/Utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016, 2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -55,20 +55,52 @@ namespace arm_compute
{
namespace utils
{
+//FIXME: Delete once tests have been ported (COMPMID-782)
/** Signature of an example to run
*
* @param[in] argc Number of command line arguments
* @param[in] argv Command line arguments
*/
-using example = void(int argc, const char **argv);
+using example = void(int argc, char **argv);
+//FIXME: Delete once tests have been ported (COMPMID-782)
/** 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] func Pointer to the function containing the code to run
*/
-int run_example(int argc, const char **argv, example &func);
+int run_example(int argc, char **argv, example &func);
+
+/** Abstract Example class.
+ *
+ * All examples have to inherit from this class.
+ */
+class Example
+{
+public:
+ virtual void do_setup(int argc, char **argv) {};
+ virtual void do_run() {};
+ virtual void do_teardown() {};
+
+ /** Default destructor. */
+ virtual ~Example() = 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, Example &example);
+
+template <typename T>
+int run_example(int argc, char **argv)
+{
+ T example;
+ return run_example(argc, argv, example);
+}
/** Draw a RGB rectangular window for the detected object
*
@@ -258,7 +290,7 @@ public:
ARM_COMPUTE_ERROR_ON_MSG(max_val >= 256, "2 bytes per colour channel not supported in file %s", ppm_filename.c_str());
}
- catch(const std::ifstream::failure &e)
+ catch(std::runtime_error &e)
{
ARM_COMPUTE_ERROR("Accessing %s: %s", ppm_filename.c_str(), e.what());
}
@@ -545,7 +577,7 @@ public:
void fill_tensor(T &tensor)
{
ARM_COMPUTE_ERROR_ON(!is_open());
- ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(&tensor, arm_compute::DataType::F32);
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_NOT_IN(&tensor, arm_compute::DataType::F32);
try
{
// Map buffer if creating a CLTensor
@@ -566,19 +598,19 @@ public:
ARM_COMPUTE_ERROR_ON_MSG(_typestring != expect_typestr, "Typestrings mismatch");
// Validate tensor shape
- ARM_COMPUTE_ERROR_ON_MSG(_shape.size() != tensor.shape().num_dimensions(), "Tensor ranks mismatch");
+ ARM_COMPUTE_ERROR_ON_MSG(_shape.size() != tensor.info()->tensor_shape().num_dimensions(), "Tensor ranks mismatch");
if(_fortran_order)
{
for(size_t i = 0; i < _shape.size(); ++i)
{
- ARM_COMPUTE_ERROR_ON_MSG(tensor.shape()[i] != _shape[i], "Tensor dimensions mismatch");
+ ARM_COMPUTE_ERROR_ON_MSG(tensor.info()->tensor_shape()[i] != _shape[i], "Tensor dimensions mismatch");
}
}
else
{
for(size_t i = 0; i < _shape.size(); ++i)
{
- ARM_COMPUTE_ERROR_ON_MSG(tensor.shape()[i] != _shape[_shape.size() - i - 1], "Tensor dimensions mismatch");
+ ARM_COMPUTE_ERROR_ON_MSG(tensor.info()->tensor_shape()[i] != _shape[_shape.size() - i - 1], "Tensor dimensions mismatch");
}
}