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

Method Invoke

tensorflow/lite/delegates/gpu/gl/kernels/test_util.cc:71–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71Status SingleOpModel::Invoke(const CompilationOptions& compile_options,
72 const RuntimeOptions& runtime_options,
73 const NodeShader& shader) {
74 std::unique_ptr<EglEnvironment> env;
75 RETURN_IF_ERROR(EglEnvironment::NewEglEnvironment(&env));
76
77 ObjectManager objects;
78
79 // Create buffers for input tensors.
80 {
81 std::unordered_map<int, uint32_t> tensor_to_id;
82 for (const auto* input : graph_.inputs()) {
83 tensor_to_id[input->tensor.ref] = input->id;
84 }
85 for (const auto& input : inputs_) {
86 GlBuffer buffer;
87 RETURN_IF_ERROR(CreatePHWC4BufferFromTensor(input, &buffer));
88 RETURN_IF_ERROR(
89 objects.RegisterBuffer(tensor_to_id[input.id], std::move(buffer)));
90 }
91 }
92
93 // Create buffers for output tensors.
94 for (const auto* output : graph_.outputs()) {
95 GlBuffer buffer;
96 RETURN_IF_ERROR(CreatePHWC4BufferFromTensorRef(output->tensor, &buffer));
97 RETURN_IF_ERROR(objects.RegisterBuffer(output->id, std::move(buffer)));
98 }
99
100 // Compile model.
101 GpuInfo gpu_info;
102 RETURN_IF_ERROR(RequestGpuInfo(&gpu_info));
103 std::unique_ptr<CompiledModel> compiled_model;
104 RETURN_IF_ERROR(Compile(
105 compile_options, graph_, /*tflite_graph_io=*/std::unordered_set<int>(),
106 shader, *NewDefaultWorkgroupsCalculator(gpu_info), &compiled_model));
107
108 // Get inference context.
109 auto command_queue = NewCommandQueue(gpu_info);
110 std::unique_ptr<InferenceContext> inference_context;
111 RETURN_IF_ERROR(compiled_model->NewRun(
112 runtime_options, &objects, command_queue.get(), &inference_context));
113 RETURN_IF_ERROR(inference_context->Reset());
114
115 // Run inference.
116 RETURN_IF_ERROR(inference_context->Execute());
117
118 // Copy output tensors to `output_`.
119 for (const auto* output : graph_.outputs()) {
120 TensorFloat32 tensor;
121 tensor.id = output->tensor.ref;
122 tensor.shape = output->tensor.shape;
123 tensor.data.reserve(output->tensor.shape.DimensionsProduct());
124 RETURN_IF_ERROR(
125 CopyFromPHWC4Buffer(*objects.FindBuffer(output->id), &tensor));
126 outputs_.push_back(std::move(tensor));
127 }
128 return OkStatus();

Callers 15

TESTFunction · 0.45
prelu_test.ccFile · 0.45
TESTFunction · 0.45
TEST_FFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
reshape_test.ccFile · 0.45
TESTFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls 15

RequestGpuInfoFunction · 0.85
NewCommandQueueFunction · 0.85
CopyFromPHWC4BufferFunction · 0.85
OkStatusFunction · 0.85
InvokeClass · 0.85
CompilationOptionsClass · 0.85
FindBufferMethod · 0.80
CompileFunction · 0.50
RuntimeOptionsClass · 0.50

Tested by

no test coverage detected