Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add offset implementation to lod tensor design #3934

Merged
merged 3 commits into from
Sep 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions paddle/framework/lod_tensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Let's go on slicing this slice. Its <1,1>-slice is
|||
```

### The General Slicing Algorithm
### The Slicing Algorithm

The algorithm, with over-simplified data structure, is defined as

Expand All @@ -106,17 +106,41 @@ struct LoDTensor {
float* tensor_;
};

LoDTensor Slice(const LoDTensor& lodt, int level, int sequence) {
LoDTensor Slice(const LoDTensor& lodt, int level, int sequence);
```

Let us revisit the example above

}
```
3
3 1 2
3 2 4 1 2 3
||| || |||| | || |||
```

### Slicing the Top Level
Suppose that we want to retrieve the <1,2>-slice

Please be aware that an RNN operator only slices the top level of a LoD Tensor to get the step inputs.
```
2
2 3
|| |||
```

```c++
LoDTensor Slice(const LoDTensor& lodt, int sequence) {
we will need to find out the starting position of this slice by summing over all leaf nodes in `LoD` to the left of the slice, i.e., 3 + 2 + 4 + 1 = 10.

To avoid the traversal of the LoD tree at slcing time, we can do it at the construction time -- instead of saving the lengths of the next level in the LoD tree, we can save the starting offset of the next level. For example, above LoD Tensor can be transformed into

```
0
0 9 10
0 3 5 9 10 12
||| || |||| | || |||
```

We don't really need the 0 on top, so the LoD Tensor could be

}
```
0 9 10
0 3 5 9 10 12
||| || |||| | || |||
```
Copy link
Contributor

Choose a reason for hiding this comment

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

有一些英文语法错误,需要再refine一下。另外需要说一下,为什么选择整体的length或offset,然后offset比length好的原因吧。