aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2017-10-30 14:13:50 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commit3faea25fe0bcb9f72bfe3da185085ed634d1b162 (patch)
treea53a50bf9e889b9d913dc47d5375a382aed57e58 /src/core
parentb5908c257d554009a00de3aaa95b3721000ed185 (diff)
downloadComputeLibrary-3faea25fe0bcb9f72bfe3da185085ed634d1b162.tar.gz
COMPMID-617: Adds validation to CLPoolingLayer
Change-Id: Ied405a9c0e9746598d03ac6a944ad87e9b6494eb Reviewed-on: http://mpd-gerrit.cambridge.arm.com/93680 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CL/CLHelpers.cpp5
-rw-r--r--src/core/CL/kernels/CLPoolingLayerKernel.cpp32
-rw-r--r--src/core/Error.cpp14
-rw-r--r--src/core/Utils.cpp1
-rw-r--r--src/core/Validate.cpp194
5 files changed, 122 insertions, 124 deletions
diff --git a/src/core/CL/CLHelpers.cpp b/src/core/CL/CLHelpers.cpp
index 901ac3f39a..54e3e525b4 100644
--- a/src/core/CL/CLHelpers.cpp
+++ b/src/core/CL/CLHelpers.cpp
@@ -24,6 +24,7 @@
#include "arm_compute/core/CL/CLHelpers.h"
#include "arm_compute/core/CL/CLTypes.h"
#include "arm_compute/core/Error.h"
+#include "arm_compute/core/Log.h"
#include "arm_compute/core/Types.h"
#include <map>
@@ -187,7 +188,7 @@ GPUTarget get_target_from_device(cl::Device &device)
if(!found_mali)
{
- ARM_COMPUTE_INFO("Can't find valid Mali GPU. Target is set to MIDGARD.");
+ ARM_COMPUTE_LOG_INFO_MSG_CORE("Can't find valid Mali GPU. Target is set to MIDGARD.");
return GPUTarget::MIDGARD;
}
@@ -201,7 +202,7 @@ GPUTarget get_target_from_device(cl::Device &device)
case 'G':
return get_bifrost_target(version);
default:
- ARM_COMPUTE_INFO("Mali GPU unknown. Target is set to the default one.");
+ ARM_COMPUTE_LOG_INFO_MSG_CORE("Mali GPU unknown. Target is set to the default one.");
return GPUTarget::MIDGARD;
}
}
diff --git a/src/core/CL/kernels/CLPoolingLayerKernel.cpp b/src/core/CL/kernels/CLPoolingLayerKernel.cpp
index 8b8f61e621..19d36a6ac6 100644
--- a/src/core/CL/kernels/CLPoolingLayerKernel.cpp
+++ b/src/core/CL/kernels/CLPoolingLayerKernel.cpp
@@ -179,6 +179,38 @@ void CLPoolingLayerKernel::configure(const ICLTensor *input, ICLTensor *output,
ICLKernel::configure(win);
}
+Error CLPoolingLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info)
+{
+ ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QS8, DataType::QS16, DataType::F16, DataType::F32);
+
+ int pool_pad_x = 0;
+ int pool_pad_y = 0;
+ int pool_size = pool_info.pool_size();
+ std::tie(pool_pad_x, pool_pad_y) = pool_info.pad_stride_info().pad();
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(((pool_pad_x >= pool_size) || (pool_pad_y >= pool_size)),
+ "Invalid pool size and pool pad combination");
+
+ // Checks performed when output is configured
+ if(output->total_size() != 0)
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_FIXED_POINT(input, output);
+
+ unsigned int pooled_w = 0;
+ unsigned int pooled_h = 0;
+ std::tie(pooled_w, pooled_h) = scaled_dimensions(input->dimension(0),
+ input->dimension(1),
+ pool_size,
+ pool_size,
+ pool_info.pad_stride_info());
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG((output->dimension(0) != pooled_w) != (output->dimension(1) != pooled_h),
+ "Invalid output pooling dimensions!");
+ }
+
+ return Error{};
+}
+
void CLPoolingLayerKernel::run(const Window &window, cl::CommandQueue &queue)
{
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
diff --git a/src/core/Error.cpp b/src/core/Error.cpp
index 389e390736..2e699feeb9 100644
--- a/src/core/Error.cpp
+++ b/src/core/Error.cpp
@@ -28,7 +28,9 @@
#include <iostream>
#include <stdexcept>
-void arm_compute::error(const char *function, const char *file, const int line, const char *msg, ...)
+using namespace arm_compute;
+
+Error arm_compute::create_error(ErrorCode error_code, const char *function, const char *file, const int line, const char *msg, ...)
{
char out[512];
va_list args;
@@ -37,16 +39,14 @@ void arm_compute::error(const char *function, const char *file, const int line,
vsnprintf(out + offset, sizeof(out) - offset, msg, args);
va_end(args);
- throw std::runtime_error(std::string(out));
+ return Error(error_code, std::string(out));
}
-void arm_compute::debug(const char *function, const char *file, const int line, const char *msg, ...)
+void arm_compute::error(const char *function, const char *file, const int line, const char *msg, ...)
{
- char out[512];
va_list args;
va_start(args, msg);
- int offset = snprintf(out, sizeof(out), "in %s %s:%d: ", function, file, line);
- vsnprintf(out + offset, sizeof(out) - offset, msg, args);
+ auto err = create_error(ErrorCode::RUNTIME_ERROR, function, file, line, msg, args);
va_end(args);
- std::cout << std::string(out) << std::endl;
+ throw std::runtime_error(err.description());
}
diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp
index 0a35e07430..bd6911fd2b 100644
--- a/src/core/Utils.cpp
+++ b/src/core/Utils.cpp
@@ -384,4 +384,5 @@ int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataTyp
default:
ARM_COMPUTE_ERROR("Undefined element size for given data type");
}
+ return 0;
}
diff --git a/src/core/Validate.cpp b/src/core/Validate.cpp
index 084a325711..b286d69454 100644
--- a/src/core/Validate.cpp
+++ b/src/core/Validate.cpp
@@ -23,108 +23,88 @@
*/
#include "arm_compute/core/Validate.h"
-void arm_compute::error_on_mismatching_windows(const char *function, const char *file, const int line,
- const arm_compute::Window &full, const arm_compute::Window &win)
+arm_compute::Error arm_compute::error_on_mismatching_windows(const char *function, const char *file, const int line,
+ const arm_compute::Window &full, const arm_compute::Window &win)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
-
full.validate();
win.validate();
for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() != win[i].start(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() != win[i].end(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != win[i].step(), function, file, line);
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_invalid_subwindow(const char *function, const char *file, const int line,
- const arm_compute::Window &full, const arm_compute::Window &sub)
+arm_compute::Error arm_compute::error_on_invalid_subwindow(const char *function, const char *file, const int line,
+ const arm_compute::Window &full, const arm_compute::Window &sub)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
-
full.validate();
sub.validate();
for(size_t i = 0; i < arm_compute::Coordinates::num_max_dimensions; ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].start() > sub[i].start(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].end() < sub[i].end(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[i].step() != sub[i].step(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC((sub[i].start() - full[i].start()) % sub[i].step(), function, file, line);
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line,
- const arm_compute::Window &full, const arm_compute::Window &window, const int dim)
+arm_compute::Error arm_compute::error_on_window_not_collapsable_at_dimension(const char *function, const char *file, const int line,
+ const arm_compute::Window &full, const arm_compute::Window &window, const int dim)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(dim);
-
full.validate();
window.validate();
- ARM_COMPUTE_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != 0, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(window[dim].start() != full[dim].start(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(full[dim].end() != window[dim].end(), function, file, line);
+
+ return arm_compute::Error{};
}
-void arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
- const arm_compute::Coordinates &pos, unsigned int max_dim)
+arm_compute::Error arm_compute::error_on_coordinates_dimensions_gte(const char *function, const char *file, const int line,
+ const arm_compute::Coordinates &pos, unsigned int max_dim)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(pos);
-
for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC(pos[i] != 0, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(pos[i] != 0, function, file, line);
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line,
- const arm_compute::Window &win, unsigned int max_dim)
+arm_compute::Error arm_compute::error_on_window_dimensions_gte(const char *function, const char *file, const int line,
+ const arm_compute::Window &win, unsigned int max_dim)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(win);
-
for(unsigned int i = max_dim; i < arm_compute::Coordinates::num_max_dimensions; ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC_MSG(win[i].start() != 0 || win[i].end() != win[i].step(),
- function, file, line,
- "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(win[i].start() != 0 || win[i].end() != win[i].step(),
+ function, file, line,
+ "Maximum number of dimensions expected %u but dimension %u is not empty", max_dim, i);
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
- const arm_compute::ITensor *tensor)
+arm_compute::Error arm_compute::error_on_tensor_not_2d(const char *function, const char *file, const int line,
+ const arm_compute::ITensor *tensor)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(tensor);
-
- ARM_COMPUTE_ERROR_ON_LOC(tensor == nullptr, function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC_MSG(tensor->info()->num_dimensions() != 2,
- function, file, line,
- "Only 2D Tensors are supported by this kernel (%d passed)", tensor->info()->num_dimensions());
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor == nullptr, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(tensor->info() == nullptr, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(tensor->info()->num_dimensions() != 2,
+ function, file, line,
+ "Only 2D Tensors are supported by this kernel (%d passed)", tensor->info()->num_dimensions());
+ return arm_compute::Error{};
}
-void arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
- arm_compute::Format fmt, arm_compute::Channel cn)
+arm_compute::Error arm_compute::error_on_channel_not_in_known_format(const char *function, const char *file, const int line,
+ arm_compute::Format fmt, arm_compute::Channel cn)
{
- ARM_COMPUTE_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(fmt == arm_compute::Format::UNKNOWN, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(cn == arm_compute::Channel::UNKNOWN, function, file, line);
switch(fmt)
{
@@ -148,84 +128,68 @@ void arm_compute::error_on_channel_not_in_known_format(const char *function, con
default:
ARM_COMPUTE_ERROR_LOC(function, file, line, "Not supported format.");
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_invalid_multi_hog(const char *function, const char *file, const int line,
- const arm_compute::IMultiHOG *multi_hog)
+arm_compute::Error arm_compute::error_on_invalid_multi_hog(const char *function, const char *file, const int line,
+ const arm_compute::IMultiHOG *multi_hog)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
-
- ARM_COMPUTE_ERROR_ON_LOC(nullptr == multi_hog, function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC(0 == multi_hog->num_models(), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(nullptr == multi_hog, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(0 == multi_hog->num_models(), function, file, line);
for(size_t i = 1; i < multi_hog->num_models(); ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->phase_type() != multi_hog->model(i)->info()->phase_type(),
- function, file, line,
- "All HOG parameters must have the same phase type");
- ARM_COMPUTE_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->normalization_type() != multi_hog->model(i)->info()->normalization_type(),
- function, file, line,
- "All HOG parameters must have the same normalization type");
- ARM_COMPUTE_ERROR_ON_LOC_MSG((multi_hog->model(0)->info()->l2_hyst_threshold() != multi_hog->model(i)->info()->l2_hyst_threshold())
- && (multi_hog->model(0)->info()->normalization_type() == arm_compute::HOGNormType::L2HYS_NORM),
- function, file, line,
- "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type");
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->phase_type() != multi_hog->model(i)->info()->phase_type(),
+ function, file, line,
+ "All HOG parameters must have the same phase type");
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG(multi_hog->model(0)->info()->normalization_type() != multi_hog->model(i)->info()->normalization_type(),
+ function, file, line,
+ "All HOG parameters must have the same normalization type");
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG((multi_hog->model(0)->info()->l2_hyst_threshold() != multi_hog->model(i)->info()->l2_hyst_threshold())
+ && (multi_hog->model(0)->info()->normalization_type() == arm_compute::HOGNormType::L2HYS_NORM),
+ function, file, line,
+ "All HOG parameters must have the same l2 hysteresis threshold if you use L2 hysteresis normalization type");
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line,
- const arm_compute::IKernel *kernel)
+arm_compute::Error arm_compute::error_on_unconfigured_kernel(const char *function, const char *file, const int line,
+ const arm_compute::IKernel *kernel)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(kernel);
-
- ARM_COMPUTE_ERROR_ON_LOC(kernel == nullptr, function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC_MSG((kernel->window().x().start() == kernel->window().x().end()) && (kernel->window().x().end() == 0) && (kernel->window().x().step() == 0),
- function, file, line,
- "This kernel hasn't been configured.");
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(kernel == nullptr, function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC_MSG((kernel->window().x().start() == kernel->window().x().end()) && (kernel->window().x().end() == 0) && (kernel->window().x().step() == 0),
+ function, file, line,
+ "This kernel hasn't been configured.");
+ return arm_compute::Error{};
}
-void arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line,
- const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape)
+arm_compute::Error arm_compute::error_on_invalid_subtensor(const char *function, const char *file, const int line,
+ const TensorShape &parent_shape, const Coordinates &coords, const TensorShape &shape)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(parent_shape);
- ARM_COMPUTE_UNUSED(coords);
- ARM_COMPUTE_UNUSED(shape);
-
// Subtensor should not index in x, y dimensions.
- ARM_COMPUTE_ERROR_ON_LOC(((coords.x() != 0) && (coords.y() != 0)), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(((coords.x() != 0) && (coords.y() != 0)), function, file, line);
// Subtensor shape should match parent tensor in x, y dimensions.
- ARM_COMPUTE_ERROR_ON_LOC(((parent_shape.x() != shape.x()) && (parent_shape.y() != parent_shape.y())), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(((parent_shape.x() != shape.x()) && (parent_shape.y() != parent_shape.y())), function, file, line);
// Check dimensions
for(unsigned int i = 0; i < TensorShape::num_max_dimensions; ++i)
{
- ARM_COMPUTE_ERROR_ON_LOC(((coords[i] >= static_cast<int>(parent_shape[i])) || (coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]))),
- function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC(((coords[i] >= static_cast<int>(parent_shape[i])) || (coords[i] + static_cast<int>(shape[i]) > static_cast<int>(parent_shape[i]))),
+ function, file, line);
}
+ return arm_compute::Error{};
}
-void arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
- const ValidRegion &parent_valid_region, const ValidRegion &valid_region)
+arm_compute::Error arm_compute::error_on_invalid_subtensor_valid_region(const char *function, const char *file, const int line,
+ const ValidRegion &parent_valid_region, const ValidRegion &valid_region)
{
- ARM_COMPUTE_UNUSED(function);
- ARM_COMPUTE_UNUSED(file);
- ARM_COMPUTE_UNUSED(line);
- ARM_COMPUTE_UNUSED(parent_valid_region);
- ARM_COMPUTE_UNUSED(valid_region);
-
// Check valid regions
for(unsigned int d = 0; d < TensorShape::num_max_dimensions; ++d)
{
- ARM_COMPUTE_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
- ARM_COMPUTE_ERROR_ON_LOC((parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) < (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
- function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] > valid_region.anchor[d]), function, file, line);
+ ARM_COMPUTE_RETURN_ERROR_ON_LOC((parent_valid_region.anchor[d] + static_cast<int>(parent_valid_region.shape[d])) < (valid_region.anchor[d] + static_cast<int>(valid_region.shape[d])),
+ function, file, line);
}
+
+ return arm_compute::Error{};
}