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_CL_LINEAR_STORAGE_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_CL_LINEAR_STORAGE_H_ 18 19 #include <string> 20 #include <utility> 21 22 #include "absl/strings/str_cat.h" 23 #include "absl/types/span.h" 24 #include "tensorflow/lite/delegates/gpu/cl/cl_context.h" 25 #include "tensorflow/lite/delegates/gpu/cl/gpu_object.h" 26 #include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h" 27 #include "tensorflow/lite/delegates/gpu/cl/util.h" 28 #include "tensorflow/lite/delegates/gpu/common/data_type.h" 29 #include "tensorflow/lite/delegates/gpu/common/status.h" 30 #include "tensorflow/lite/delegates/gpu/common/task/tensor_desc.h" 31 #include "tensorflow/lite/delegates/gpu/common/task/tensor_linear_desc.h" 32 #include "tensorflow/lite/delegates/gpu/common/types.h" 33 34 namespace tflite { 35 namespace gpu { 36 namespace cl { 37 38 // Represent GPU 1D-array of FLT4(float4/half4) values 39 // Can use inside texture2d or buffer 40 class LinearStorage : public GPUObject { 41 public: LinearStorage()42 LinearStorage() {} ~LinearStorage()43 ~LinearStorage() override { Release(); } 44 45 // Move only 46 LinearStorage(LinearStorage&& storage); 47 LinearStorage& operator=(LinearStorage&& storage); 48 LinearStorage(const LinearStorage&) = delete; 49 LinearStorage& operator=(const LinearStorage&) = delete; 50 51 absl::Status GetGPUResources(const GPUObjectDescriptor* obj_ptr, 52 GPUResourcesWithValue* resources) const override; 53 54 absl::Status CreateFromTensorLinearDescriptor( 55 const TensorLinearDescriptor& desc, CLContext* context); 56 57 private: 58 void Release(); 59 60 cl_mem memory_ = nullptr; 61 int depth_; 62 LinearStorageType storage_type_; 63 }; 64 65 } // namespace cl 66 } // namespace gpu 67 } // namespace tflite 68 69 #endif // TENSORFLOW_LITE_DELEGATES_GPU_CL_LINEAR_STORAGE_H_ 70