1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_SPI_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_SPI_H_ 18 19 #include <cstdint> 20 21 #include "tensorflow/lite/delegates/gpu/api.h" 22 #include "tensorflow/lite/delegates/gpu/common/access_type.h" 23 #include "tensorflow/lite/delegates/gpu/common/status.h" 24 25 // Contains only service provider-related interfaces. Users should not use them 26 // directly. 27 28 namespace tflite { 29 namespace gpu { 30 31 // Converts a tensor object into another one. 32 class TensorObjectConverter { 33 public: 34 virtual ~TensorObjectConverter() = default; 35 36 virtual absl::Status Convert(const TensorObject& input, 37 const TensorObject& output) = 0; 38 }; 39 40 class TensorObjectConverterBuilder { 41 public: 42 virtual ~TensorObjectConverterBuilder() = default; 43 44 virtual bool IsSupported(const TensorObjectDef& input, 45 const TensorObjectDef& output) const = 0; 46 47 virtual absl::Status MakeConverter( 48 const TensorObjectDef& input, const TensorObjectDef& output, 49 std::unique_ptr<TensorObjectConverter>* converter) = 0; 50 }; 51 52 // Connects tensor definition provided by a user (external) with tensor 53 // definition used by the inference engine (internal). 54 struct TensorTieDef { 55 uint32_t id; 56 AccessType access_type; 57 TensorObjectDef internal_def; 58 TensorObjectDef external_def; 59 }; 60 61 // Connects external tensor object to internal tensor object and provides 62 // functionality to copy data to/from external object to internal. 63 class TensorTie { 64 public: TensorTie(const TensorTieDef & def)65 explicit TensorTie(const TensorTieDef& def) : def_(def) {} 66 67 virtual ~TensorTie() = default; 68 69 virtual absl::Status SetExternalObject(TensorObject obj) = 0; 70 71 virtual TensorObject GetExternalObject() = 0; 72 73 virtual absl::Status CopyToExternalObject() = 0; 74 75 virtual absl::Status CopyFromExternalObject() = 0; 76 def()77 const TensorTieDef& def() const { return def_; } 78 79 private: 80 const TensorTieDef def_; 81 }; 82 83 } // namespace gpu 84 } // namespace tflite 85 86 #endif // TENSORFLOW_LITE_DELEGATES_GPU_SPI_H_ 87