• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CL_CONTEXT_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_CL_CL_CONTEXT_H_
18 
19 #include "tensorflow/lite/delegates/gpu/cl/cl_device.h"
20 #include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h"
21 #include "tensorflow/lite/delegates/gpu/common/data_type.h"
22 #include "tensorflow/lite/delegates/gpu/common/status.h"
23 
24 namespace tflite {
25 namespace gpu {
26 namespace cl {
27 
28 // A RAII wrapper around opencl context
29 class CLContext {
30  public:
CLContext()31   CLContext() {}
32   CLContext(cl_context context, bool has_ownership);
33 
34   // Move only
35   CLContext(CLContext&& context);
36   CLContext& operator=(CLContext&& context);
37   CLContext(const CLContext&) = delete;
38   CLContext& operator=(const CLContext&) = delete;
39 
40   ~CLContext();
41 
context()42   cl_context context() const { return context_; }
43 
44   bool IsFloatTexture2DSupported(int num_channels, DataType data_type,
45                                  cl_mem_flags flags = CL_MEM_READ_WRITE) const;
46 
47  private:
48   void Release();
49 
50   cl_context context_ = nullptr;
51   bool has_ownership_ = false;
52 };
53 
54 absl::Status CreateCLContext(const CLDevice& device, CLContext* result);
55 absl::Status CreateCLGLContext(const CLDevice& device,
56                                cl_context_properties egl_context,
57                                cl_context_properties egl_display,
58                                CLContext* result);
59 
60 }  // namespace cl
61 }  // namespace gpu
62 }  // namespace tflite
63 
64 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_CL_CL_CONTEXT_H_
65