深度学习框架 源码阅读 调试 分析 c++ tiny-dnn (1)

layer类层次

在这里插入图片描述

前向传播调用栈举例

在这里插入图片描述

后向传播调用栈举例

在这里插入图片描述

前向传播

在这里插入图片描述

后向传播

在这里插入图片描述

参与后向传播的有:

  1. 网络network(图graph或序列seq),
  2. 层layer(激活函数层, cnn层, rnn层,全连接层, … )

参与后前传播的有:

  1. 网络network(图graph或序列seq),
  2. 层layer(激活函数层, cnn层, rnn层,全连接层, … )
去掉并行选项, 看到完整调用栈
//config.h

//去掉以下这行的注释,  即 去掉了并行选项,  变成单线程直接调用. 
 #define CNN_SINGLE_THREAD



去掉并行选项后, 再编译, 调式, 看到以下完整调用栈

在这里插入图片描述

#完整调用栈文本

tiny_dnn::kernels::avx_conv2d_5x5_kernel<tiny_dnn::aligned_allocator<float,64> >(const tiny_dnn::core::conv_params &,const std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,const std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,const std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,const bool) conv2d_op_avx.h:178
<lambda_93cd752631eaddbf3fd5164277579d9c>::operator()(unsigned long long) conv2d_op_avx.h:461
tiny_dnn::for_i<unsigned __int64,<lambda_93cd752631eaddbf3fd5164277579d9c> >(bool,unsigned long long,<lambda_93cd752631eaddbf3fd5164277579d9c>,unsigned long long) parallel_for.h:187
tiny_dnn::kernels::conv2d_op_avx(const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > &,const std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,const std::vector<float,tiny_dnn::aligned_allocator<float,64> > &,std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > &,const tiny_dnn::core::conv_params &,const bool) conv2d_op_avx.h:460
tiny_dnn::Conv2dOp::compute(tiny_dnn::core::OpKernelContext &) conv2d_op.h:46
tiny_dnn::convolutional_layer::forward_propagation(const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *> > &,std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *> > &) convolutional_layer.h:298
tiny_dnn::layer::forward() layer.h:554
tiny_dnn::sequential::forward(const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > >,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > > > &) nodes.h:296
tiny_dnn::network<tiny_dnn::sequential>::fprop(const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > >,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > > > &) network.h:203
tiny_dnn::network<tiny_dnn::sequential>::train_onebatch<tiny_dnn::mse,tiny_dnn::adagrad>(tiny_dnn::adagrad &,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,int,const int,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *) network.h:924
tiny_dnn::network<tiny_dnn::sequential>::train_once<tiny_dnn::mse,tiny_dnn::adagrad>(tiny_dnn::adagrad &,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *,int,const int,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > *) network.h:897
tiny_dnn::network<tiny_dnn::sequential>::fit<tiny_dnn::mse,tiny_dnn::adagrad,<lambda_2167b27d0bf24d6ba6fbafdc977e3835>,<lambda_dfd0aadcd2585f275bac64861e8acb9b> >(tiny_dnn::adagrad &,const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > >,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > > > &,const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > >,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > > > &,unsigned long long,int,<lambda_2167b27d0bf24d6ba6fbafdc977e3835>,<lambda_dfd0aadcd2585f275bac64861e8acb9b>,const bool,const int,const std::vector<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > >,std::allocator<std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > > > &) network.h:863
tiny_dnn::network<tiny_dnn::sequential>::train<tiny_dnn::mse,tiny_dnn::adagrad,<lambda_2167b27d0bf24d6ba6fbafdc977e3835>,<lambda_dfd0aadcd2585f275bac64861e8acb9b> >(tiny_dnn::adagrad &,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > &,const std::vector<unsigned __int64,std::allocator<unsigned __int64> > &,unsigned long long,int,<lambda_2167b27d0bf24d6ba6fbafdc977e3835>,<lambda_dfd0aadcd2585f275bac64861e8acb9b>,const bool,const int,const std::vector<std::vector<float,tiny_dnn::aligned_allocator<float,64> >,std::allocator<std::vector<float,tiny_dnn::aligned_allocator<float,64> > > > &) network.h:305
train_lenet(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,double,const int,const int,backend_t) train.cpp:115
main(int,char **) train.cpp:212
invoke_main() 0x00007ff6939e9629
__scrt_common_main_seh() 0x00007ff6939e950e
__scrt_common_main() 0x00007ff6939e93ce
mainCRTStartup(void *) 0x00007ff6939e96be
BaseThreadInitThunk 0x00007ff903867034
RtlUserThreadStart 0x00007ff9043e2651


很明显的层次:

  1. train
    1. train_lenet
    2. sequential.train
    3. sequential.fit
    4. sequential.train_once
    5. sequential.train_onebatch
  2. forward
    1. sequential.fprop : 这是缩写 forward_propagation
    2. sequential.forward
    3. layer.forward
    4. convolutional_layer.forward_propagation
    5. Conv2dOp.compute
  3. kernel
    1. kernels.conv2d_op_avx
    2. for_i
    3. operator()
    4. kernels.avx_conv2d_5x5_kernel

由此可见, 所谓kernel就是实际干活的, 实际执行具体计算过程的. 所以应该有各种各样的kernel

完成各种各样具体计算任务的部件 叫 kernel

tiny-dnn中有以下这些kernel:

在这里插入图片描述

注意 pytorch 中的 kernel 也是这个意思

nodes: 图或序列

在这里插入图片描述

nodes : 多个节点, 即 表示 网络结构 的顶层标记类. 网络结构 有 : 图结构、序列结构

compute: 前向计算入口统称, 且 即将转向kernel

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ziix

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值