aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/graph
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2017-10-18 17:29:27 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commit0c29cd3aac40e512d648506b1b3b8332bb45f063 (patch)
treed1ca728a9adf233f590ab7dfff8e627166c30b83 /arm_compute/graph
parentdaaa1fa506834c9d9ff44e5b38f05781ec416912 (diff)
downloadComputeLibrary-0c29cd3aac40e512d648506b1b3b8332bb45f063.tar.gz
COMPMID-630 : Rework nodes for selective target compilation.
Reworked nodes: -ActivationLayer Change-Id: Iaa394531ef208db48caa2c18a41ad9a845471f94 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/92281 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute/graph')
-rw-r--r--arm_compute/graph/IOperation.h56
-rw-r--r--arm_compute/graph/NodeContext.h143
-rw-r--r--arm_compute/graph/NodeParameter.h74
-rw-r--r--arm_compute/graph/OperationRegistrar.h59
-rw-r--r--arm_compute/graph/OperationRegistry.h86
-rw-r--r--arm_compute/graph/operations/CL/CLActivationLayerOperation.h49
-rw-r--r--arm_compute/graph/operations/NEON/NEActivationLayerOperation.h49
7 files changed, 516 insertions, 0 deletions
diff --git a/arm_compute/graph/IOperation.h b/arm_compute/graph/IOperation.h
new file mode 100644
index 0000000000..c2c56a349d
--- /dev/null
+++ b/arm_compute/graph/IOperation.h
@@ -0,0 +1,56 @@
+/*
+ * 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_GRAPH_IOPERATION_H__
+#define __ARM_COMPUTE_GRAPH_IOPERATION_H__
+
+#include "arm_compute/graph/NodeContext.h"
+#include "arm_compute/graph/Types.h"
+#include "arm_compute/runtime/IFunction.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Operation functor interface */
+class IOperation
+{
+public:
+ /** Virtual Destructor */
+ virtual ~IOperation() = default;
+ /** Interface to be implemented that configures an operation
+ *
+ * @param[in] ctx Node parameters to be used by the operation
+ */
+ virtual std::unique_ptr<arm_compute::IFunction> configure(NodeContext &ctx) = 0;
+ /** Interface to be implemented that returns the target of the operation
+ *
+ * @return Target of the operation
+ */
+ virtual TargetHint target() const = 0;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_IOPERATION_H__ */
diff --git a/arm_compute/graph/NodeContext.h b/arm_compute/graph/NodeContext.h
new file mode 100644
index 0000000000..8e8a761d22
--- /dev/null
+++ b/arm_compute/graph/NodeContext.h
@@ -0,0 +1,143 @@
+/*
+ * 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_GRAPH_NODE_CONTEXT_H__
+#define __ARM_COMPUTE_GRAPH_NODE_CONTEXT_H__
+
+#include "arm_compute/core/Error.h"
+#include "arm_compute/graph/NodeParameter.h"
+#include "arm_compute/graph/Types.h"
+#include "support/ToolchainSupport.h"
+
+#include <map>
+#include <memory>
+#include <string>
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Node Context class
+ *
+ * Node context class is used to hold all the parameters required by a node to execute
+ */
+class NodeContext
+{
+public:
+ /** Default Constructor
+ * (TODO(geopin01): Should we have an enum with all the supported ops instead?)
+ *
+ * @param[in] operation Name of the operation
+ */
+ NodeContext(std::string operation)
+ : _operation(operation), _target(TargetHint::DONT_CARE), _inputs(), _outputs(), _parameters() {};
+ /** Sets the execution target of the node
+ *
+ * @param[in] target Execution target of the node
+ */
+ void set_target(TargetHint target);
+ /** Adds an input tensor to the context
+ *
+ * @param[in] input Input to add
+ */
+ void add_input(arm_compute::ITensor *input);
+ /** Adds and output to the context
+ *
+ * @param[in] output Output to add
+ */
+ void add_output(arm_compute::ITensor *output);
+ /** Adds a parameter to the context
+ *
+ * @param[in] name Parameter name
+ * @param[in] parameter Parameter to add
+ */
+ template <typename T>
+ void add_parameter(std::string name, T parameter);
+ /** Returns the operation of this node.
+ *
+ * @return The operation name
+ */
+ std::string operation() const;
+ /** Returns the execution target of this node
+ *
+ * @return The execution target
+ */
+ TargetHint target() const;
+ /** Returns input tensor of a given index
+ *
+ * @param[in] idx Index of the input tensor
+ *
+ * @return A pointer the requested input tensor else nullptr
+ */
+ arm_compute::ITensor *input(size_t idx) const;
+ /** Returns output tensor of a given index
+ *
+ * @param[in] idx Index of the output tensor
+ *
+ * @return A pointer the requested output tensor else nullptr
+ */
+ arm_compute::ITensor *output(size_t idx) const;
+ /** Returns the parameter with the given name
+ *
+ * @param[in] name Parameter name
+ *
+ * @return The requested parameter else an empty object
+ */
+ template <typename T>
+ T parameter(std::string name) const;
+ /** Returns number of inputs
+ *
+ * @return Number of inputs
+ */
+ size_t num_inputs() const;
+ /** Returns number of output
+ *
+ * @return Number of outputs
+ */
+ size_t num_outputs() const;
+
+private:
+ std::string _operation;
+ TargetHint _target;
+ std::vector<arm_compute::ITensor *> _inputs;
+ std::vector<arm_compute::ITensor *> _outputs;
+ std::map<std::string, std::unique_ptr<NodeParameterBase>> _parameters;
+};
+
+template <typename T>
+inline void NodeContext::add_parameter(std::string name, T parameter)
+{
+ ARM_COMPUTE_ERROR_ON_MSG(_parameters.find(name) != _parameters.end(), "Parameter already exists!");
+ _parameters[name] = support::cpp14::make_unique<NodeParameter<T>>(name, parameter);
+}
+
+template <typename T>
+inline T NodeContext::parameter(std::string name) const
+{
+ auto it = _parameters.find(name);
+ ARM_COMPUTE_ERROR_ON(it == _parameters.end());
+ return static_cast<NodeParameter<T> *>(it->second.get())->value();
+}
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_NODE_CONTEXT_H__ */
diff --git a/arm_compute/graph/NodeParameter.h b/arm_compute/graph/NodeParameter.h
new file mode 100644
index 0000000000..9d3823d543
--- /dev/null
+++ b/arm_compute/graph/NodeParameter.h
@@ -0,0 +1,74 @@
+/*
+ * 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_GRAPH_NODE_PARAMETER_H__
+#define __ARM_COMPUTE_GRAPH_NODE_PARAMETER_H__
+
+#include <ostream>
+#include <string>
+
+namespace arm_compute
+{
+namespace graph
+{
+/**Node Parameter Empty base class */
+class NodeParameterBase
+{
+};
+
+/** Template parameter implementation */
+template <typename T>
+class NodeParameter : public NodeParameterBase
+{
+public:
+ /** Default Constructor
+ *
+ * @param[in] name Paremeter name
+ * @param[in] val Parameter value
+ */
+ NodeParameter(std::string name, T val)
+ : _name(name), _val(val) {};
+ /** Returns parameter's name
+ *
+ * @return the name of the parameter
+ */
+ std::string name() const
+ {
+ return _name;
+ }
+ /** Returns parameter's value
+ *
+ * @return the value of the parameter
+ */
+ T value()
+ {
+ return _val;
+ }
+
+private:
+ std::string _name;
+ T _val;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_NODE_PARAMETER_H__ */
diff --git a/arm_compute/graph/OperationRegistrar.h b/arm_compute/graph/OperationRegistrar.h
new file mode 100644
index 0000000000..ff31963dc3
--- /dev/null
+++ b/arm_compute/graph/OperationRegistrar.h
@@ -0,0 +1,59 @@
+/*
+ * 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_GRAPH_OPERATION_REGISTRAR
+#define ARM_COMPUTE_GRAPH_OPERATION_REGISTRAR
+
+#include "arm_compute/graph/OperationRegistry.h"
+#include "arm_compute/graph/Types.h"
+
+#include <string>
+#include <utility>
+
+namespace arm_compute
+{
+namespace graph
+{
+namespace detail
+{
+/** Helper class to statically register an operation */
+template <typename T>
+class OperationRegistrar final
+{
+public:
+ /** Add a new test case with the given name to the framework.
+ *
+ * @param[in] operation_name Operation name
+ */
+ OperationRegistrar(std::string operation_name);
+};
+
+template <typename T>
+inline OperationRegistrar<T>::OperationRegistrar(std::string operation_name)
+{
+ OperationRegistry::get().add_operation<T>(std::move(operation_name));
+}
+} // namespace detail
+} // namespace graph
+} // namespace arm_compute
+#endif /* ARM_COMPUTE_GRAPH_OPERATION_REGISTRAR */ \ No newline at end of file
diff --git a/arm_compute/graph/OperationRegistry.h b/arm_compute/graph/OperationRegistry.h
new file mode 100644
index 0000000000..905e8ee66f
--- /dev/null
+++ b/arm_compute/graph/OperationRegistry.h
@@ -0,0 +1,86 @@
+/*
+ * 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_GRAPH_OPERATION_REGISTRY_H__
+#define __ARM_COMPUTE_GRAPH_OPERATION_REGISTRY_H__
+
+#include "arm_compute/graph/IOperation.h"
+#include "arm_compute/graph/Types.h"
+#include "support/ToolchainSupport.h"
+
+#include <map>
+#include <memory>
+#include <string>
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Registry holding all the supported operations */
+class OperationRegistry
+{
+public:
+ /** Gets operation registry instance
+ *
+ * @return Operation registry instance
+ */
+ static OperationRegistry &get();
+ /** Finds an operation in the registry
+ *
+ * @param[in] operation Name of the operation to find
+ * @param[in] target Target of the operation
+ *
+ * @return Pointer to the operation functor if found, else nullptr
+ */
+ IOperation *find_operation(const std::string &operation, TargetHint target);
+ /** Checks if an operation for a given target exists
+ *
+ * @param[in] operation Operation name
+ * @param[in] target Execution target
+ *
+ * @return True if exists else false
+ */
+ bool contains(const std::string &operation, TargetHint target) const;
+ /** Registers and operation to the registry
+ *
+ * @param operation_name Name of the operation to register
+ */
+ template <typename T>
+ void add_operation(const std::string &operation_name);
+
+private:
+ /** Default Constructor */
+ OperationRegistry();
+
+private:
+ std::map<std::string, std::vector<std::unique_ptr<IOperation>>> _registered_ops;
+};
+
+template <typename T>
+inline void OperationRegistry::add_operation(const std::string &operation_name)
+{
+ _registered_ops[operation_name].emplace_back(support::cpp14::make_unique<T>());
+}
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_OPERATION_REGISTRY_H__ */
diff --git a/arm_compute/graph/operations/CL/CLActivationLayerOperation.h b/arm_compute/graph/operations/CL/CLActivationLayerOperation.h
new file mode 100644
index 0000000000..2053fb674d
--- /dev/null
+++ b/arm_compute/graph/operations/CL/CLActivationLayerOperation.h
@@ -0,0 +1,49 @@
+/*
+ * 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_GRAPH_CL_ACTIVATIONLAYER_OPERATION_H__
+#define __ARM_COMPUTE_GRAPH_CL_ACTIVATIONLAYER_OPERATION_H__
+
+#include "arm_compute/graph/IOperation.h"
+
+#include "arm_compute/graph/NodeContext.h"
+#include "arm_compute/graph/Types.h"
+#include "arm_compute/runtime/IFunction.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Operation functor interface */
+class CLActivationLayerOperation : public IOperation
+{
+public:
+ // Inherited methods overriden:
+ std::unique_ptr<arm_compute::IFunction> configure(NodeContext &ctx) final;
+ TargetHint target() const final;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_CL_ACTIVATIONLAYER_OPERATION_H__ */
diff --git a/arm_compute/graph/operations/NEON/NEActivationLayerOperation.h b/arm_compute/graph/operations/NEON/NEActivationLayerOperation.h
new file mode 100644
index 0000000000..f6e1bd7d39
--- /dev/null
+++ b/arm_compute/graph/operations/NEON/NEActivationLayerOperation.h
@@ -0,0 +1,49 @@
+/*
+ * 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_GRAPH_NE_ACTIVATIONLAYER_OPERATION_H__
+#define __ARM_COMPUTE_GRAPH_NE_ACTIVATIONLAYER_OPERATION_H__
+
+#include "arm_compute/graph/IOperation.h"
+
+#include "arm_compute/graph/NodeContext.h"
+#include "arm_compute/graph/Types.h"
+#include "arm_compute/runtime/IFunction.h"
+
+#include <memory>
+
+namespace arm_compute
+{
+namespace graph
+{
+/** Operation functor interface */
+class NEActivationLayerOperation : public IOperation
+{
+public:
+ // Inherited methods overriden:
+ std::unique_ptr<arm_compute::IFunction> configure(NodeContext &ctx) final;
+ TargetHint target() const final;
+};
+} // namespace graph
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_GRAPH_NE_ACTIVATIONLAYER_OPERATION_H__ */