COMPMID-793 : Add graph intermediate representation

Change-Id: Ic1685de4e19e0ac79669ef2da64e1dc96c7ea0bf
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115248
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
diff --git a/arm_compute/core/Error.h b/arm_compute/core/Error.h
index 56c7ccd..f178936 100644
--- a/arm_compute/core/Error.h
+++ b/arm_compute/core/Error.h
@@ -29,6 +29,16 @@
 
 namespace arm_compute
 {
+/** Ignores unused arguments
+ *
+ * @tparam T Argument types
+ */
+template <typename... T>
+inline void ignore_unused(T &&...)
+{
+}
+
+/** Available error codes */
 enum class ErrorCode
 {
     OK,           /**< No error */
@@ -142,9 +152,9 @@
  * This is useful if for example a variable is only used
  * in debug builds and generates a warning in release builds.
  *
- * @param[in] var Variable which is unused.
+ * @param[in] ... Variables which are unused.
  */
-#define ARM_COMPUTE_UNUSED(var) (void)(var)
+#define ARM_COMPUTE_UNUSED(...) ignore_unused(__VA_ARGS__) // NOLINT
 
 /** Creates an error with a given message
  *
diff --git a/arm_compute/core/FixedPoint.inl b/arm_compute/core/FixedPoint.inl
index 9c7e35a..eb3516e 100644
--- a/arm_compute/core/FixedPoint.inl
+++ b/arm_compute/core/FixedPoint.inl
@@ -22,7 +22,7 @@
  * SOFTWARE.
  */
 #include "arm_compute/core/Error.h"
-#include "arm_compute/core/utils/misc/utility.h"
+#include "arm_compute/core/utils/misc/Utility.h"
 
 #include <cmath>
 #include <limits>
diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h
index 24ba521..1554f63 100644
--- a/arm_compute/core/Helpers.h
+++ b/arm_compute/core/Helpers.h
@@ -33,7 +33,6 @@
 #include "arm_compute/core/TensorShape.h"
 #include "arm_compute/core/Types.h"
 #include "arm_compute/core/Window.h"
-#include "arm_compute/core/utils/misc/utility.h"
 
 #include <array>
 #include <cstddef>
diff --git a/arm_compute/core/ITensorInfo.h b/arm_compute/core/ITensorInfo.h
index 167fb41..ce0cf53 100644
--- a/arm_compute/core/ITensorInfo.h
+++ b/arm_compute/core/ITensorInfo.h
@@ -30,7 +30,7 @@
 #include "arm_compute/core/Types.h"
 #include "arm_compute/core/Utils.h"
 #include "arm_compute/core/utils/misc/ICloneable.h"
-#include "arm_compute/core/utils/misc/utility.h"
+#include "arm_compute/core/utils/misc/Utility.h"
 
 #include <cstddef>
 
diff --git a/arm_compute/core/TensorShape.h b/arm_compute/core/TensorShape.h
index dc836c9..d5532e8 100644
--- a/arm_compute/core/TensorShape.h
+++ b/arm_compute/core/TensorShape.h
@@ -26,7 +26,7 @@
 
 #include "arm_compute/core/Dimensions.h"
 #include "arm_compute/core/Error.h"
-#include "arm_compute/core/utils/misc/utility.h"
+#include "arm_compute/core/utils/misc/Utility.h"
 
 #include <algorithm>
 #include <array>
diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h
index 143ee02..ae88e60 100644
--- a/arm_compute/core/Types.h
+++ b/arm_compute/core/Types.h
@@ -1076,5 +1076,5 @@
     DIRECT,  /**< Direct convolution */
     WINOGRAD /**< Convolution using Winograd */
 };
-}
+} // namespace arm_compute
 #endif /* __ARM_COMPUTE_TYPES_H__ */
diff --git a/arm_compute/core/utils/logging/Types.h b/arm_compute/core/utils/logging/Types.h
index 171270d..0b40e3d 100644
--- a/arm_compute/core/utils/logging/Types.h
+++ b/arm_compute/core/utils/logging/Types.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -36,6 +36,7 @@
     VERBOSE, /**< All logging messages */
     INFO,    /**< Information log level */
     WARN,    /**< Warning log level */
+    ERROR,   /**< Error log level */
     OFF      /**< No logging */
 };
 
diff --git a/arm_compute/core/utils/misc/CRTP.h b/arm_compute/core/utils/misc/CRTP.h
new file mode 100644
index 0000000..9947312
--- /dev/null
+++ b/arm_compute/core/utils/misc/CRTP.h
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_MISC_CRTP_H__
+#define __ARM_COMPUTE_MISC_CRTP_H__
+
+namespace arm_compute
+{
+namespace misc
+{
+/** Curiously recurring template pattern Interface */
+template <typename T, template <typename> class Type>
+struct CRTP
+{
+public:
+    using ExactType = T;
+
+protected:
+    const T &impl() const
+    {
+        return static_cast<const T &>(*this);
+    }
+    T &impl()
+    {
+        return static_cast<T &>(*this);
+    }
+
+private:
+    CRTP() = default;
+    friend Type<T>;
+};
+} // namespace misc
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_MISC_CRTP_H__ */
diff --git a/arm_compute/core/utils/misc/Cast.h b/arm_compute/core/utils/misc/Cast.h
new file mode 100644
index 0000000..f6c91dd
--- /dev/null
+++ b/arm_compute/core/utils/misc/Cast.h
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_MISC_CAST_H__
+#define __ARM_COMPUTE_MISC_CAST_H__
+
+#include "arm_compute/core/Error.h"
+
+namespace arm_compute
+{
+namespace utils
+{
+namespace cast
+{
+/** Polymorphic cast between two types
+ *
+ * @warning Will throw an exception if cast cannot take place
+ *
+ * @tparam Target Target to cast type
+ * @tparam Source Source from cast type
+ *
+ * @param[in] v Value to cast
+ *
+ * @return The casted type
+ */
+template <typename Target, typename Source>
+inline Target polymorphic_cast(Source *v)
+{
+    if(dynamic_cast<Target>(v) == nullptr)
+    {
+        throw std::bad_cast();
+    }
+    return static_cast<Target>(v);
+}
+
+/** Polymorphic down cast between two types
+ *
+ * @warning Will assert if cannot take place
+ *
+ * @tparam Target Target to cast type
+ * @tparam Source Source from cast type
+ *
+ * @param[in] v Value to cast
+ *
+ * @return The casted type
+ */
+template <typename Target, typename Source>
+inline Target polymorphic_downcast(Source *v)
+{
+    ARM_COMPUTE_ERROR_ON(dynamic_cast<Target>(v) != static_cast<Target>(v));
+    return static_cast<Target>(v);
+}
+} // namespace cast
+} // namespace utils
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_MISC_CAST_H__ */
diff --git a/arm_compute/core/utils/misc/Iterable.h b/arm_compute/core/utils/misc/Iterable.h
new file mode 100644
index 0000000..96a650a
--- /dev/null
+++ b/arm_compute/core/utils/misc/Iterable.h
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_MISC_ITERABLE_H__
+#define __ARM_COMPUTE_MISC_ITERABLE_H__
+
+#include <iterator>
+
+namespace arm_compute
+{
+namespace utils
+{
+namespace iterable
+{
+/** Reverse range iterable class
+ *
+ * @tparam T Type to create a reverse range on
+ */
+template <typename T>
+class reverse_iterable
+{
+public:
+    /** Default constructor
+     *
+     * @param[in] it Value to reverse iterate on
+     */
+    explicit reverse_iterable(T &it)
+        : _it(it)
+    {
+    }
+
+    typename T::reverse_iterator begin()
+    {
+        return _it.rbegin();
+    }
+
+    typename T::reverse_iterator end()
+    {
+        return _it.rend();
+    }
+
+    typename T::const_reverse_iterator cbegin()
+    {
+        return _it.rbegin();
+    }
+
+    typename T::const_reverse_iterator cend()
+    {
+        return _it.rend();
+    }
+
+private:
+    T &_it;
+};
+
+/** Creates a reverse iterable for a given type
+ *
+ * @tparam T Type to create a reverse iterable on
+ *
+ * @param[in] val Iterable input
+ *
+ * @return Reverse iterable container
+ */
+template <typename T>
+reverse_iterable<T> reverse_iterate(T &val)
+{
+    return reverse_iterable<T>(val);
+}
+} // namespace iterable
+} // namespace utils
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_MISC_ITERABLE_H__ */
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h
index 2919625..354f60d 100644
--- a/arm_compute/core/utils/misc/ShapeCalculator.h
+++ b/arm_compute/core/utils/misc/ShapeCalculator.h
@@ -174,7 +174,6 @@
 
     return output_shape;
 }
-
 inline TensorShape compute_fully_connected_reshaped_weights_shape(const ITensorInfo *input, bool transpose_weights, bool is_batched_fc_layer, const int interleave)
 {
     TensorShape output_shape{ input->tensor_shape() };
@@ -194,7 +193,6 @@
 
     return output_shape;
 }
-
 inline TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const PadStrideInfo &conv_info, const Size2D &kernel_size)
 {
     // Compute height
@@ -212,6 +210,22 @@
 
     return output_shape;
 }
+inline TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info)
+{
+    const TensorShape input_shape{ input.tensor_shape() };
+    const TensorShape weights_shape{ weights.tensor_shape() };
+
+    unsigned int output_width  = 0;
+    unsigned int output_height = 0;
+    std::tie(output_width, output_height) = scaled_dimensions(input_shape.x(), input_shape.y(), weights_shape.x(), weights_shape.y(), conv_info);
+
+    TensorShape output_shape{ input_shape };
+    output_shape.set(0, output_width);
+    output_shape.set(1, output_height);
+    output_shape.set(2, weights_shape[3]);
+
+    return output_shape;
+}
 } // namespace shape_calculator
 } // namespace misc
 } // namespace arm_compute
diff --git a/arm_compute/core/utils/misc/utility.h b/arm_compute/core/utils/misc/Utility.h
similarity index 99%
rename from arm_compute/core/utils/misc/utility.h
rename to arm_compute/core/utils/misc/Utility.h
index 8ba9231..639f2e1 100644
--- a/arm_compute/core/utils/misc/utility.h
+++ b/arm_compute/core/utils/misc/Utility.h
@@ -164,7 +164,6 @@
 
     return idx;
 }
-
 } // namespace utility
 } // namespace arm_compute
 #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */
diff --git a/arm_compute/core/utils/strong_type/StrongType.h b/arm_compute/core/utils/strong_type/StrongType.h
new file mode 100644
index 0000000..5a38edb
--- /dev/null
+++ b/arm_compute/core/utils/strong_type/StrongType.h
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_H__
+#define __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_H__
+
+#include <type_traits>
+
+namespace arm_compute
+{
+namespace strong_type
+{
+/** Strong type
+ *
+ * @tparam T           Exact type of the Strong Type
+ * @tparam Tag         Tag used to distinguish between types with same T
+ * @tparam Attributes  Attributes of the Strong Type
+ */
+template <typename T, typename Tag, template <typename> class... Attributes>
+class StrongType : public Attributes<StrongType<T, Tag, Attributes...>>...
+{
+public:
+    /** Exact underlying type **/
+    using ExactType = T;
+
+public:
+    /** Default Constructor
+     *
+     * @param[in] val Initialization value
+     */
+    StrongType(T val)
+        : _val(val)
+    {
+    }
+    /** Accessor of the value of the exact type
+     *
+     * @return Exact type value
+     */
+    T &get()
+    {
+        return _val;
+    }
+    /** Accessor of the value of the exact type
+     *
+     * @return Exact type value
+     */
+    const T &get() const
+    {
+        return _val;
+    }
+
+private:
+    T _val = {};
+};
+} // namespace strong_type
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_H__ */
diff --git a/arm_compute/core/utils/strong_type/StrongTypeAttributes.h b/arm_compute/core/utils/strong_type/StrongTypeAttributes.h
new file mode 100644
index 0000000..b5ed48f
--- /dev/null
+++ b/arm_compute/core/utils/strong_type/StrongTypeAttributes.h
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+#ifndef __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__
+#define __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__
+
+#include "arm_compute/core/utils/misc/CRTP.h"
+
+namespace arm_compute
+{
+namespace strong_type
+{
+/** Comparable attribute */
+template <typename T>
+struct Comparable : misc::CRTP<T, Comparable>
+{
+    bool operator==(T const &other) const
+    {
+        return this->impl().get() == other.get();
+    }
+    bool operator!=(T const &other) const
+    {
+        return !(*this == other);
+    }
+    bool operator>(T const &other) const
+    {
+        return this->impl().get() > other.get();
+    }
+    bool operator<(T const &other) const
+    {
+        return this->impl().get() < other.get();
+    }
+    bool operator>=(T const &other) const
+    {
+        return !(*this < other);
+    }
+    bool operator<=(T const &other) const
+    {
+        return !(*this > other);
+    }
+};
+} // namespace strong_type
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__ */