• 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_PROGRAM_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_CL_CL_PROGRAM_H_
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include "absl/types/span.h"
23 #include "tensorflow/lite/delegates/gpu/cl/cl_context.h"
24 #include "tensorflow/lite/delegates/gpu/cl/cl_device.h"
25 #include "tensorflow/lite/delegates/gpu/cl/opencl_wrapper.h"
26 #include "tensorflow/lite/delegates/gpu/common/status.h"
27 #include "tensorflow/lite/delegates/gpu/common/task/compiler_options.h"
28 
29 namespace tflite {
30 namespace gpu {
31 namespace cl {
32 
33 std::string CompilerOptionsToString(
34     const GpuInfo& gpu_info,
35     const std::vector<CompilerOptions>& compiler_options);
36 
37 class CLProgram {
38  public:
CLProgram()39   CLProgram() {}
40   CLProgram(cl_program program, cl_device_id device_id);
41 
42   // Move only
43   CLProgram(CLProgram&& program);
44   CLProgram& operator=(CLProgram&& program);
45   CLProgram(const CLProgram&) = delete;
46   CLProgram& operator=(const CLProgram&) = delete;
47 
48   ~CLProgram();
49 
program()50   cl_program program() const { return program_; }
51 
52   // Return the cl_device_id associated with the program object.
53   // This can be the device associated with context on which the program object
54   // has been created or can be device that was specified when a program object
55   // was created using clCreateProgramWithBinary.
GetDeviceId()56   cl_device_id GetDeviceId() const { return device_id_; }
57 
58   absl::Status GetBinary(std::vector<uint8_t>* result) const;
59 
60  private:
61   void Release();
62 
63   cl_program program_ = nullptr;
64 
65   // reference
66   cl_device_id device_id_ = nullptr;
67 };
68 
69 absl::Status CreateCLProgram(const std::string& code,
70                              const std::string& compiler_options,
71                              const CLContext& context, const CLDevice& device,
72                              CLProgram* result);
73 
74 absl::Status CreateCLProgramFromBinary(const CLContext& context,
75                                        const CLDevice& device,
76                                        absl::Span<const uint8_t> binary,
77                                        CLProgram* result);
78 
79 }  // namespace cl
80 }  // namespace gpu
81 }  // namespace tflite
82 
83 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_CL_CL_PROGRAM_H_
84