Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
0c9279af
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0c9279af
编写于
5月 17, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git log printer
上级
d2f8befa
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
229 addition
and
39 deletion
+229
-39
CMakeLists.txt
CMakeLists.txt
+4
-0
src/common/log.h
src/common/log.h
+151
-0
src/framework/executor.cpp
src/framework/executor.cpp
+0
-12
src/framework/operator.h
src/framework/operator.h
+7
-0
src/io.cpp
src/io.cpp
+9
-6
src/operators/conv_op.h
src/operators/conv_op.h
+1
-0
src/operators/kernel/arm/conv_kernel.cpp
src/operators/kernel/arm/conv_kernel.cpp
+4
-4
src/operators/op_param.cpp
src/operators/op_param.cpp
+19
-16
src/operators/op_param.h
src/operators/op_param.h
+2
-1
test/main.cpp
test/main.cpp
+1
-0
test/unit-test/test_log.cpp
test/unit-test/test_log.cpp
+31
-0
未找到文件。
CMakeLists.txt
浏览文件 @
0c9279af
...
...
@@ -48,3 +48,7 @@ add_dependencies(paddle-mobile openblas_proj)
# gen test
ADD_EXECUTABLE
(
paddle-mobile-test test/main.cpp test/test_helper.h
)
target_link_libraries
(
paddle-mobile-test paddle-mobile
)
# gen test log
ADD_EXECUTABLE
(
test-log test/unit-test/test_log.cpp
)
target_link_libraries
(
test-log paddle-mobile
)
src/common/log.h
0 → 100644
浏览文件 @
0c9279af
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#pragma once
#ifdef PADDLE_MOBILE_DEBUG
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
namespace
paddle_mobile
{
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
// log level
static
LogLevel
log_level
=
kLOG_DEBUG4
;
static
std
::
vector
<
std
::
string
>
logs
{
"NO"
,
"ERROR "
,
"WARNING"
,
"INFO "
,
"DEBUG "
,
"DEBUG1 "
,
"DEBUG2 "
,
"DEBUG3 "
,
"DEBUG4 "
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{
buffer_
<<
value
;
return
*
this
;
}
private:
void
print
(
LogLevel
level
)
{
buffer_
<<
std
::
endl
;
if
(
level
==
kLOG_ERROR
)
{
std
::
cerr
<<
buffer_
.
str
();
}
else
{
std
::
cout
<<
buffer_
.
str
();
}
}
std
::
ostringstream
buffer_
;
};
struct
ToLog
{
ToLog
(
LogLevel
level
=
kLOG_DEBUG
,
const
std
::
string
&
info
=
""
)
:
level_
(
level
)
{
unsigned
blanks
=
(
unsigned
)(
level
>
kLOG_DEBUG
?
(
level
-
kLOG_DEBUG
)
*
4
:
1
);
printer_
<<
logs
[
level
]
<<
" "
<<
info
<<
":"
<<
std
::
string
(
blanks
,
' '
);
}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
printer_
<<
value
;
return
*
this
;
}
~
ToLog
()
{
printer_
.
print
(
level_
);
}
private:
LogLevel
level_
;
Print
printer_
;
};
#define LOG(level) \
if (level > paddle_mobile::log_level) { \
} else \
paddle_mobile::ToLog(level, \
(std::stringstream() \
<< "[file: " << (strrchr(__FILE__, '/') \
? (strrchr(__FILE__, '/') + 1) \
: __FILE__) \
<< "] [line: " << __LINE__ << "] ") \
.str())
#define DLOG \
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG, \
(std::stringstream() \
<< "[file: " << (strrchr(__FILE__, '/') \
? (strrchr(__FILE__, '/') + 1) \
: __FILE__) \
<< "] [line: " << __LINE__ << "] ") \
.str())
}
#else
namespace
paddle_mobile
{
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{}
private:
};
struct
ToLog
{
ToLog
(
LogLevel
level
)
{}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
return
*
this
;
}
};
#define LOG(level) \
if (true) { \
} else \
paddle_mobile::ToLog(level)
#define DLOG \
if (true) { \
} else \
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG)
}
#endif
src/framework/executor.cpp
浏览文件 @
0c9279af
...
...
@@ -35,27 +35,15 @@ Executor<Dtype>::Executor(const Program<Dtype> p) : program_(p) {
const
std
::
vector
<
std
::
shared_ptr
<
BlockDesc
>>
blocks
=
to_predict_program_
->
Blocks
();
// std::cout << " **block size " << blocks.size() << std::endl;
for
(
int
i
=
0
;
i
<
blocks
.
size
();
++
i
)
{
std
::
shared_ptr
<
BlockDesc
>
block_desc
=
blocks
[
i
];
std
::
vector
<
std
::
shared_ptr
<
OpDesc
>>
ops
=
block_desc
->
Ops
();
// std::cout << " ops " << ops.size() << std::endl;
for
(
int
j
=
0
;
j
<
ops
.
size
();
++
j
)
{
std
::
shared_ptr
<
OpDesc
>
op
=
ops
[
j
];
// std::cout << " input 0 " << op->Input("Input")[0] << std::endl;
if
(
op
->
Type
()
==
"conv2d"
&&
op
->
Input
(
"Input"
)[
0
]
==
"pixel"
)
{
// std::cout << " conv2d attr size: " << op->GetAttrMap().size()
// << std::endl;
// std::cout << " input size: " << op->GetInputs().size() <<
// std::endl;
// std::cout << " output size: " << op->GetOutputs().size() <<
// std::endl;
Attribute
strides_attr
=
op
->
GetAttrMap
().
at
(
"strides"
);
std
::
vector
<
int
>
stride
=
strides_attr
.
Get
<
std
::
vector
<
int
>>
();
for
(
int
k
=
0
;
k
<
stride
.
size
();
++
k
)
{
// std::cout << " stride " << stride[k] << std::endl;
}
std
::
shared_ptr
<
operators
::
ConvOp
<
Dtype
,
float
>>
conv
=
...
...
src/framework/operator.h
浏览文件 @
0c9279af
...
...
@@ -68,6 +68,13 @@ public:
:
OperatorBase
<
Dtype
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
virtual
void
InferShape
()
const
=
0
;
void
ClearVariables
()
const
{
if
(
this
->
scope_
)
{
this
->
scope_
->
EraseVars
(
this
->
inputs_
.
at
(
"Filter"
));
this
->
scope_
->
EraseVars
(
this
->
inputs_
.
at
(
"Input"
));
}
}
protected:
virtual
void
RunImpl
()
const
=
0
;
...
...
src/io.cpp
浏览文件 @
0c9279af
...
...
@@ -19,6 +19,7 @@ SOFTWARE.
#include <fstream>
#include <iostream>
#include "common/log.h"
#include "framework/framework.pb.h"
#include "framework/lod_tensor.h"
#include "framework/program_desc.h"
...
...
@@ -41,25 +42,27 @@ void ReadBinaryFile(const std::string &filename, std::string *contents) {
template
<
typename
Dtype
,
Precision
P
>
void
Loader
<
Dtype
,
P
>::
LoadVar
(
framework
::
LoDTensor
*
tensor
,
const
std
::
string
&
file_path
)
{
// std::cout << " to load " << file_path << std::endl;
LOG
(
kLOG_DEBUG
)
<<
" to load "
<<
file_path
;
// Log(kLOG_DEBUG) << "123";
std
::
ifstream
is
(
file_path
);
std
::
streampos
pos
=
is
.
tellg
();
// save current position
is
.
seekg
(
0
,
std
::
ios
::
end
);
// std::cout << " file length = " << is.tellg() << std::endl
;
LOG
(
kLOG_DEBUG
)
<<
" file length = "
<<
is
.
tellg
()
;
is
.
seekg
(
pos
);
// restore saved position
// 1. version
uint32_t
version
;
is
.
read
(
reinterpret_cast
<
char
*>
(
&
version
),
sizeof
(
version
));
// std::cout << " version: " << version << std::endl
;
LOG
(
kLOG_INFO
)
<<
" version: "
<<
version
;
// 2 Lod information
uint64_t
lod_level
;
is
.
read
(
reinterpret_cast
<
char
*>
(
&
lod_level
),
sizeof
(
lod_level
));
// std::cout << " load level: " << lod_level << std::end
l;
// std::cout << " lod info: " << std::endl
;
LOG
(
kLOG_DEBUG
)
<<
" load level: "
<<
lod_leve
l
;
LOG
(
kLOG_DEBUG
)
<<
" lod info: "
;
auto
&
lod
=
*
tensor
->
mutable_lod
();
lod
.
resize
(
lod_level
);
for
(
uint64_t
i
=
0
;
i
<
lod_level
;
++
i
)
{
...
...
@@ -69,7 +72,7 @@ void Loader<Dtype, P>::LoadVar(framework::LoDTensor *tensor,
is
.
read
(
reinterpret_cast
<
char
*>
(
tmp
.
data
()),
static_cast
<
std
::
streamsize
>
(
size
));
for
(
int
j
=
0
;
j
<
tmp
.
size
();
++
j
)
{
// std::cout << " lod - " << tmp[j] << std::endl
;
LOG
(
kLOG_DEBUG1
)
<<
" lod - "
<<
tmp
[
j
]
;
}
lod
[
i
]
=
tmp
;
}
...
...
src/operators/conv_op.h
浏览文件 @
0c9279af
...
...
@@ -43,6 +43,7 @@ protected:
void
RunImpl
()
const
{
operators
::
ConvKernel
<
DeviceType
,
T
,
ConvParam
>
kernel
;
kernel
.
Compute
(
param_
);
this
->
ClearVariables
();
}
ConvParam
param_
;
...
...
src/operators/kernel/arm/conv_kernel.cpp
浏览文件 @
0c9279af
...
...
@@ -38,7 +38,7 @@ template <>
void
ConvKernel
<
CPU
,
float
,
ConvParam
>::
Compute
(
const
ConvParam
&
param
)
const
{
const
Tensor
*
input
=
param
.
Input
();
std
::
cout
<<
" conv param "
<<
param
<<
std
::
endl
;
LOG
(
kLOG_DEBUG
)
<<
param
;
// The filter will be reshaped in the calculations,
// so here use an assignment operation,
...
...
@@ -53,7 +53,7 @@ void ConvKernel<CPU, float, ConvParam>::Compute(const ConvParam ¶m) const {
std
::
vector
<
int
>
paddings
=
param
.
Paddings
();
std
::
vector
<
int
>
dilations
=
param
.
Dilations
();
std
::
cout
<<
" compute end get Attrs "
<<
strides
[
0
]
<<
std
::
endl
;
DLOG
<<
" compute end get Attrs "
<<
strides
[
0
]
;
const
int
batch_size
=
static_cast
<
int
>
(
input
->
dims
()[
0
]);
...
...
@@ -99,9 +99,9 @@ void ConvKernel<CPU, float, ConvParam>::Compute(const ConvParam ¶m) const {
filter
.
numel
()
/
filter
.
dims
()[
0
]};
filter
.
Resize
(
filter_matrix_shape
);
std
::
cout
<<
" input dim "
<<
input
->
dims
()
<<
std
::
endl
;
DLOG
<<
" input dim "
<<
input
->
dims
()
;
std
::
cout
<<
" output dim "
<<
output
->
dims
()
<<
std
::
endl
;
DLOG
<<
" output dim "
<<
output
->
dims
()
;
framework
::
DDim
output_matrix_shape
=
{
output
->
dims
()[
1
],
...
...
src/operators/op_param.cpp
浏览文件 @
0c9279af
...
...
@@ -21,22 +21,25 @@ SOFTWARE.
namespace
paddle_mobile
{
namespace
operators
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ConvParam
&
conv_param
)
{
os
<<
"parameter of conv: "
<<
std
::
endl
;
os
<<
" stride: "
<<
" ("
<<
conv_param
.
Strides
()[
0
]
<<
conv_param
.
Strides
()[
1
]
<<
") "
<<
std
::
endl
;
os
<<
" paddings: "
<<
" ("
<<
conv_param
.
Paddings
()[
0
]
<<
conv_param
.
Paddings
()[
1
]
<<
") "
<<
std
::
endl
;
os
<<
" dilations: "
<<
" ("
<<
conv_param
.
Dilations
()[
0
]
<<
conv_param
.
Dilations
()[
1
]
<<
") "
<<
std
::
endl
;
os
<<
" groups: "
<<
conv_param
.
Groups
()
<<
std
::
endl
;
os
<<
" input dims: "
<<
conv_param
.
Input
()
->
dims
()
<<
std
::
endl
;
os
<<
" filter dims: "
<<
conv_param
.
Filter
()
->
dims
()
<<
std
::
endl
;
os
<<
" output dims: "
<<
conv_param
.
Output
()
->
dims
()
<<
std
::
endl
;
return
os
;
Print
&
operator
<<
(
Print
&
printer
,
const
ConvParam
&
conv_param
)
{
printer
<<
"parameter of conv: "
<<
"
\n
"
;
printer
<<
" stride: "
<<
" ("
<<
conv_param
.
Strides
()[
0
]
<<
conv_param
.
Strides
()[
1
]
<<
") "
<<
"
\n
"
;
printer
<<
" paddings: "
<<
" ("
<<
conv_param
.
Paddings
()[
0
]
<<
conv_param
.
Paddings
()[
1
]
<<
") "
<<
"
\n
"
;
printer
<<
" dilations: "
<<
" ("
<<
conv_param
.
Dilations
()[
0
]
<<
conv_param
.
Dilations
()[
1
]
<<
") "
<<
"
\n
"
;
printer
<<
" groups: "
<<
conv_param
.
Groups
()
<<
"
\n
"
;
printer
<<
" input dims: "
<<
conv_param
.
Input
()
->
dims
()
<<
"
\n
"
;
printer
<<
" filter dims: "
<<
conv_param
.
Filter
()
->
dims
()
<<
"
\n
"
;
printer
<<
" output dims: "
<<
conv_param
.
Output
()
->
dims
();
return
printer
;
}
}
// namespace operators
...
...
src/operators/op_param.h
浏览文件 @
0c9279af
...
...
@@ -18,6 +18,7 @@ SOFTWARE.
#pragma once;
#include "common/log.h"
#include "common/type_define.h"
#include "framework/lod_tensor.h"
#include "framework/scope.h"
...
...
@@ -104,7 +105,7 @@ private:
int
groups
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ConvParam
&
conv_param
);
Print
&
operator
<<
(
Print
&
printer
,
const
ConvParam
&
conv_param
);
}
// namespace operators
}
// namespace paddle_mobile
test/main.cpp
浏览文件 @
0c9279af
...
...
@@ -49,6 +49,7 @@ int main() {
// }
paddle_mobile
::
Loader
<
paddle_mobile
::
CPU
>
loader
;
//../../test/models/image_classification_resnet.inference.model
auto
program
=
loader
.
Load
(
std
::
string
(
"../../test/models/image_classification_resnet.inference.model"
));
...
...
test/unit-test/test_log.cpp
0 → 100644
浏览文件 @
0c9279af
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
==============================================================================*/
#include "common/log.h"
int
main
()
{
LOG
(
paddle_mobile
::
kLOG_DEBUG
)
<<
"test debug"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
"test debug1"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG2
)
<<
"test debug2"
<<
" next log"
;
DLOG
<<
"test DLOG"
;
LOG
(
paddle_mobile
::
kLOG_ERROR
)
<<
" error occur !"
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录