arm_compute v17.10

Change-Id: If1489af40eccd0219ede8946577afbf04db31b29
diff --git a/examples/SConscript b/examples/SConscript
index 853a1bb..52d2f26 100644
--- a/examples/SConscript
+++ b/examples/SConscript
@@ -30,7 +30,6 @@
 examples_env = env.Clone()
 
 examples_env.Append(CPPPATH = ["#"])
-examples_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
 examples_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
 
 # Build examples
@@ -38,39 +37,44 @@
 
 if env['os'] in ['android', 'bare_metal'] or env['standalone']:
     Import('arm_compute_a')
-    arm_compute_lib = arm_compute_a
+    Import('arm_compute_core_a')
+    arm_compute_libs = [ arm_compute_a, arm_compute_core_a ]
     arm_compute_dependency = arm_compute_a
 else:
     Import('arm_compute_so')
-    arm_compute_lib = "arm_compute"
+    arm_compute_libs = ["arm_compute", "arm_compute_core"]
     arm_compute_dependency = arm_compute_so
 
 if env['opencl'] and env['neon']:
     for file in Glob("./neoncl_*.cpp"):
         example = os.path.basename(os.path.splitext(str(file))[0])
-        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = [arm_compute_lib, "OpenCL"])
+        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = arm_compute_libs +["OpenCL"])
         Depends(prog, [arm_compute_dependency, opencl])
         alias = examples_env.Alias(example, prog)
         Default(alias)
-    Import('arm_compute_graph_a')
-    Import('arm_compute_graph_so')
     if env['os'] == 'android':
-        arm_compute_graph_lib = arm_compute_graph_a
+        Import('arm_compute_graph_a')
+        Import('arm_compute_core_a')
+        Import('arm_compute_a')
+        arm_compute_graph_libs = [ arm_compute_graph_a, arm_compute_a, arm_compute_core_a]
+        graph_dependency = arm_compute_graph_a
     else:
-        arm_compute_graph_lib = "arm_compute_graph"
+        Import('arm_compute_graph_so')
+        arm_compute_graph_libs = ["arm_compute_graph", "arm_compute", "arm_compute_core"]
+        graph_dependency = arm_compute_graph_so
 
     graph_utils = examples_env.Object("../utils/GraphUtils.cpp")
     for file in Glob("./graph_*.cpp"):
         example = os.path.basename(os.path.splitext(str(file))[0])
-        prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = [arm_compute_graph_lib, "OpenCL"])
-        Depends(prog, [arm_compute_dependency, opencl])
+        prog = examples_env.Program(example, ["{}.cpp".format(example), utils, graph_utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = arm_compute_graph_libs + ["OpenCL"])
+        Depends(prog, [graph_dependency, opencl])
         alias = examples_env.Alias(example, prog)
         Default(alias)
 
 if env['opencl']:
     for file in Glob("./cl_*.cpp"):
         example = os.path.basename(os.path.splitext(str(file))[0])
-        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = [arm_compute_lib, "OpenCL"])
+        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], CPPDEFINES=['ARM_COMPUTE_CL'], LIBS = arm_compute_libs +["OpenCL"])
         Depends(prog, [arm_compute_dependency, opencl])
         alias = examples_env.Alias(example, prog)
         Default(alias)
@@ -78,7 +82,7 @@
 if env['neon']:
     for file in Glob("./neon_*.cpp"):
         example = os.path.basename(os.path.splitext(str(file))[0])
-        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = [arm_compute_lib])
+        prog = examples_env.Program(example, ["{}.cpp".format(example), utils], LIBS = arm_compute_libs)
         Depends(prog, arm_compute_dependency)
         alias = examples_env.Alias(example, prog)
         Default(alias)
diff --git a/examples/graph_alexnet.cpp b/examples/graph_alexnet.cpp
new file mode 100644
index 0000000..dce7132
--- /dev/null
+++ b/examples/graph_alexnet.cpp
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2017 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_CL /* Needed by Utils.cpp to handle OpenCL exceptions properly */
+#error "This example needs to be built with -DARM_COMPUTE_CL"
+#endif /* ARM_COMPUTE_CL */
+
+#include "arm_compute/core/Logger.h"
+#include "arm_compute/graph/Graph.h"
+#include "arm_compute/graph/Nodes.h"
+#include "arm_compute/runtime/CL/CLScheduler.h"
+#include "arm_compute/runtime/CPP/CPPScheduler.h"
+#include "arm_compute/runtime/Scheduler.h"
+#include "support/ToolchainSupport.h"
+#include "utils/GraphUtils.h"
+#include "utils/Utils.h"
+
+#include <cstdlib>
+#include <iostream>
+#include <memory>
+
+using namespace arm_compute::graph;
+using namespace arm_compute::graph_utils;
+
+/** Generates appropriate accessor according to the specified path
+ *
+ * @note If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader
+ *
+ * @param[in] path      Path to the data files
+ * @param[in] data_file Relative path to the data files from path
+ *
+ * @return An appropriate tensor accessor
+ */
+std::unique_ptr<ITensorAccessor> get_accessor(const std::string &path, const std::string &data_file)
+{
+    if(path.empty())
+    {
+        return arm_compute::support::cpp14::make_unique<DummyAccessor>();
+    }
+    else
+    {
+        return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(path + data_file);
+    }
+}
+
+/** Example demonstrating how to implement AlexNet's network using the Compute Library's graph API
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] batches )
+ */
+void main_graph_alexnet(int argc, const char **argv)
+{
+    std::string  data_path;   /** Path to the trainable data */
+    unsigned int batches = 4; /** Number of batches */
+
+    // Parse arguments
+    if(argc < 2)
+    {
+        // Print help
+        std::cout << "Usage: " << argv[0] << " [path_to_data] [batches]\n\n";
+        std::cout << "No data folder provided: using random values\n\n";
+    }
+    else if(argc == 2)
+    {
+        //Do something with argv[1]
+        data_path = argv[1];
+        std::cout << "Usage: " << argv[0] << " [path_to_data] [batches]\n\n";
+        std::cout << "No number of batches where specified, thus will use the default : " << batches << "\n\n";
+    }
+    else
+    {
+        //Do something with argv[1] and argv[2]
+        data_path = argv[1];
+        batches   = std::strtol(argv[2], nullptr, 0);
+    }
+
+    // Check if OpenCL is available and initialize the scheduler
+    TargetHint hint = TargetHint::NEON;
+    if(arm_compute::opencl_is_available())
+    {
+        arm_compute::CLScheduler::get().default_init();
+        hint = TargetHint::OPENCL;
+    }
+
+    Graph graph;
+    arm_compute::Logger::get().set_logger(std::cout, arm_compute::LoggerVerbosity::INFO);
+
+    graph << hint
+          << Tensor(TensorInfo(TensorShape(227U, 227U, 3U, batches), 1, DataType::F32), DummyAccessor())
+          // Layer 1
+          << ConvolutionLayer(
+              11U, 11U, 96U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv1_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv1_b.npy"),
+              PadStrideInfo(4, 4, 0, 0))
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          << NormalizationLayer(NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f))
+          << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0)))
+          // Layer 2
+          << ConvolutionMethodHint::DIRECT
+          << ConvolutionLayer(
+              5U, 5U, 256U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv2_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv2_b.npy"),
+              PadStrideInfo(1, 1, 2, 2), 2)
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          << NormalizationLayer(NormalizationLayerInfo(NormType::CROSS_MAP, 5, 0.0001f, 0.75f))
+          << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0)))
+          // Layer 3
+          << ConvolutionLayer(
+              3U, 3U, 384U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv3_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv3_b.npy"),
+              PadStrideInfo(1, 1, 1, 1))
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          // Layer 4
+          << ConvolutionLayer(
+              3U, 3U, 384U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv4_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv4_b.npy"),
+              PadStrideInfo(1, 1, 1, 1), 2)
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          // Layer 5
+          << ConvolutionLayer(
+              3U, 3U, 256U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv5_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/conv5_b.npy"),
+              PadStrideInfo(1, 1, 1, 1), 2)
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0)))
+          // Layer 6
+          << FullyConnectedLayer(
+              4096U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc6_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc6_b.npy"))
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          // Layer 7
+          << FullyConnectedLayer(
+              4096U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc7_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc7_b.npy"))
+          << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU))
+          // Layer 8
+          << FullyConnectedLayer(
+              1000U,
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc8_w.npy"),
+              get_accessor(data_path, "/cnn_data/alexnet_model/fc8_b.npy"))
+          // Softmax
+          << SoftmaxLayer()
+          << Tensor(DummyAccessor());
+
+    // Run graph
+    graph.run();
+}
+
+/** Main program for AlexNet
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] batches )
+ */
+int main(int argc, const char **argv)
+{
+    return arm_compute::utils::run_example(argc, argv, main_graph_alexnet);
+}
diff --git a/examples/graph_lenet.cpp b/examples/graph_lenet.cpp
index 676fdb9..1427abe 100644
--- a/examples/graph_lenet.cpp
+++ b/examples/graph_lenet.cpp
@@ -25,6 +25,7 @@
 #error "This example needs to be built with -DARM_COMPUTE_CL"
 #endif /* ARM_COMPUTE_CL */
 
+#include "arm_compute/core/Logger.h"
 #include "arm_compute/graph/Graph.h"
 #include "arm_compute/graph/Nodes.h"
 #include "arm_compute/runtime/CL/CLScheduler.h"
@@ -93,16 +94,18 @@
     }
 
     // Check if OpenCL is available and initialize the scheduler
+    TargetHint hint = TargetHint::NEON;
     if(arm_compute::opencl_is_available())
     {
         arm_compute::CLScheduler::get().default_init();
+        hint = TargetHint::OPENCL;
     }
 
     Graph graph;
-    graph.set_info_enablement(true);
+    arm_compute::Logger::get().set_logger(std::cout, arm_compute::LoggerVerbosity::INFO);
 
     //conv1 << pool1 << conv2 << pool2 << fc1 << act1 << fc2 << smx
-    graph << Hint::OPENCL
+    graph << hint
           << Tensor(TensorInfo(TensorShape(28U, 28U, 1U, batches), 1, DataType::F32), DummyAccessor())
           << ConvolutionLayer(
               5U, 5U, 20U,
diff --git a/examples/neon_cartoon_effect.cpp b/examples/neon_cartoon_effect.cpp
new file mode 100644
index 0000000..f4f2003
--- /dev/null
+++ b/examples/neon_cartoon_effect.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+
+#include "arm_compute/runtime/NEON/NEFunctions.h"
+
+#include "arm_compute/core/Types.h"
+#include "utils/Utils.h"
+
+using namespace arm_compute;
+using namespace utils;
+
+void main_neon_cartoon_effect(int argc, const char **argv)
+{
+    // Open PPM file
+    PPMLoader ppm;
+    Image     src_img;
+    Image     dst_img;
+    Image     gaus5x5_img;
+    Image     canny_edge_img;
+
+    if(argc < 2)
+    {
+        // Print help
+        std::cout << "Usage: ./build/neon_cartoon_effect [input_image.ppm]\n\n";
+        std::cout << "No input_image provided, creating a dummy 640x480 image\n";
+        // Create an empty grayscale 640x480 image
+        src_img.allocator()->init(TensorInfo(640, 480, Format::U8));
+    }
+    else
+    {
+        ppm.open(argv[1]);
+        ppm.init_image(src_img, Format::U8);
+    }
+
+    // Initialize just the dimensions and format of the images:
+    gaus5x5_img.allocator()->init(*src_img.info());
+    canny_edge_img.allocator()->init(*src_img.info());
+    dst_img.allocator()->init(*src_img.info());
+
+    NEGaussian5x5           gaus5x5;
+    NECannyEdge             canny_edge;
+    NEArithmeticSubtraction sub;
+
+    // Configure the functions to call
+    gaus5x5.configure(&src_img, &gaus5x5_img, BorderMode::REPLICATE);
+    canny_edge.configure(&src_img, &canny_edge_img, 100, 80, 3, 1, BorderMode::REPLICATE);
+    sub.configure(&gaus5x5_img, &canny_edge_img, &dst_img, ConvertPolicy::SATURATE);
+
+    // Now that the padding requirements are known we can allocate the images:
+    src_img.allocator()->allocate();
+    dst_img.allocator()->allocate();
+    gaus5x5_img.allocator()->allocate();
+    canny_edge_img.allocator()->allocate();
+
+    // Fill the input image with the content of the PPM image if a filename was provided:
+    if(ppm.is_open())
+    {
+        ppm.fill_image(src_img);
+    }
+
+    // Execute the functions:
+    gaus5x5.run();
+    canny_edge.run();
+    sub.run();
+
+    // Save the result to file:
+    if(ppm.is_open())
+    {
+        const std::string output_filename = std::string(argv[1]) + "_out.ppm";
+        save_to_ppm(dst_img, output_filename);
+    }
+}
+
+/** Main program for cartoon effect test
+ *
+ * @param[in] argc Number of arguments
+ * @param[in] argv Arguments ( [optional] Path to PPM image to process )
+ */
+int main(int argc, const char **argv)
+{
+    return utils::run_example(argc, argv, main_neon_cartoon_effect);
+}
diff --git a/examples/neon_cnn.cpp b/examples/neon_cnn.cpp
index 238f057..198890c 100644
--- a/examples/neon_cnn.cpp
+++ b/examples/neon_cnn.cpp
@@ -24,6 +24,10 @@
 #include "arm_compute/runtime/NEON/NEFunctions.h"
 
 #include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/Allocator.h"
+#include "arm_compute/runtime/BlobLifetimeManager.h"
+#include "arm_compute/runtime/MemoryManagerOnDemand.h"
+#include "arm_compute/runtime/PoolManager.h"
 #include "utils/Utils.h"
 
 using namespace arm_compute;
@@ -34,6 +38,18 @@
     ARM_COMPUTE_UNUSED(argc);
     ARM_COMPUTE_UNUSED(argv);
 
+    // Create NEON allocator
+    Allocator allocator;
+
+    // Create memory manager components
+    // We need 2 memory managers: 1 for handling the tensors within the functions (mm_layers) and 1 for handling the input and output tensors of the functions (mm_transitions))
+    auto lifetime_mgr0  = std::make_shared<BlobLifetimeManager>();                           // Create lifetime manager
+    auto lifetime_mgr1  = std::make_shared<BlobLifetimeManager>();                           // Create lifetime manager
+    auto pool_mgr0      = std::make_shared<PoolManager>();                                   // Create pool manager
+    auto pool_mgr1      = std::make_shared<PoolManager>();                                   // Create pool manager
+    auto mm_layers      = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr0, pool_mgr0); // Create the memory manager
+    auto mm_transitions = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr1, pool_mgr1); // Create the memory manager
+
     // The src tensor should contain the input image
     Tensor src;
 
@@ -55,15 +71,16 @@
     Tensor out_fc0;
     Tensor out_softmax;
 
-    NEConvolutionLayer    conv0;
-    NEConvolutionLayer    conv1;
+    // Create layers and set memory manager where allowed to manage internal memory requirements
+    NEConvolutionLayer    conv0(mm_layers);
+    NEConvolutionLayer    conv1(mm_layers);
     NEPoolingLayer        pool0;
     NEPoolingLayer        pool1;
-    NEFullyConnectedLayer fc0;
+    NEFullyConnectedLayer fc0(mm_layers);
     NEActivationLayer     act0;
     NEActivationLayer     act1;
     NEActivationLayer     act2;
-    NESoftmaxLayer        softmax;
+    NESoftmaxLayer        softmax(mm_layers);
 
     /* [Initialize tensors] */
 
@@ -171,9 +188,37 @@
 
     /* -----------------------End: [Configure functions] */
 
+    /*[ Add tensors to memory manager ]*/
+
+    // We need 2 memory groups for handling the input and output
+    // We call explicitly allocate after manage() in order to avoid overlapping lifetimes
+    MemoryGroup memory_group0(mm_transitions);
+    MemoryGroup memory_group1(mm_transitions);
+
+    memory_group0.manage(&out_conv0);
+    out_conv0.allocator()->allocate();
+    memory_group1.manage(&out_act0);
+    out_act0.allocator()->allocate();
+    memory_group0.manage(&out_pool0);
+    out_pool0.allocator()->allocate();
+    memory_group1.manage(&out_conv1);
+    out_conv1.allocator()->allocate();
+    memory_group0.manage(&out_act1);
+    out_act1.allocator()->allocate();
+    memory_group1.manage(&out_pool1);
+    out_pool1.allocator()->allocate();
+    memory_group0.manage(&out_fc0);
+    out_fc0.allocator()->allocate();
+    memory_group1.manage(&out_act2);
+    out_act2.allocator()->allocate();
+    memory_group0.manage(&out_softmax);
+    out_softmax.allocator()->allocate();
+
+    /* -----------------------End: [ Add tensors to memory manager ] */
+
     /* [Allocate tensors] */
 
-    // Now that the padding requirements are known we can allocate the images:
+    // Now that the padding requirements are known we can allocate all tensors
     src.allocator()->allocate();
     weights0.allocator()->allocate();
     weights1.allocator()->allocate();
@@ -181,18 +226,32 @@
     biases0.allocator()->allocate();
     biases1.allocator()->allocate();
     biases2.allocator()->allocate();
-    out_conv0.allocator()->allocate();
-    out_conv1.allocator()->allocate();
-    out_act0.allocator()->allocate();
-    out_act1.allocator()->allocate();
-    out_act2.allocator()->allocate();
-    out_pool0.allocator()->allocate();
-    out_pool1.allocator()->allocate();
-    out_fc0.allocator()->allocate();
-    out_softmax.allocator()->allocate();
 
     /* -----------------------End: [Allocate tensors] */
 
+    // Finalize layers memory manager
+
+    // Set allocator that the memory manager will use
+    mm_layers->set_allocator(&allocator);
+
+    // Number of pools that the manager will create. This specifies how many layers you want to run in parallel
+    mm_layers->set_num_pools(1);
+
+    // Finalize the manager. (Validity checks, memory allocations etc)
+    mm_layers->finalize();
+
+    // Finalize transitions memory manager
+
+    // Set allocator that the memory manager will use
+    mm_transitions->set_allocator(&allocator);
+
+    // Number of pools that the manager will create. This specifies how many models we can run in parallel.
+    // Setting to 2 as we need one for the input and one for the output at any given time
+    mm_transitions->set_num_pools(2);
+
+    // Finalize the manager. (Validity checks, memory allocations etc)
+    mm_transitions->finalize();
+
     /* [Initialize weights and biases tensors] */
 
     // Once the tensors have been allocated, the src, weights and biases tensors can be initialized
@@ -202,6 +261,10 @@
 
     /* [Execute the functions] */
 
+    // Acquire memory for the memory groups
+    memory_group0.acquire();
+    memory_group1.acquire();
+
     conv0.run();
     act0.run();
     pool0.run();
@@ -212,6 +275,10 @@
     act2.run();
     softmax.run();
 
+    // Release memory
+    memory_group0.release();
+    memory_group1.release();
+
     /* -----------------------End: [Execute the functions] */
 }