diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-04-03 13:44:29 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:49:16 +0000 |
commit | d9eb27597eabe5b7c17520f4f9b3f8a282d72573 (patch) | |
tree | 9b2b7d74b0ef83623b18d6d4279a564e5b63d641 /arm_compute/graph/backends | |
parent | a8ca2b0cfe052c9a28b691317a674f28f495c139 (diff) | |
download | ComputeLibrary-d9eb27597eabe5b7c17520f4f9b3f8a282d72573.tar.gz |
COMPMID-797: Switch to new graph.
- Cleaned up build system
Change-Id: If2faa27ee5b31fa8b972836960ab3ef671059c8d
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/126435
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Pablo Tello <pablo.tello@arm.com>
Diffstat (limited to 'arm_compute/graph/backends')
18 files changed, 1262 insertions, 0 deletions
diff --git a/arm_compute/graph/backends/BackendRegistrar.h b/arm_compute/graph/backends/BackendRegistrar.h new file mode 100644 index 0000000000..f7f2f7f9d2 --- /dev/null +++ b/arm_compute/graph/backends/BackendRegistrar.h @@ -0,0 +1,61 @@ +/* + * 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_GRAPH_BACKEND_REGISTRAR_H__ +#define ARM_COMPUTE_GRAPH_BACKEND_REGISTRAR_H__ + +#include "arm_compute/graph/Types.h" +#include "arm_compute/graph/backends/BackendRegistry.h" + +#include <utility> + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +namespace detail +{ +/** Helper class to statically register a backend */ +template <typename T> +class BackendRegistrar final +{ +public: + /** Add a new backend to the backend registry + * + * @param[in] target Execution target + */ + BackendRegistrar(Target target); +}; + +template <typename T> +inline BackendRegistrar<T>::BackendRegistrar(Target target) +{ + BackendRegistry::get().add_backend<T>(target); +} +} // namespace detail +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* ARM_COMPUTE_GRAPH_BACKEND_REGISTRAR_H__ */
\ No newline at end of file diff --git a/arm_compute/graph/backends/BackendRegistry.h b/arm_compute/graph/backends/BackendRegistry.h new file mode 100644 index 0000000000..69114ed26d --- /dev/null +++ b/arm_compute/graph/backends/BackendRegistry.h @@ -0,0 +1,91 @@ +/* + * 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_GRAPH_BACKEND_REGISTRY_H__ +#define __ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H__ + +#include "arm_compute/graph/IDeviceBackend.h" +#include "arm_compute/graph/Types.h" +#include "support/ToolchainSupport.h" + +#include <map> +#include <memory> + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** Registry holding all the supported backends */ +class BackendRegistry final +{ +public: + /** Gets backend registry instance + * + * @return Backend registry instance + */ + static BackendRegistry &get(); + /** Finds a backend in the registry + * + * @param[in] target Backend target + * + * @return Pointer to the backend interface if found, else nullptr + */ + IDeviceBackend *find_backend(Target target); + /** Checks if a backend for a given target exists + * + * @param[in] target Execution target + * + * @return True if exists else false + */ + bool contains(Target target) const; + /** Backends accessor + * + * @return Map containing the registered backends + */ + const std::map<Target, std::unique_ptr<IDeviceBackend>> &backends() const; + /** Registers a backend to the registry + * + * @param[in] target Execution target to register for + */ + template <typename T> + void add_backend(Target target); + +private: + /** Default Constructor */ + BackendRegistry(); + +private: + std::map<Target, std::unique_ptr<IDeviceBackend>> _registered_backends; +}; + +template <typename T> +inline void BackendRegistry::add_backend(Target target) +{ + _registered_backends[target] = support::cpp14::make_unique<T>(); +} +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_BACKEND_REGISTRY_H__ */ diff --git a/arm_compute/graph/backends/CL/CLDeviceBackend.h b/arm_compute/graph/backends/CL/CLDeviceBackend.h new file mode 100644 index 0000000000..5adbe0e1a8 --- /dev/null +++ b/arm_compute/graph/backends/CL/CLDeviceBackend.h @@ -0,0 +1,71 @@ +/* + * 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_GRAPH_CLDEVICEBACKEND_H__ +#define __ARM_COMPUTE_GRAPH_CLDEVICEBACKEND_H__ + +#include "arm_compute/graph/IDeviceBackend.h" + +#include "arm_compute/runtime/CL/CLBufferAllocator.h" +#include "arm_compute/runtime/CL/CLTuner.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** OpenCL device backend */ +class CLDeviceBackend final : public IDeviceBackend +{ +public: + /** Default Constructor */ + CLDeviceBackend(); + /** Destructor */ + ~CLDeviceBackend(); + /** Switchs on or off the kernel tuning + * + * @note When true the tuner set is used, if no tuner is set a new default one is created + * + * @param[in] enable_tuning Enables tuning if false else true + */ + void set_kernel_tuning(bool enable_tuning); + + // Inherited overridden methods + void initialize_backend() override; + void setup_backend_context(GraphContext &ctx) override; + bool is_backend_supported() override; + std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) override; + std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) override; + std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) override; + Status validate_node(INode &node) override; + std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) override; + +private: + CLTuner _tuner; /**< CL kernel tuner */ + CLBufferAllocator _allocator; /**< CL buffer affinity allocator */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_CLDEVICEBACKEND_H__ diff --git a/arm_compute/graph/backends/CL/CLFunctionFactory.h b/arm_compute/graph/backends/CL/CLFunctionFactory.h new file mode 100644 index 0000000000..6caca547cf --- /dev/null +++ b/arm_compute/graph/backends/CL/CLFunctionFactory.h @@ -0,0 +1,57 @@ +/* + * 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_GRAPH_CLFUNCTIONFACTORY_H__ +#define __ARM_COMPUTE_GRAPH_CLFUNCTIONFACTORY_H__ + +#include "arm_compute/runtime/IFunction.h" + +#include <memory> + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; +class GraphContext; + +namespace backends +{ +/** Factory for generating OpenCL backend functions **/ +class CLFunctionFactory final +{ +public: + /** Create a backend execution function depending on the node type + * + * @param[in] node Node to create the backend function for + * @param[in] ctx Context to use + * + * @return Backend function + */ + static std::unique_ptr<arm_compute::IFunction> create(INode *node, GraphContext &ctx); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_CLFUNCTIONFACTORY_H__ diff --git a/arm_compute/graph/backends/CL/CLNodeValidator.h b/arm_compute/graph/backends/CL/CLNodeValidator.h new file mode 100644 index 0000000000..9bd4842cf7 --- /dev/null +++ b/arm_compute/graph/backends/CL/CLNodeValidator.h @@ -0,0 +1,52 @@ +/* + * 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_GRAPH_CLNODEVALIDATOR_H__ +#define __ARM_COMPUTE_GRAPH_CLNODEVALIDATOR_H__ + +#include "arm_compute/core/Error.h" + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; + +namespace backends +{ +class CLNodeValidator final +{ +public: + /** Validate a node + * + * @param[in] node Node to validate + * + * @return An error status + */ + static Status validate(INode *node); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_CLNODEVALIDATOR_H__ diff --git a/arm_compute/graph/backends/CL/CLSubTensorHandle.h b/arm_compute/graph/backends/CL/CLSubTensorHandle.h new file mode 100644 index 0000000000..4be5842c70 --- /dev/null +++ b/arm_compute/graph/backends/CL/CLSubTensorHandle.h @@ -0,0 +1,71 @@ +/* + * 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_GRAPH_CLSUBTENSORHANDLE_H__ +#define __ARM_COMPUTE_GRAPH_CLSUBTENSORHANDLE_H__ + +#include "arm_compute/graph/ITensorHandle.h" + +#include "arm_compute/runtime/CL/CLSubTensor.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** OpenCL Sub-Tensor handle interface object **/ +class CLSubTensorHandle final : public ITensorHandle +{ +public: + /** Default constructor + * + * @param[in] parent_handle Parent tensor handle + * @param[in] shape Sub-Tensor shape + * @param[in] coords Starting coordinates + * @param[in] extend_parent Extends parent shape if true + */ + CLSubTensorHandle(ITensorHandle *parent_handle, const TensorShape &shape, const Coordinates &coords, bool extend_parent = false); + /** Destructor: free the tensor's memory */ + ~CLSubTensorHandle() = default; + /** Allow instances of this class to be move constructed */ + CLSubTensorHandle(CLSubTensorHandle &&) = default; + /** Allow instances of this class to be moved */ + CLSubTensorHandle &operator=(CLSubTensorHandle &&) = default; + + // Inherited overridden methods + void allocate() override; + arm_compute::ITensor &tensor() override; + const arm_compute::ITensor &tensor() const override; + void map(bool blocking) override; + void unmap() override; + void release_if_unused() override; + bool is_subtensor() const override; + +private: + arm_compute::CLSubTensor _sub_tensor; /**< Backend Sub-Tensor */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_CLSUBTENSORHANDLE_H__ */ diff --git a/arm_compute/graph/backends/CL/CLTensorHandle.h b/arm_compute/graph/backends/CL/CLTensorHandle.h new file mode 100644 index 0000000000..8f5a70cbbb --- /dev/null +++ b/arm_compute/graph/backends/CL/CLTensorHandle.h @@ -0,0 +1,68 @@ +/* + * 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_GRAPH_CLTENSORHANDLE_H__ +#define __ARM_COMPUTE_GRAPH_CLTENSORHANDLE_H__ + +#include "arm_compute/graph/ITensorHandle.h" + +#include "arm_compute/runtime/CL/CLTensor.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** OpenCL Tensor handle interface object **/ +class CLTensorHandle final : public ITensorHandle +{ +public: + /** Default Constructor + * + * @param[in] info Tensor metadata + */ + CLTensorHandle(const ITensorInfo &info); + /** Destructor: free the tensor's memory */ + ~CLTensorHandle() = default; + /** Allow instances of this class to be move constructed */ + CLTensorHandle(CLTensorHandle &&) = default; + /** Allow instances of this class to be moved */ + CLTensorHandle &operator=(CLTensorHandle &&) = default; + + // Inherited overridden methods + void allocate() override; + arm_compute::ITensor &tensor() override; + const arm_compute::ITensor &tensor() const override; + void map(bool blocking) override; + void unmap() override; + void release_if_unused() override; + bool is_subtensor() const override; + +private: + arm_compute::CLTensor _tensor; /**< Backend Tensor */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_CLTENSORHANDLE_H__ */ diff --git a/arm_compute/graph/backends/GLES/GCDeviceBackend.h b/arm_compute/graph/backends/GLES/GCDeviceBackend.h new file mode 100644 index 0000000000..be81a8f1f2 --- /dev/null +++ b/arm_compute/graph/backends/GLES/GCDeviceBackend.h @@ -0,0 +1,60 @@ +/* + * 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_GRAPH_GCDEVICEBACKEND_H__ +#define __ARM_COMPUTE_GRAPH_GCDEVICEBACKEND_H__ + +#include "arm_compute/graph/IDeviceBackend.h" + +#include "arm_compute/runtime/GLES_COMPUTE/GCBufferAllocator.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** GLES Compute device backend */ +class GCDeviceBackend final : public IDeviceBackend +{ +public: + /** Default Constructor */ + GCDeviceBackend(); + + // Inherited overridden methods + void initialize_backend() override; + void setup_backend_context(GraphContext &ctx) override; + bool is_backend_supported() override; + std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) override; + std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) override; + std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) override; + Status validate_node(INode &node) override; + std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) override; + +private: + GCBufferAllocator _allocator; /**< GLES buffer affinity allocator */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_GCDEVICEBACKEND_H__ diff --git a/arm_compute/graph/backends/GLES/GCFunctionFactory.h b/arm_compute/graph/backends/GLES/GCFunctionFactory.h new file mode 100644 index 0000000000..c819c034f6 --- /dev/null +++ b/arm_compute/graph/backends/GLES/GCFunctionFactory.h @@ -0,0 +1,57 @@ +/* + * 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_GRAPH_GCFUNCTIONFACTORY_H__ +#define __ARM_COMPUTE_GRAPH_GCFUNCTIONFACTORY_H__ + +#include "arm_compute/runtime/IFunction.h" + +#include <memory> + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; +class GraphContext; + +namespace backends +{ +/** Factory for generating GLES compute backend functions **/ +class GCFunctionFactory final +{ +public: + /** Create a backend execution function depending on the node type + * + * @param[in] node Node to create the backend function for + * @param[in] ctx Context to use + * + * @return Backend function + */ + static std::unique_ptr<arm_compute::IFunction> create(INode *node, GraphContext &ctx); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_GCFUNCTIONFACTORY_H__ diff --git a/arm_compute/graph/backends/GLES/GCNodeValidator.h b/arm_compute/graph/backends/GLES/GCNodeValidator.h new file mode 100644 index 0000000000..6fdfbdd894 --- /dev/null +++ b/arm_compute/graph/backends/GLES/GCNodeValidator.h @@ -0,0 +1,52 @@ +/* + * 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_GRAPH_GCNODEVALIDATOR_H__ +#define __ARM_COMPUTE_GRAPH_GCNODEVALIDATOR_H__ + +#include "arm_compute/core/Error.h" + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; + +namespace backends +{ +class GCNodeValidator final +{ +public: + /** Validate a node + * + * @param[in] node Node to validate + * + * @return An error status + */ + static Status validate(INode *node); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_GCNODEVALIDATOR_H__ diff --git a/arm_compute/graph/backends/GLES/GCTensorHandle.h b/arm_compute/graph/backends/GLES/GCTensorHandle.h new file mode 100644 index 0000000000..774268fd3f --- /dev/null +++ b/arm_compute/graph/backends/GLES/GCTensorHandle.h @@ -0,0 +1,68 @@ +/* + * 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_GRAPH_GCTENSORHANDLE_H__ +#define __ARM_COMPUTE_GRAPH_GCTENSORHANDLE_H__ + +#include "arm_compute/graph/ITensorHandle.h" + +#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** GLES compute tensor handle interface object **/ +class GCTensorHandle final : public ITensorHandle +{ +public: + /** Default Constructor + * + * @param[in] info Tensor metadata + */ + GCTensorHandle(const ITensorInfo &info); + /** Destructor: free the tensor's memory */ + ~GCTensorHandle() = default; + /** Allow instances of this class to be move constructed */ + GCTensorHandle(GCTensorHandle &&) = default; + /** Allow instances of this class to be moved */ + GCTensorHandle &operator=(GCTensorHandle &&) = default; + + // Inherited overridden methods + void allocate() override; + arm_compute::ITensor &tensor() override; + const arm_compute::ITensor &tensor() const override; + void map(bool blocking) override; + void unmap() override; + void release_if_unused() override; + bool is_subtensor() const override; + +private: + arm_compute::GCTensor _tensor; /**< Backend Tensor */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_GCTENSORHANDLE_H__ */ diff --git a/arm_compute/graph/backends/NEON/NEDeviceBackend.h b/arm_compute/graph/backends/NEON/NEDeviceBackend.h new file mode 100644 index 0000000000..b23c83adea --- /dev/null +++ b/arm_compute/graph/backends/NEON/NEDeviceBackend.h @@ -0,0 +1,59 @@ +/* + * 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_GRAPH_NEDEVICEBACKEND_H__ +#define __ARM_COMPUTE_GRAPH_NEDEVICEBACKEND_H__ + +#include "arm_compute/graph/IDeviceBackend.h" + +#include "arm_compute/runtime/Allocator.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** NEON device backend */ +class NEDeviceBackend final : public IDeviceBackend +{ +public: + NEDeviceBackend(); + + // Inherited overridden methods + void initialize_backend() override; + void setup_backend_context(GraphContext &ctx) override; + bool is_backend_supported() override; + std::unique_ptr<ITensorHandle> create_tensor(const Tensor &tensor) override; + std::unique_ptr<ITensorHandle> create_subtensor(ITensorHandle *parent, TensorShape shape, Coordinates coords, bool extend_parent) override; + std::unique_ptr<arm_compute::IFunction> configure_node(INode &node, GraphContext &ctx) override; + Status validate_node(INode &node) override; + std::shared_ptr<arm_compute::IMemoryManager> create_memory_manager(MemoryManagerAffinity affinity) override; + +private: + Allocator _allocator; /**< NEON backend allocator */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_NEDEVICEBACKEND_H__ diff --git a/arm_compute/graph/backends/NEON/NEFunctionFactory.h b/arm_compute/graph/backends/NEON/NEFunctionFactory.h new file mode 100644 index 0000000000..1143c29c5b --- /dev/null +++ b/arm_compute/graph/backends/NEON/NEFunctionFactory.h @@ -0,0 +1,57 @@ +/* + * 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_GRAPH_NEFUNCTIONFACTORY_H__ +#define __ARM_COMPUTE_GRAPH_NEFUNCTIONFACTORY_H__ + +#include "arm_compute/runtime/IFunction.h" + +#include <memory> + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; +class GraphContext; + +namespace backends +{ +/** Factory for generating NEON backend functions **/ +class NEFunctionFactory final +{ +public: + /** Create a backend execution function depending on the node type + * + * @param[in] node Node to create the backend function for + * @param[in] ctx Context to use + * + * @return Backend function + */ + static std::unique_ptr<arm_compute::IFunction> create(INode *node, GraphContext &ctx); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_NEFUNCTIONFACTORY_H__ diff --git a/arm_compute/graph/backends/NEON/NENodeValidator.h b/arm_compute/graph/backends/NEON/NENodeValidator.h new file mode 100644 index 0000000000..38f58a9d91 --- /dev/null +++ b/arm_compute/graph/backends/NEON/NENodeValidator.h @@ -0,0 +1,52 @@ +/* + * 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_GRAPH_NENODEVALIDATOR_H__ +#define __ARM_COMPUTE_GRAPH_NENODEVALIDATOR_H__ + +#include "arm_compute/core/Error.h" + +namespace arm_compute +{ +namespace graph +{ +// Forward declarations +class INode; + +namespace backends +{ +class NENodeValidator final +{ +public: + /** Validate a node + * + * @param[in] node Node to validate + * + * @return An error status + */ + static Status validate(INode *node); +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif //__ARM_COMPUTE_GRAPH_NENODEVALIDATOR_H__ diff --git a/arm_compute/graph/backends/NEON/NESubTensorHandle.h b/arm_compute/graph/backends/NEON/NESubTensorHandle.h new file mode 100644 index 0000000000..11dcec60f3 --- /dev/null +++ b/arm_compute/graph/backends/NEON/NESubTensorHandle.h @@ -0,0 +1,71 @@ +/* + * 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_GRAPH_NESUBTENSORHANDLE_H__ +#define __ARM_COMPUTE_GRAPH_NESUBTENSORHANDLE_H__ + +#include "arm_compute/graph/ITensorHandle.h" + +#include "arm_compute/runtime/SubTensor.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** NEON Sub-Tensor handle interface object **/ +class NESubTensorHandle final : public ITensorHandle +{ +public: + /** Default constructor + * + * @param[in] parent_handle Parent tensor handle + * @param[in] shape Sub-Tensor shape + * @param[in] coords Starting coordinates + * @param[in] extend_parent Extends parent shape if true + */ + NESubTensorHandle(ITensorHandle *parent_handle, const TensorShape &shape, const Coordinates &coords, bool extend_parent = false); + /** Destructor: free the tensor's memory */ + ~NESubTensorHandle() = default; + /** Allow instances of this class to be move constructed */ + NESubTensorHandle(NESubTensorHandle &&) = default; + /** Allow instances of this class to be moved */ + NESubTensorHandle &operator=(NESubTensorHandle &&) = default; + + // Inherited overridden methods + void allocate() override; + arm_compute::ITensor &tensor() override; + const arm_compute::ITensor &tensor() const override; + void map(bool blocking) override; + void unmap() override; + void release_if_unused() override; + bool is_subtensor() const override; + +private: + arm_compute::SubTensor _sub_tensor; /**< Backend Sub-Tensor */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_NESUBTENSORHANDLE_H__ */ diff --git a/arm_compute/graph/backends/NEON/NETensorHandle.h b/arm_compute/graph/backends/NEON/NETensorHandle.h new file mode 100644 index 0000000000..06ccdd83cc --- /dev/null +++ b/arm_compute/graph/backends/NEON/NETensorHandle.h @@ -0,0 +1,68 @@ +/* + * 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_GRAPH_NETENSORHANDLE_H__ +#define __ARM_COMPUTE_GRAPH_NETENSORHANDLE_H__ + +#include "arm_compute/graph/ITensorHandle.h" + +#include "arm_compute/runtime/Tensor.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** NEON Tensor handle interface object **/ +class NETensorHandle final : public ITensorHandle +{ +public: + /** Default Constructor + * + * @param[in] info Tensor metadata + */ + NETensorHandle(const ITensorInfo &info); + /** Destructor: free the tensor's memory */ + ~NETensorHandle() = default; + /** Allow instances of this class to be move constructed */ + NETensorHandle(NETensorHandle &&) = default; + /** Allow instances of this class to be moved */ + NETensorHandle &operator=(NETensorHandle &&) = default; + + // Inherited overridden methods + void allocate() override; + arm_compute::ITensor &tensor() override; + const arm_compute::ITensor &tensor() const override; + void map(bool blocking) override; + void unmap() override; + void release_if_unused() override; + bool is_subtensor() const override; + +private: + arm_compute::Tensor _tensor; /**< Backend Tensor */ +}; +} // namespace backends +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_GRAPH_NETENSORHANDLE_H__ */ diff --git a/arm_compute/graph/backends/Utils.h b/arm_compute/graph/backends/Utils.h new file mode 100644 index 0000000000..b902d17c0e --- /dev/null +++ b/arm_compute/graph/backends/Utils.h @@ -0,0 +1,97 @@ +/* + * 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_GRAPH_BACKENDS_UTILS_H__ +#define __ARM_COMPUTE_GRAPH_BACKENDS_UTILS_H__ + +#include "arm_compute/graph/GraphContext.h" +#include "arm_compute/runtime/IMemoryManager.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +/** Creates and configures a named function + * + * @param[in] name Name of the function + * @param[in] args Function arguments + * + * @return A configured backend function + */ +template <typename FunctionType, typename FunctionNameType, typename... ParameterType> +std::pair<std::unique_ptr<arm_compute::IFunction>, FunctionNameType> create_named_function(FunctionNameType name, ParameterType... args) +{ + auto f = arm_compute::support::cpp14::make_unique<FunctionType>(); + f->configure(std::forward<ParameterType>(args)...); + return std::make_pair(std::move(f), name); +} + +/** Creates and configures a named function + * + * @param[in] name Name of the function + * @param[in] mm Memory manager to use + * @param[in] args Function arguments + * + * @return A configured backend function + */ +template <typename FunctionType, typename FunctionNameType, typename MemoryManagerType, typename... ParameterType> +std::pair<std::unique_ptr<arm_compute::IFunction>, FunctionNameType> create_named_memory_managed_function(FunctionNameType name, + MemoryManagerType mm, + ParameterType... args) +{ + auto f = arm_compute::support::cpp14::make_unique<FunctionType>(mm); + f->configure(std::forward<ParameterType>(args)...); + return std::make_pair(std::move(f), name); +} + +/** Checks if an operation is in place + * + * @param[in] input Pointer to input + * @param[in] output Pointer to output + * + * @return True if output is nullptr or input is equal to the output, else false + */ +inline bool is_in_place_operation(void *input, void *output) +{ + return (output == nullptr) || (input == output); +} + +/** Returns the memory manager for a given target + * + * @param[in] ctx Graph context containing memory management metadata + * @param[in] target Target to retrieve the memory manager from + * + * @return The memory manager for the given target else false + */ +inline std::shared_ptr<IMemoryManager> get_memory_manager(GraphContext &ctx, Target target) +{ + bool enabled = ctx.config().use_function_memory_manager && (ctx.memory_management_ctx(target) != nullptr); + return enabled ? ctx.memory_management_ctx(target)->mm : nullptr; +} +} // namespace backends +} // namespace graph +} // namespace arm_compute + +#endif /* __ARM_COMPUTE_GRAPH_BACKENDS_UTILS_H__ */ diff --git a/arm_compute/graph/backends/ValidateHelpers.h b/arm_compute/graph/backends/ValidateHelpers.h new file mode 100644 index 0000000000..ca01295d15 --- /dev/null +++ b/arm_compute/graph/backends/ValidateHelpers.h @@ -0,0 +1,150 @@ +/* + * 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_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H__ +#define __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H__ + +#include "arm_compute/graph/Logger.h" +#include "arm_compute/graph/Tensor.h" +#include "arm_compute/graph/Types.h" +#include "arm_compute/graph/nodes/Nodes.h" + +#include "arm_compute/core/Error.h" +#include "arm_compute/core/ITensorInfo.h" + +namespace arm_compute +{ +namespace graph +{ +namespace backends +{ +namespace detail +{ +/** Returns backing tensor info of a given tensor + * + * @param[in] tensor Tensor to extract the backing tensor from + * + * @return Backing tensor tensor info if present else nullptr + */ +inline arm_compute::ITensorInfo *get_backing_tensor_info(arm_compute::graph::Tensor *tensor) +{ + return ((tensor == nullptr) || (tensor->handle() == nullptr)) ? nullptr : tensor->handle()->tensor().info(); +} + +/** Validates a Convolution layer node + * + * @tparam ConvolutionLayer Default Convolution layer function type + * @tparam DirectConvolutionLayer Direct Convolution layer function type + * @tparam GEMMConvolutionLayer GEMM Convolution layer function type + * @tparam WinogradConvolutionLayer Winograd Convolution layer function type + * + * @param[in] node Node to validate + * + * @return Status + */ +template <typename ConvolutionLayer, typename DirectConvolutionLayer, typename GEMMConvolutionLayer, typename WinogradConvolutionLayer> +Status validate_convolution_layer(ConvolutionLayerNode &node) +{ + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); + ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); + ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); + + // Extract IO and info + arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); + arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1)); + arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2)); + arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); + const PadStrideInfo conv_info = node.convolution_info(); + const ConvolutionMethod conv_algorithm = node.convolution_method(); + + // Validate function + Status status{}; + switch(conv_algorithm) + { + case ConvolutionMethod::DIRECT: + status = DirectConvolutionLayer::validate(input, weights, biases, output, conv_info); + break; + case ConvolutionMethod::GEMM: + status = GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info); + break; + case ConvolutionMethod::WINOGRAD: + status = WinogradConvolutionLayer::validate(input, weights, biases, output, conv_info); + break; + default: + break; + } + + // If validation fails try the Default approach + if(!bool(status) || (conv_algorithm == ConvolutionMethod::DEFAULT)) + { + std::cout << status.error_description() << std::endl; + status = ConvolutionLayer::validate(input, weights, biases, output, conv_info); + if(bool(status)) + { + ARM_COMPUTE_LOG_GRAPH_INFO("Switched ConvolutionLayer method of node with ID : " + << node.id() << " and Name: " << node.name() << std::endl); + node.set_convolution_method(ConvolutionMethod::DEFAULT); + } + } + + return status; +} + +/** Validates a Depthwise Convolution layer node + * + * @tparam DepthwiseConvolutionLayer Default Depthwise Convolution layer type + * @tparam DepthwiseConvolutionLayer3x3 Optimized 3x3 Depthwise Convolution layer type + * + * @param[in] node Node to validate + * + * @return Status + */ +template <typename DepthwiseConvolutionLayer, typename DepthwiseConvolutionLayer3x3> +Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node) +{ + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); + ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); + ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); + + // Extract IO and info + arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1)); + const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method(); + ARM_COMPUTE_ERROR_ON(weights == nullptr); + + // TODO (geopin01) : Switch when validation is implemented + // Validate function + if((dwc_algorithm == DepthwiseConvolutionMethod::OPTIMIZED_3x3) && (weights->tensor_shape().x() != 3)) + { + ARM_COMPUTE_LOG_GRAPH_INFO("Switched DepthwiseConvolutionLayer method of node with ID : " + << node.id() << " and Name: " << node.name() << std::endl); + node.set_depthwise_convolution_method(DepthwiseConvolutionMethod::DEFAULT); + } + + return Status{}; +} +} // namespace detail +} // namespace backends +} // namespace graph +} // namespace arm_compute + +#endif /* __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H__ */ |