• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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_METAL_GPU_OBJECT_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_METAL_GPU_OBJECT_H_
18 
19 #import <Metal/Metal.h>
20 
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "tensorflow/lite/delegates/gpu/common/access_type.h"
27 #include "tensorflow/lite/delegates/gpu/common/data_type.h"
28 #include "tensorflow/lite/delegates/gpu/common/status.h"
29 #include "tensorflow/lite/delegates/gpu/common/task/gpu_object_desc.h"
30 
31 namespace tflite {
32 namespace gpu {
33 namespace metal {
34 
35 struct GPUResourcesWithValue {
36   std::vector<std::pair<std::string, int>> ints;
37   std::vector<std::pair<std::string, float>> floats;
38   std::vector<std::pair<std::string, id<MTLBuffer>>> buffers;
39   std::vector<std::pair<std::string, id<MTLTexture>>> images2d;
40   std::vector<std::pair<std::string, id<MTLTexture>>> image2d_arrays;
41   std::vector<std::pair<std::string, id<MTLTexture>>> images3d;
42   std::vector<std::pair<std::string, id<MTLTexture>>> image_buffers;
43 };
44 
45 class GPUObject {
46  public:
47   GPUObject() = default;
48   // Move only
49   GPUObject(GPUObject&& obj_desc) = default;
50   GPUObject& operator=(GPUObject&& obj_desc) = default;
51   GPUObject(const GPUObject&) = delete;
52   GPUObject& operator=(const GPUObject&) = delete;
53   virtual ~GPUObject() = default;
54   virtual absl::Status GetGPUResources(
55       const GPUObjectDescriptor* obj_ptr,
56       GPUResourcesWithValue* resources) const = 0;
57 };
58 
59 using GPUObjectPtr = std::unique_ptr<GPUObject>;
60 
61 }  // namespace metal
62 }  // namespace gpu
63 }  // namespace tflite
64 
65 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_METAL_GPU_OBJECT_H_
66