From cac13b1cfd593889271f8e2191be2039b8d88f36 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 27 Apr 2018 19:07:19 +0100 Subject: COMPMID-1097: Port mobilenet to NHWC Change-Id: I789065bfa0d4ef133388e1904c5caf31e450f80f Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129495 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- src/graph/Utils.cpp | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'src/graph/Utils.cpp') diff --git a/src/graph/Utils.cpp b/src/graph/Utils.cpp index 8537bbfb2a..030fa2df59 100644 --- a/src/graph/Utils.cpp +++ b/src/graph/Utils.cpp @@ -89,10 +89,6 @@ PassManager create_default_pass_manager(Target target) return pm; } -/** Default setups a graph Context - * - * @param[in] ctx Context to default initialize - */ void setup_default_graph_context(GraphContext &ctx) { for(const auto &backend : backends::BackendRegistry::get().backends()) @@ -100,5 +96,40 @@ void setup_default_graph_context(GraphContext &ctx) backend.second->setup_backend_context(ctx); } } + +size_t get_dimension_size(const TensorDescriptor &descriptor, const DataLayoutDimension data_layout_dimension) +{ + ARM_COMPUTE_ERROR_ON_MSG(descriptor.layout == DataLayout::UNKNOWN, "Cannot retrieve the dimension index for an unknown layout!"); + return descriptor.shape[get_dimension_idx(descriptor, data_layout_dimension)]; +} + +size_t get_dimension_idx(const TensorDescriptor &descriptor, const DataLayoutDimension data_layout_dimension) +{ + ARM_COMPUTE_ERROR_ON_MSG(descriptor.layout == DataLayout::UNKNOWN, "Cannot retrieve the dimension index for an unknown layout!"); + + /* Return the index based on the data layout + * [N C H W] + * [3 2 1 0] + * [N H W C] + */ + switch(data_layout_dimension) + { + case DataLayoutDimension::CHANNEL: + return (descriptor.layout == DataLayout::NCHW) ? 2 : 0; + break; + case DataLayoutDimension::HEIGHT: + return (descriptor.layout == DataLayout::NCHW) ? 1 : 2; + break; + case DataLayoutDimension::WIDTH: + return (descriptor.layout == DataLayout::NCHW) ? 0 : 1; + break; + case DataLayoutDimension::BATCHES: + return 3; + break; + default: + ARM_COMPUTE_ERROR("Data layout index not supported!"); + break; + } +} } // namespace graph } // namespace arm_compute \ No newline at end of file -- cgit v1.2.1