aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-12-12 19:01:46 +0000
committerGeorgios Pinitas <georgios.pinitas@arm.com>2018-12-13 10:42:21 +0000
commit3ba0ab113cd81705a3e5962ba807f30656987935 (patch)
tree9fb587dcb8b0c14aeeaf261bff340a95841ff85c
parent05045c1e052dbba4e44bf0bb8ead3e9b5220d04e (diff)
downloadComputeLibrary-3ba0ab113cd81705a3e5962ba807f30656987935.tar.gz
COMPMID-1710: Avoid undefined behavior in GCC 8.2
Undefined behavior when pushing object which contain unique_ptr to a vector container. Vector dynamic resizing was making all the unique_ptr members of the inserted objects up to this point invalid. As a workaround, memory is reserved to avoid vector reallocation. Change-Id: I74f7641a7f36981ebe51720a924b865bb7f54c91 Reviewed-on: https://review.mlplatform.org/390 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Marquez <pablo.tello@arm.com>
-rw-r--r--arm_compute/graph/Workload.h14
-rw-r--r--src/graph/detail/ExecutionHelpers.cpp8
2 files changed, 18 insertions, 4 deletions
diff --git a/arm_compute/graph/Workload.h b/arm_compute/graph/Workload.h
index e9368eefd0..682b08d88d 100644
--- a/arm_compute/graph/Workload.h
+++ b/arm_compute/graph/Workload.h
@@ -69,6 +69,20 @@ public:
*/
struct ExecutionTask
{
+ ExecutionTask(std::unique_ptr<arm_compute::IFunction> &&f, INode *n)
+ : task(std::move(f)), node(n)
+ {
+ }
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ ExecutionTask(const ExecutionTask &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ ExecutionTask &operator=(const ExecutionTask &) = delete;
+ /** Default Move Constructor. */
+ ExecutionTask(ExecutionTask &&) noexcept = default;
+ /** Default move assignment operator */
+ ExecutionTask &operator=(ExecutionTask &&) noexcept = default;
+ /** Default destructor */
+ ~ExecutionTask() = default;
// TODO (geopin01) : Support vector of functions?
std::unique_ptr<arm_compute::IFunction> task = {}; /**< Task to execute */
INode *node = {}; /**< Node bound to this workload */
diff --git a/src/graph/detail/ExecutionHelpers.cpp b/src/graph/detail/ExecutionHelpers.cpp
index f2c381b7df..767154b45e 100644
--- a/src/graph/detail/ExecutionHelpers.cpp
+++ b/src/graph/detail/ExecutionHelpers.cpp
@@ -135,6 +135,9 @@ ExecutionWorkload configure_all_nodes(Graph &g, GraphContext &ctx, const std::ve
workload.graph = &g;
workload.ctx = &ctx;
+ // Reserve memory for tasks
+ workload.tasks.reserve(node_order.size());
+
// Create tasks
for(auto &node_id : node_order)
{
@@ -146,10 +149,7 @@ ExecutionWorkload configure_all_nodes(Graph &g, GraphContext &ctx, const std::ve
std::unique_ptr<IFunction> func = backend.configure_node(*node, ctx);
if(func != nullptr)
{
- ExecutionTask task;
- task.task = std::move(func);
- task.node = node;
- workload.tasks.push_back(std::move(task));
+ workload.tasks.emplace_back(ExecutionTask(std::move(func), node));
}
}
}