Tensor: An Unified Data Type in PaddlePaddle#2099
Tensor: An Unified Data Type in PaddlePaddle#2099wangkuiyi merged 4 commits intoPaddlePaddle:developfrom
Conversation
| 2. `Allocation`: heterogeneous resource allocator [i.e. 20MB in GPU]. | ||
| 3. `Dim`: size of each dimension. [i.e. Dim<4>({10, 2, 5, 1})] | ||
| 4. `Array`: dynamic array consists of `Place`, `Dim`, and a pointer to memory. | ||
|
|
There was a problem hiding this comment.
I think maybe we should take Expression templates into consideration, which could reduce some temp memory allocation. And paddle has a implementation already.
There was a problem hiding this comment.
It looks like pretty useful in linear operations.
| 4. `Array`: dynamic array consists of `Place`, `Dim`, and a pointer to memory. | ||
|
|
||
| If you dig deeper into Majel source code, you will find Majel heavily use `boost.variant`. The variant class template is a safe, generic, stack-based discriminated union container, **offering a simple solution for manipulating an object from a heterogeneous set of types in a uniform manner**. Whereas standard containers such as std::vector may be thought of as "multi-value, single type," variant is "multi-type, single value." | ||
|
|
There was a problem hiding this comment.
Does Majel introduces other libraries from boost? Let's make a check
There was a problem hiding this comment.
$ for i in $(du -a | grep '\.h$' | cut -f 2); do \
grep 'boost::' $i; \
done | \
grep -o 'boost::[a-zA-Z_]*' | sort | uniq
boost::apply_visitor
boost::bad_get
boost::get
boost::python
boost::shared_ptr
boost::static_visitor
boost::variant
wangkuiyi
left a comment
There was a problem hiding this comment.
This is one of the best design doc I've read since I joined PaddlePaddle project. It states the pain point and gradually derives a solution, which is justifiably optimal.
paddle/tensor/README.md
Outdated
|
|
||
| Consequently, we decide to refactor PaddlePaddle step-by-step. First, refactor and replace Matrix/Vector to Tensor, a modern terminology in the deep learning system. Fortunately, we can learn from Majel how to define a Tensor. | ||
|
|
||
| To simplify heterogeneous resource allocation in any dimensions (1-9) and types (double, float, float16), Majel consists of several primitives such as `Dim`, `Place` and `Array`, all of them are standard C++ classes. |
There was a problem hiding this comment.
standard C++ classes ==> C++ class templates
|
|
||
| int main() | ||
| { | ||
| boost::variant< int, std::string > u("hello world"); |
There was a problem hiding this comment.
Thanks for this example of boost:variant.
I noticed an additional interesting thing about variant -- the default value of a varaint typed variable is the first template argument. For example, if Place is defined as
typedef boost::variant<GpuPlace, CpuPlace> Place;then
Place p;
std::out << p;prints "GpuPlace(0)".
However, if we reverse the order of GpuPlace and CpuPlace in the definition of Place like
typedef boost:variant<CpuPlace, GpuPlace> Place;then above printing code would prints "CpuPlace".
There was a problem hiding this comment.
Why Majel did not write as typedef boost:variant<CpuPlace, GpuPlace> Place; If do so, it will default allocate the memory in CPU place.
|
A few questions:
|
Yeah, It's more convenient to work on
I strongly agree with you. we should reserve the name
I tested all features of variant in Majel using lightweight header files and it works well. If add boost, everyone needs to install it and we can even throw
Yeah, I will review, approve and replace makefile to CMake. |
* ttfnet infer * fix ttfnet deploy * clean code * add comment, fix config * add comment, update modelzoo * fix norm resize, update modelzoo
View
I already integrated a lightweight
variantinto our project, so we can excludeboostnow.It's better to maintain a new repository https://github.com/gangliao/Tensor , because we don't want PaddlePaddle Review Process and Messaging to block our progress. We want more focused on refactoring.InTensorrepository, I addedvariant, runnable CMake and unit test framework to accelerate our development progress.