From d1ad7eae81ee12e069c4b9034ab21acb4260c697 Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Tue, 11 Dec 2018 14:40:35 -0800 Subject: [PATCH 1/8] Adding RuntimeTypes.h to contain runtime common data structures. --- include/glow/Runtime/RuntimeTypes.h | 84 +++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 include/glow/Runtime/RuntimeTypes.h diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h new file mode 100644 index 0000000000..d6c5e1825b --- /dev/null +++ b/include/glow/Runtime/RuntimeTypes.h @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GLOW_RUNTIME_RUNTIMETYPES_H +#define GLOW_RUNTIME_RUNTIMETYPES_H + +#include "glow/Graph/Graph.h" + +#include +#include +#include + +namespace glow { +namespace runtime { + +using NetworkID = size_t; +using DeviceID = size_t; + +/// Enum to communicate results when communicating with device at initialization +/// and runtime. +enum ResultCode { READY, EXECUTED, FAILED, CANCELLED }; + +struct DeviceMemoryInfo { + /// Available memory on device in MB + double availableMemory; + /// Total useable memory on device in MB + double maximumUsableMemory; +}; + +/// Data structure that contains everything needed by the executor to execute a +/// network at runtime. +struct ExecutionDAG { + /// Vector of networks to be run. + std::vector networks; + /// Mapping of networkID to the deviceID where the network is loaded. + std::unordered_map devices; + /// vector of root nodes, these have no dependencies and can be run first. + std::vector roots; + /// Mapping of networkID to a vector of it's dependancies. + std::unordered_map> dependencies; + /// Mapping of networkID to a vector of networks that depend on it. + std::unordered_map> dependents; + /// Mapping of NetworkID to a vector of input placeholder names for the + /// network. + std::unordered_map> inputs; + /// Mapping of NetworkID to a vector of output placeholder names for the + /// network. + std::unordered_map> outputs; +}; + +/// Data structure containing the output from the Partitioner. It is consumed by +/// the Provisioner and used to generate an executionDAG. +struct DependancyDAG { + /// Vector of unique pointers to modules containing sub-networks. + std::vector> modules; + /// Vector of root nodes. + std::vector roots; + /// Mapping of Module * to a vector of it's dependancies. + std::unordered_map> dependencies; + /// Mapping of Module * to a vector of networks that depend on it. + std::unordered_map> dependents; + /// Mapping of Module * to a vector of input placeholder names for the + /// network. + std::unordered_map> inputs; + /// Mapping of Module * to a vector of output placeholder names for the + /// network. + std::unordered_map> outputs; +}; + +} // namespace runtime +} // namespace glow +#endif // GLOW_RUNTIME_RUNTIMETYPES_H From f00f8faeeb3d73e7b50b48915028310d9bca5b98 Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Tue, 11 Dec 2018 16:15:04 -0800 Subject: [PATCH 2/8] Dependancy -> dependency --- include/glow/Runtime/RuntimeTypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index d6c5e1825b..bf53382696 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -62,7 +62,7 @@ struct ExecutionDAG { /// Data structure containing the output from the Partitioner. It is consumed by /// the Provisioner and used to generate an executionDAG. -struct DependancyDAG { +struct DependencyDAG { /// Vector of unique pointers to modules containing sub-networks. std::vector> modules; /// Vector of root nodes. From 2078cf6c33bb6fe5d4320f27a3c3e0bf1437686b Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Tue, 11 Dec 2018 16:40:36 -0800 Subject: [PATCH 3/8] Changed to bytes removed inputs/outputs from DependencyDAG --- include/glow/Runtime/RuntimeTypes.h | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index bf53382696..3175dc7823 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -33,10 +33,10 @@ using DeviceID = size_t; enum ResultCode { READY, EXECUTED, FAILED, CANCELLED }; struct DeviceMemoryInfo { - /// Available memory on device in MB - double availableMemory; - /// Total useable memory on device in MB - double maximumUsableMemory; + /// Available memory on device in bytes. + uint64_t availableMemory; + /// Total useable memory on device in bytes. + uint64_t maximumUsableMemory; }; /// Data structure that contains everything needed by the executor to execute a @@ -71,12 +71,6 @@ struct DependencyDAG { std::unordered_map> dependencies; /// Mapping of Module * to a vector of networks that depend on it. std::unordered_map> dependents; - /// Mapping of Module * to a vector of input placeholder names for the - /// network. - std::unordered_map> inputs; - /// Mapping of Module * to a vector of output placeholder names for the - /// network. - std::unordered_map> outputs; }; } // namespace runtime From 514a459018b4cc18e789b22a2ba9b94e15b518ab Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Wed, 12 Dec 2018 11:12:26 -0800 Subject: [PATCH 4/8] Added comments updated type names. --- include/glow/Runtime/RuntimeTypes.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index 3175dc7823..af2219bb47 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -25,13 +25,15 @@ namespace glow { namespace runtime { -using NetworkID = size_t; -using DeviceID = size_t; +using NetworkIDty = size_t; +using DeviceIDty = size_t; /// Enum to communicate results when communicating with device at initialization /// and runtime. enum ResultCode { READY, EXECUTED, FAILED, CANCELLED }; +/// Data structure that contains memory information for each device. Used to +/// communicate memory constraints to the Partitioner and Provisioner. struct DeviceMemoryInfo { /// Available memory on device in bytes. uint64_t availableMemory; @@ -43,21 +45,21 @@ struct DeviceMemoryInfo { /// network at runtime. struct ExecutionDAG { /// Vector of networks to be run. - std::vector networks; - /// Mapping of networkID to the deviceID where the network is loaded. - std::unordered_map devices; + std::vector networks; + /// Mapping of networkID to the deviceIDty where the network is loaded. + std::unordered_map devices; /// vector of root nodes, these have no dependencies and can be run first. - std::vector roots; + std::vector roots; /// Mapping of networkID to a vector of it's dependancies. - std::unordered_map> dependencies; + std::unordered_map> dependencies; /// Mapping of networkID to a vector of networks that depend on it. - std::unordered_map> dependents; - /// Mapping of NetworkID to a vector of input placeholder names for the + std::unordered_map> dependents; + /// Mapping of NetworkIDty to a vector of input placeholder names for the /// network. - std::unordered_map> inputs; - /// Mapping of NetworkID to a vector of output placeholder names for the + std::unordered_map> inputs; + /// Mapping of NetworkIDty to a vector of output placeholder names for the /// network. - std::unordered_map> outputs; + std::unordered_map> outputs; }; /// Data structure containing the output from the Partitioner. It is consumed by From e35408bb283f84c6bd05c5518d4efc9c0efafaad Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Thu, 13 Dec 2018 08:52:28 -0800 Subject: [PATCH 5/8] Added moduleSize to DependencyDAG --- include/glow/Runtime/RuntimeTypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index af2219bb47..2bfbac2784 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -73,6 +73,8 @@ struct DependencyDAG { std::unordered_map> dependencies; /// Mapping of Module * to a vector of networks that depend on it. std::unordered_map> dependents; + /// Mapping of Module * to total size of constants/weights for module. + std::unordered_map moduleSize; }; } // namespace runtime From 4f5acea2f1282188a17a1150aac2e28495abecf4 Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Thu, 13 Dec 2018 13:37:18 -0800 Subject: [PATCH 6/8] Removed Maxmemory from DeviceMemoryInfo and renamed to DeviceInfo --- include/glow/Runtime/RuntimeTypes.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index 2bfbac2784..4cd5fac229 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -32,13 +32,11 @@ using DeviceIDty = size_t; /// and runtime. enum ResultCode { READY, EXECUTED, FAILED, CANCELLED }; -/// Data structure that contains memory information for each device. Used to -/// communicate memory constraints to the Partitioner and Provisioner. -struct DeviceMemoryInfo { +/// Data structure that contains device constraint information for each device. +/// Used to communicate memory constraints and later costs to the Partitioner. +struct DeviceInfo { /// Available memory on device in bytes. uint64_t availableMemory; - /// Total useable memory on device in bytes. - uint64_t maximumUsableMemory; }; /// Data structure that contains everything needed by the executor to execute a From a7bfe847de2fe447aa88ea9be78f5d7da655cdf4 Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Thu, 27 Dec 2018 16:48:56 -0800 Subject: [PATCH 7/8] Updated RuntimeTypes to use new DAGNode, added input bool to symbolInfo --- include/glow/Backends/BackendUtils.h | 2 + include/glow/Runtime/RuntimeTypes.h | 55 +++++++++++----------------- 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/include/glow/Backends/BackendUtils.h b/include/glow/Backends/BackendUtils.h index 20ff23eef9..91f8400554 100644 --- a/include/glow/Backends/BackendUtils.h +++ b/include/glow/Backends/BackendUtils.h @@ -30,6 +30,8 @@ struct RuntimeSymbolInfo { size_t offset; /// Type of symbol. Type type; + /// Is the symbol an input for the function. + bool input; }; /// Contains the information needed to be passed forward from compile time to diff --git a/include/glow/Runtime/RuntimeTypes.h b/include/glow/Runtime/RuntimeTypes.h index 4cd5fac229..e4a8a7dd03 100644 --- a/include/glow/Runtime/RuntimeTypes.h +++ b/include/glow/Runtime/RuntimeTypes.h @@ -16,6 +16,7 @@ #ifndef GLOW_RUNTIME_RUNTIMETYPES_H #define GLOW_RUNTIME_RUNTIMETYPES_H +#include "glow/Backends/BackendUtils.h" #include "glow/Graph/Graph.h" #include @@ -39,40 +40,26 @@ struct DeviceInfo { uint64_t availableMemory; }; -/// Data structure that contains everything needed by the executor to execute a -/// network at runtime. -struct ExecutionDAG { - /// Vector of networks to be run. - std::vector networks; - /// Mapping of networkID to the deviceIDty where the network is loaded. - std::unordered_map devices; - /// vector of root nodes, these have no dependencies and can be run first. - std::vector roots; - /// Mapping of networkID to a vector of it's dependancies. - std::unordered_map> dependencies; - /// Mapping of networkID to a vector of networks that depend on it. - std::unordered_map> dependents; - /// Mapping of NetworkIDty to a vector of input placeholder names for the - /// network. - std::unordered_map> inputs; - /// Mapping of NetworkIDty to a vector of output placeholder names for the - /// network. - std::unordered_map> outputs; -}; - -/// Data structure containing the output from the Partitioner. It is consumed by -/// the Provisioner and used to generate an executionDAG. -struct DependencyDAG { - /// Vector of unique pointers to modules containing sub-networks. - std::vector> modules; - /// Vector of root nodes. - std::vector roots; - /// Mapping of Module * to a vector of it's dependancies. - std::unordered_map> dependencies; - /// Mapping of Module * to a vector of networks that depend on it. - std::unordered_map> dependents; - /// Mapping of Module * to total size of constants/weights for module. - std::unordered_map moduleSize; +/// Individual Node in the DAG for a given network. This contains all the +/// information needed to run the sub-network at inference time. +struct DAGNode { + /// The children of this node, these are nodes that depend on the current + /// node. + std::vector children; + /// Pointers to the parents of this node. This is used by the executor for + /// determining if a given node has all dependencies met. + std::vector parents; + /// ID of the deviceManager that this network is assigned to. + DeviceIDty deviceID; + /// The logicalDevice is an output of the Partitioner to indicate that two + /// networks should be assigned to the same device. + DeviceIDty logicalDevice; + /// Name assigned to the sub-network, this is the id that will be passed to + /// the DeviceManager when requesting a run of the network. + std::string name; + /// Runtime bundle containing all the symbol information for this network at + /// runtime. + RuntimeBundle runtimeBundle; }; } // namespace runtime From b796396e17c7f5e7b82cecfb8e128770264fb5e4 Mon Sep 17 00:00:00 2001 From: Garret Catron Date: Thu, 27 Dec 2018 16:54:19 -0800 Subject: [PATCH 8/8] Added output to symbolInfo --- include/glow/Backends/BackendUtils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/glow/Backends/BackendUtils.h b/include/glow/Backends/BackendUtils.h index 91f8400554..5f984093c9 100644 --- a/include/glow/Backends/BackendUtils.h +++ b/include/glow/Backends/BackendUtils.h @@ -32,6 +32,8 @@ struct RuntimeSymbolInfo { Type type; /// Is the symbol an input for the function. bool input; + /// Is the symbol an output for the function. + bool output; }; /// Contains the information needed to be passed forward from compile time to