[自制深度学习推理框架]笔记1

本次笔记包含第一课和第二课

vector<vector<vector<float>>>

在内存中并不连续,容易造成内存的访问,扩容以及修改的不方便(比如卷积的时候cache不命中)

KuiperInfer框架中使用Armadillo里的arma::matarma::cube类作为数据管理类来实现Tensor类。Tensor类的主要工作是封装arma::cube并提供了方便数据访问的对外接口

class Tensor{
public:
    void Function1(); // 对外接口1
    void Function2(); // 对外接口2
private:
    std::vector<uint32_t> raw_shapes_;
    arma::fcube data_; //具体的数据管理者
}

Cube与Matrix关系详见本文,可以简单的认为就是按照BCHW方式保存

namespace kuiper_infer {
Tensor<float>::Tensor(uint32_t channels, uint32_t rows, uint32_t cols) {
  data_ = arma::fcube(rows, cols, channels);
}

其中fcube是float cube

知识点:1. 赋值函数,2. 拷贝构造函数

uint32_t Tensor<float>::cols() const {
}
uint32_t Tensor<float>::channels() const {
}
uint32_t Tensor<float>::size() const {
}
void Tensor<float>::set_data(const arma::fcube& data) {
}
bool Tensor<float>::empty() const {
}
float Tensor<float>::index(uint32_t offset) const {
}
float& Tensor<float>::index(uint32_t offset) {
}
std::vector<uint32_t> Tensor<float>::shapes() const {
}
float Tensor<float>::at(uint32_t channel, uint32_t row, uint32_t col) const {
}
float& Tensor<float>::at(uint32_t channel, uint32_t row, uint32_t col) {
}
void Tensor<float>::Fill(float value) {
}
void Tensor<float>::Fill(const std::vector<float>& values) {
}

知识点:
3. CHECK的使用
4. 以下函数有什么区别

float Tensor<float>::index(uint32_t offset) const {
  CHECK(offset < this->data_.size()) << "Tensor capacity is not enough!";
  return this->data_.at(offset);
}

float& Tensor<float>::index(uint32_t offset) {
  CHECK(offset < this->data_.size()) << "Tensor capacity is not enough!";
  return this->data_.at(offset);
}

Tensor类模板
拥有两个特化类

知识点:
5. 特化类
6. std::move

Tensor(arma::cube)是列主序的!

作业:
完成padding,fill函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值