1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_TENSORRT_DELEGATE_ 17 #define MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_TENSORRT_DELEGATE_ 18 #include <string> 19 #include <vector> 20 #include <map> 21 #include <memory> 22 #include "include/api/delegate.h" 23 #include "src/delegate/tensorrt/tensorrt_subgraph.h" 24 #include "include/api/kernel.h" 25 #include "include/errorcode.h" 26 #include "src/common/log_adapter.h" 27 #include "include/api/context.h" 28 29 namespace mindspore::lite { 30 typedef TensorRTOp *(*TensorRTGetOp)(const schema::Primitive *primitive, 31 const std::vector<mindspore::MSTensor> &in_tensors, 32 const std::vector<mindspore::MSTensor> &out_tensors, const std::string &name); 33 34 class TensorRTDelegate : public Delegate { 35 public: TensorRTDelegate(mindspore::Context * context)36 explicit TensorRTDelegate(mindspore::Context *context) : context_(context) {} 37 38 ~TensorRTDelegate() override; 39 40 Status Init() override; 41 42 Status Build(DelegateModel<schema::Primitive> *model) override; 43 44 private: 45 TensorRTOp *FindTensorRTOp(kernel::Kernel *kernel, const schema::Primitive *primitive); 46 47 TensorRTSubGraph *CreateTensorRTGraph(const std::vector<TensorRTOp *> &ops, DelegateModel<schema::Primitive> *model, 48 KernelIter from, KernelIter end); 49 50 std::map<schema::PrimitiveType, TensorRTGetOp> op_func_lists_; 51 52 std::vector<schema::PrimitiveType> unsupport_hw_op_lists_; 53 54 mindspore::Context *context_; 55 56 std::shared_ptr<GPUDeviceInfo> device_info_{nullptr}; 57 58 TensorRTRuntime *runtime_{nullptr}; 59 60 bool support_hw_resize_{true}; 61 }; 62 } // namespace mindspore::lite 63 #endif // MINDSPORE_LITE_SRC_RUNTIME_DELEGATE_TENSORRT_DELEGATE_ 64