Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #2617

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • Tags
    • 贡献者
    • 分支图
    • Diff
  • Issue 1423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
  • Wiki 0
    • Wiki
  • 分析
    • 仓库
    • DevOps
  • 项目成员
  • Pages
P
Paddle
  • 项目概览
    • 项目概览
    • 详情
    • 发布
  • 仓库
    • 仓库
    • 文件
    • 提交
    • 分支
    • 标签
    • 贡献者
    • 分支图
    • 比较
  • Issue 1,423
    • Issue 1,423
    • 列表
    • 看板
    • 标记
    • 里程碑
  • 合并请求 543
    • 合并请求 543
  • Pages
  • 分析
    • 分析
    • 仓库分析
    • DevOps
  • Wiki 0
    • Wiki
  • 成员
    • 成员
  • 收起侧边栏
  • 动态
  • 分支图
  • 创建新Issue
  • 提交
  • Issue看板
已关闭
开放中
Opened 6月 27, 2017 by saxon_zh@saxon_zhGuest

Redesign of dims_ in Tensor

Created by: reyoung

Dim<N> and DDim have two advantages:

  1. Checking Rank during compile time.
  2. The memory of dims are static allocation, not dynamic allocation as std::vector.

Checking Rank

The tensor should be like this

template <size_t Rank>
class Tensor {
 public:
  Dim<Rank> dims_;
};

So, the different rank of a tensor is different type. Then we use Variable::Get<Tensor<2>>() to get a matrix. If the vairable is not typed Tensor<2>, then an error occurs.

But we do not want to have template argument now. Our tensor is like

class Tensor {
 public:
  DDim dims_;
};

then we cannot use type to check Tensor's rank, i.e., we cannot use the major advantage of Dim<N>.

Static Allocation

Dim<N> and DDim are allocated in once, not like std::vector has a growth memory. std::vector is very slow when memory needs realloc, but DDim and Dim<N> do have this issue.

However, DDim is a boost::variant. sizeof(DDim) is as large as the maximum rank that Paddle supports. The sizeof(DDim) is 48 now, can hold 12 integers. In the neural network, most of tensors' rank is less than 5.

Simpler solution

Here, I propose two solutions, which could simplify Dim<N> and DDim design.

  1. Just use a constexpr size_t MAX_RANK=12; and each tensor holds a variable size_t dims_[MAX_RANK];. The advantages of this design and DDim are same, static allocation. The disadvantage of this design is we limit our tensor's rank less than 13.

  2. Use the boost::small_vector<size_t, 5> dims_ to represent dims. boost::small_vector is a vector-like container optimized for the case when it contains few elements. If rank is less than 5, dims_ is static allocation at once. Otherwise, it just likes a plain std::vector.

Maybe we should change our dim design?

指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#2617
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7