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_COMMON_SELECTORS_OPERATION_SELECTOR_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_SELECTORS_OPERATION_SELECTOR_H_ 18 19 #include <memory> 20 21 #include "absl/container/flat_hash_map.h" 22 #include "tensorflow/lite/delegates/gpu/common/model.h" 23 #include "tensorflow/lite/delegates/gpu/common/model_hints.h" 24 #include "tensorflow/lite/delegates/gpu/common/selectors/subgraph.h" 25 #include "tensorflow/lite/delegates/gpu/common/status.h" 26 #include "tensorflow/lite/delegates/gpu/common/task/gpu_operation.h" 27 #include "tensorflow/lite/delegates/gpu/common/task/tensor_desc.h" 28 #include "tensorflow/lite/delegates/gpu/common/task/weights_layout.h" 29 30 namespace tflite { 31 namespace gpu { 32 33 struct SharedWeightsConvDesc { 34 int weights_id; 35 WeightsDescription desc; 36 std::vector<int> global_const_ids; 37 38 bool operator==(const SharedWeightsConvDesc& t) const { 39 return weights_id == t.weights_id && desc == t.desc; 40 } 41 RemapIdsSharedWeightsConvDesc42 void RemapIds(const absl::flat_hash_map<int, ValueId>& mapping) { 43 for (int i = 0; i < global_const_ids.size(); ++i) { 44 int local_id = -(global_const_ids[i] + 1); 45 if (local_id >= 0) { 46 global_const_ids[i] = mapping.at(local_id); 47 } 48 } 49 } 50 }; 51 52 absl::Status GPUOperationFromNode( 53 const GpuInfo& gpu_info, const OperationDef& op_def, ModelHints hints, 54 const std::vector<Value*>& inputs, const std::vector<Value*>& outputs, 55 const Node& node, std::vector<SharedWeightsConvDesc>* shared_conv_weights, 56 GPUOperationsSubgraph* gpu_subgraph); 57 58 } // namespace gpu 59 } // namespace tflite 60 61 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_SELECTORS_OPERATION_SELECTOR_H_ 62