Skip to content

Conversation

@Superjomn
Copy link
Contributor

No description provided.

Copy link
Collaborator

@wangkuiyi wangkuiyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢 @Superjomn 的这个PR。我对这个base class的设计有些不解之处。请看看我的comment吧。

* TensorRT's ITensor follows row major, NCHW. Fluid is also row major, so in
* most cases just need to copy the data.
*/
class EngineInputConverter {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个Engine指的是什么engine呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TensorRT engine 或者 Anajin engine, 用于sub-block的加速

} // namespace inference
} // namespace paddle

#define REGISTER_TRT_INPUT_CONVERTER(in_op_type__, Converter__) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRT => TENSORRT

(*it->second)(in, out, max_size);
}

static EngineInputConverter& Global() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该返回一个 const reference 或者一个pointer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会改成 pointer

public:
EngineInputConverter() {}

virtual void operator()(const LoDTensor& in, void* out, size_t max_size) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里 max_size 的语义是什么呢?是说如果input tensor太大了,要截断?还是放弃conversion?

EngineInputConverter() {}

virtual void operator()(const LoDTensor& in, void* out, size_t max_size) {}
void Execute(const std::string& in_op_type, const LoDTensor& in, void* out,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然class name是xxxConverter,我理解 operator() 回去执行 convert。顾名思义,Execute也应该是执行 conversion 的。但是这样一来,operator() 和 Executor 的意思就重复了?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的确,Converter.Run 可能好一些

*/
class EngineInputConverter {
public:
EngineInputConverter() {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 Converter 是用来 convert 什么的呢?从 operator() 看貌似是convert LoDTensor的。其他Fluid类型是否需要convert?如果要,那么应该用什么method来convert呢?

Executor 看上去在执行一些operators。是说这个 converter 也需要能convert operators吗?如果是,那么是不是应该把 operator() 改名成 ConvertVar,把 Execute 改名成 ConvertOp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert Engine 的 Input

比如数据流是

fluid op -> LoDTensor -> ITensor -> TensorRT engine

这里的 EngineInputConverter 完成 LoDTensor.data() -> ITensor.data 的数据转换,考虑到无法保证 每个FluidOp 的输出都能用相同的方式转换成TensorRT的输入,所以用工厂为每个相关的Fluid Op 留下定制转换过程的空间。

cudaStream_t* stream_{nullptr};

private:
std::unordered_map<std::string,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样一个class里,实现了多个 design patterns:(1) singleton,(2)registration,(3)operator overloading。这几个都是 code style 里提醒需要慎用的:

我们真的需要他们吗?

@Xreki Xreki added the 预测 原名Inference,包含Capi预测问题等 label Apr 27, 2018
@@ -0,0 +1,55 @@
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

io_converter.cc和io_converter.h可以放到convert文件夹下么?

} // namespace inference
} // namespace paddle

#define REGISTER_TRT_INPUT_CONVERTER(in_op_type__, Converter__) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个define可以放到namespace里么?

private:
std::unordered_map<std::string,
::paddle::inference::tensorrt::EngineInputConverter*>
converters_;
Copy link
Contributor

@luotao1 luotao1 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::paddle::inference::tensorrt::EngineInputConverter* -》 EngineInputConverter,更加简短。

#define REGISTER_TRT_INPUT_CONVERTER(in_op_type__, Converter__) \
struct trt_input_##in_op_type__##_converter { \
trt_input_##in_op_type__##_converter() { \
::paddle::inference::tensorrt::EngineInputConverter::Global() \
Copy link
Contributor

@luotao1 luotao1 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::paddle::inference::tensorrt::EngineInputConverter* -》 EngineInputConverter,更加简短。

@Superjomn Superjomn force-pushed the feature/convert_trt_io branch from da930ab to 729c703 Compare April 30, 2018 15:16
@Superjomn Superjomn closed this May 2, 2018
@Superjomn Superjomn reopened this May 3, 2018
@Superjomn Superjomn changed the title feature/convert TensorRT IO feature/Inference Analysis booted with TensorRT engine May 3, 2018
@Superjomn Superjomn changed the title feature/Inference Analysis booted with TensorRT engine WIP feature/Inference Analysis booted with TensorRT engine May 3, 2018
@Xreki
Copy link
Contributor

Xreki commented May 3, 2018

这个PR里面的内容太多了,图相关的内容可以放在另一个PR里面吧,尽量使每个PR的功能相对独立且简单。

@Superjomn Superjomn closed this May 3, 2018
@Superjomn Superjomn reopened this May 7, 2018
@Superjomn Superjomn closed this May 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

预测 原名Inference,包含Capi预测问题等

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants