Apollo 11.0
自动驾驶开放平台
inference.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
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
17#pragma once
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23
26
27#if GPU_PLATFORM == NVIDIA
28 #include <c10/cuda/CUDACachingAllocator.h>
29 using c10::cuda::CUDACachingAllocator::emptyCache;
30#elif GPU_PLATFORM == AMD
31 #include <c10/hip/HIPCachingAllocator.h>
32 using c10::hip::HIPCachingAllocator::emptyCache;
33#endif
34
35namespace apollo {
36namespace perception {
37namespace inference {
38
39typedef std::map<std::string, base::BlobPtr<float>> BlobMap;
40
41class Inference {
42 public:
43 Inference() = default;
44
45 virtual ~Inference() = default;
46
47 virtual bool Init(const std::map<std::string, std::vector<int>> &shapes) = 0;
48
49 virtual void Infer() = 0;
50
51 virtual base::BlobPtr<float> get_blob(const std::string &name) = 0;
52
53 virtual void SetStream(cudaStream_t stream) {}
54
55 void set_max_batch_size(const int &batch_size);
56
57 void set_gpu_id(const int &gpu_id);
58
59 void set_model_info(const std::string &proto_file,
60 const std::vector<std::string> &net_input_names,
61 const std::vector<std::string> &net_output_names);
62
63 protected:
65 int gpu_id_ = 0;
66 std::string proto_file_ = "";
67 std::vector<std::string> net_output_names_;
68 std::vector<std::string> net_input_names_;
69};
70
71} // namespace inference
72} // namespace perception
73} // namespace apollo
std::vector< std::string > net_input_names_
Definition inference.h:68
virtual void SetStream(cudaStream_t stream)
Definition inference.h:53
std::vector< std::string > net_output_names_
Definition inference.h:67
virtual bool Init(const std::map< std::string, std::vector< int > > &shapes)=0
virtual base::BlobPtr< float > get_blob(const std::string &name)=0
void set_model_info(const std::string &proto_file, const std::vector< std::string > &net_input_names, const std::vector< std::string > &net_output_names)
Definition inference.cc:29
void set_max_batch_size(const int &batch_size)
Definition inference.cc:23
void set_gpu_id(const int &gpu_id)
Definition inference.cc:27
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition blob.h:313
std::map< std::string, base::BlobPtr< float > > BlobMap
Definition inference.h:39
class register implement
Definition arena_queue.h:37