MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Prepare

Method Prepare

tensorflow/lite/delegates/gpu/cl/gpu_api_delegate.cc:90–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 }
89
90 Status Prepare(TfLiteContext* context,
91 const TfLiteDelegateParams* delegate_params) {
92 // Extract TFLite delegate execution plan from the context and convert it
93 // into FlowGraph32.
94 GraphFloat32 graph;
95 RETURN_IF_ERROR(BuildModel(context, delegate_params, &graph));
96
97 // Apply general transformations on the graph.
98 NullTransformationReporter reporter;
99 ModelTransformer transformer(&graph, &reporter);
100 if (!ApplyGeneralTransformations(&transformer)) {
101 return InternalError("Graph general transformations failed");
102 }
103
104 InferenceEnvironmentOptions env_options;
105 env_options.egl_context = options_.egl_context;
106 env_options.egl_display = options_.egl_display;
107 env_options.serialized_binary_cache = {
108 options_.serialized_binary_cache_data,
109 options_.serialized_binary_cache_size};
110 InferenceEnvironmentProperties properties;
111 Status status =
112 NewInferenceEnvironment(env_options, &environment_, &properties);
113 if (!properties.is_opencl_available) {
114 context->ReportError(context,
115 "TfLiteGpuDelegate: OpenCL is not available");
116 }
117 if (!properties.is_gl_sharing_supported) {
118 context->ReportError(context,
119 "TfLiteGpuDelegate: GL sharing is not supported");
120 }
121 if (!properties.is_cl_to_gl_fast_sync_supported) {
122 context->ReportError(
123 context, "TfLiteGpuDelegate: fast CL to GL sync is not supported");
124 }
125 if (!properties.is_gl_to_cl_fast_sync_supported) {
126 context->ReportError(
127 context, "TfLiteGpuDelegate: fast GL to CL sync is not supported");
128 }
129 RETURN_IF_ERROR(status);
130
131 InferenceOptions options;
132 options.priority = ToPriority(options_.compile_options.inference_priority);
133 options.allow_precision_loss =
134 options_.compile_options.precision_loss_allowed != 0;
135 std::unique_ptr<InferenceBuilder> builder;
136 RETURN_IF_ERROR(
137 environment_->NewInferenceBuilder(options, graph, &builder));
138
139 // At this point tflite didn't allocate tensors yet, therefore, collect
140 // indices and set all input and output tensors from tflite later.
141 auto inputs = graph.inputs();
142 input_indices_.reserve(inputs.size());
143 for (auto input : inputs) {
144 auto tensor_index = input->tensor.ref;
145 int object_index = input_indices_.size();
146 input_indices_.push_back(tensor_index);
147 RETURN_IF_ERROR(

Callers 1

DelegatePrepareFunction · 0.45

Implementers 1

GpuDelegatetensorflow/lite/delegates/gpu/java/src

Calls 15

BuildModelFunction · 0.85
NewInferenceEnvironmentFunction · 0.85
ToPriorityFunction · 0.85
NewInferenceBuilderMethod · 0.80
SetInputObjectDefMethod · 0.80
SetOutputObjectDefMethod · 0.80
InternalErrorFunction · 0.50
ReportErrorMethod · 0.45
inputsMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected