Apollo  6.0
Open source self driving car software
leakyReLU_plugin.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 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 <algorithm>
20 #include <vector>
21 
23 
24 namespace apollo {
25 namespace perception {
26 namespace inference {
27 
28 class ReLUPlugin : public nvinfer1::IPlugin {
29  public:
30  ReLUPlugin(const ReLUParameter &param, const nvinfer1::Dims &in_dims) {
31  input_dims_.nbDims = in_dims.nbDims;
32  CHECK_GT(input_dims_.nbDims, 0);
33  for (int i = 0; i < in_dims.nbDims; i++) {
34  input_dims_.d[i] = in_dims.d[i];
35  input_dims_.type[i] = in_dims.type[i];
36  }
37  negative_slope_ = param.negative_slope();
38  }
39 
42  virtual int initialize() { return 0; }
43  virtual void terminate() {}
44  int getNbOutputs() const override { return 1; }
45 
46  nvinfer1::Dims getOutputDimensions(int index, const nvinfer1::Dims *inputs,
47  int nbInputDims) override {
48  nvinfer1::Dims out_dims = inputs[0];
49  return out_dims;
50  }
51 
52  void configure(const nvinfer1::Dims *inputDims, int nbInputs,
53  const nvinfer1::Dims *outputDims, int nbOutputs,
54  int maxBatchSize) override {
55  input_dims_ = inputDims[0];
56  }
57 
58  size_t getWorkspaceSize(int maxBatchSize) const override { return 0; }
59 
60  virtual int enqueue(int batchSize, const void *const *inputs, void **outputs,
61  void *workspace, cudaStream_t stream);
62 
63  size_t getSerializationSize() override { return 0; }
64 
65  void serialize(void *buffer) override {
66  char *d = reinterpret_cast<char *>(buffer), *a = d;
67  size_t size = getSerializationSize();
68  CHECK_EQ(d, a + size);
69  }
70 
71  private:
72  float negative_slope_;
73  nvinfer1::Dims input_dims_;
74 };
75 
76 } // namespace inference
77 } // namespace perception
78 } // namespace apollo
int getNbOutputs() const override
Definition: leakyReLU_plugin.h:44
size_t getWorkspaceSize(int maxBatchSize) const override
Definition: leakyReLU_plugin.h:58
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
nvinfer1::Dims getOutputDimensions(int index, const nvinfer1::Dims *inputs, int nbInputDims) override
Definition: leakyReLU_plugin.h:46
ReLUPlugin(const ReLUParameter &param, const nvinfer1::Dims &in_dims)
Definition: leakyReLU_plugin.h:30
virtual int enqueue(int batchSize, const void *const *inputs, void **outputs, void *workspace, cudaStream_t stream)
virtual int initialize()
Definition: leakyReLU_plugin.h:42
void configure(const nvinfer1::Dims *inputDims, int nbInputs, const nvinfer1::Dims *outputDims, int nbOutputs, int maxBatchSize) override
Definition: leakyReLU_plugin.h:52
void serialize(void *buffer) override
Definition: leakyReLU_plugin.h:65
~ReLUPlugin()
Definition: leakyReLU_plugin.h:41
Definition: leakyReLU_plugin.h:28
size_t getSerializationSize() override
Definition: leakyReLU_plugin.h:63
ReLUPlugin()
Definition: leakyReLU_plugin.h:40
virtual void terminate()
Definition: leakyReLU_plugin.h:43