/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 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 TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TENSOR_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TENSOR_H_ #include #include #include "tensorflow/lite/delegates/gpu/common/data_type.h" #include "tensorflow/lite/delegates/gpu/common/shape.h" namespace tflite { namespace gpu { namespace internal_tensor { // Meta function given element type returns a type for Tensor data container. template struct StorageType; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; template <> struct StorageType { using value = std::vector; }; } // namespace internal_tensor template struct Tensor { using ShapeType = ShapeT; constexpr static DataType kType = Type; using TensorStorageType = typename internal_tensor::StorageType::value; // Opaque id of a tensor. int64_t id = -1; ShapeType shape; TensorStorageType data; }; // TensorRef is a reference to another tensor. If an object should never hold // tensor data, then TensorRef should be used instead. template struct TensorRef { using ShapeType = ShapeT; DataType type = DataType::UNKNOWN; ShapeT shape; // Opaque reference to a tensor. Upstream component is responsible for // resolving this reference into an actual tensor. int64_t ref = -1; // Specifies if the tensor should be a variable input tensor that must be an // output as well as an input to the graph. bool is_variable_input = false; }; template constexpr DataType Tensor::kType; template Tensor MakeZeroTensor(const ShapeT& shape) { Tensor tensor; tensor.shape = shape; tensor.data = typename Tensor::TensorStorageType( shape.DimensionsProduct(), 0); return tensor; } using TensorFloat32 = Tensor; using Tensor5DFloat32 = Tensor; } // namespace gpu } // namespace tflite #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TENSOR_H_