• 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_CL_GPU_OBJECT_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_CL_GPU_OBJECT_H_
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h"
25 #include "tensorflow/lite/delegates/gpu/common/access_type.h"
26 #include "tensorflow/lite/delegates/gpu/common/data_type.h"
27 #include "tensorflow/lite/delegates/gpu/common/status.h"
28 #include "tensorflow/lite/delegates/gpu/common/task/gpu_object_desc.h"
29 
30 namespace tflite {
31 namespace gpu {
32 namespace cl {
33 
34 struct GPUResourcesWithValue {
35   std::vector<std::pair<std::string, int>> ints;
36   std::vector<std::pair<std::string, float>> floats;
37   std::vector<std::pair<std::string, cl_mem>> buffers;
38   std::vector<std::pair<std::string, cl_mem>> images2d;
39   std::vector<std::pair<std::string, cl_mem>> image2d_arrays;
40   std::vector<std::pair<std::string, cl_mem>> images3d;
41   std::vector<std::pair<std::string, cl_mem>> image_buffers;
42   std::vector<std::pair<std::string, cl_mem>> custom_memories;
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 cl
62 }  // namespace gpu
63 }  // namespace tflite
64 
65 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_CL_GPU_OBJECT_H_
66