diff options
Diffstat (limited to 'src/graph/Utils.cpp')
-rw-r--r-- | src/graph/Utils.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
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 |