Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5d7a4caa
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
提交
5d7a4caa
编写于
5月 17, 2018
作者:
R
Ruilong Liu
提交者:
GitHub
5月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #184 from codeWorm2015/develop
fix
#183
git log printer
上级
dc349ae9
2def7a15
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
223 addition
and
52 deletion
+223
-52
CMakeLists.txt
CMakeLists.txt
+4
-0
src/common/log.h
src/common/log.h
+154
-0
src/framework/executor.cpp
src/framework/executor.cpp
+0
-18
src/framework/operator.h
src/framework/operator.h
+0
-1
src/io.cpp
src/io.cpp
+9
-6
src/operators/kernel/arm/conv_kernel.cpp
src/operators/kernel/arm/conv_kernel.cpp
+3
-7
src/operators/op_param.cpp
src/operators/op_param.cpp
+20
-19
src/operators/op_param.h
src/operators/op_param.h
+2
-1
test/unit-test/test_log.cpp
test/unit-test/test_log.cpp
+31
-0
未找到文件。
CMakeLists.txt
浏览文件 @
5d7a4caa
...
...
@@ -50,3 +50,7 @@ ADD_EXECUTABLE(paddle-mobile-test test/main.cpp test/test_helper.h
test/elementwise_add_op_test.h test/test_include.h
test/mul_op_test.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
浏览文件 @
5d7a4caa
/* 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
浏览文件 @
5d7a4caa
...
...
@@ -35,36 +35,18 @@ namespace paddle_mobile {
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
=
std
::
make_shared
<
operators
::
ConvOp
<
Dtype
,
float
>>
(
op
->
Type
(),
op
->
GetInputs
(),
op
->
GetOutputs
(),
...
...
src/framework/operator.h
浏览文件 @
5d7a4caa
...
...
@@ -75,7 +75,6 @@ namespace paddle_mobile {
std
::
shared_ptr
<
Scope
>
scope
)
:
OperatorBase
<
Dtype
>
(
type
,
inputs
,
outputs
,
attrs
,
scope
)
{}
virtual
void
InferShape
()
const
=
0
;
virtual
void
Run
()
const
=
0
;
};
...
...
src/io.cpp
浏览文件 @
5d7a4caa
...
...
@@ -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 @@ namespace paddle_mobile {
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 @@ namespace paddle_mobile {
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/kernel/arm/conv_kernel.cpp
浏览文件 @
5d7a4caa
...
...
@@ -40,9 +40,9 @@ namespace paddle_mobile {
template
<
>
void
ConvKernel
<
CPU
,
float
,
ConvParam
>::
Compute
(
const
ConvParam
&
param
)
const
{
const
Tensor
*
input
=
param
.
Input
()
;
LOG
(
kLOG_DEBUG
)
<<
param
;
std
::
cout
<<
" conv param "
<<
param
<<
std
::
endl
;
const
Tensor
*
input
=
param
.
Input
()
;
// The filter will be reshaped in the calculations,
// so here use an assignment operation,
...
...
@@ -57,7 +57,7 @@ namespace paddle_mobile {
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
]);
...
...
@@ -110,10 +110,6 @@ namespace paddle_mobile {
filter
.
dims
()[
0
],
filter
.
numel
()
/
filter
.
dims
()[
0
]};
filter
.
Resize
(
filter_matrix_shape
);
std
::
cout
<<
" input dim "
<<
input
->
dims
()
<<
std
::
endl
;
std
::
cout
<<
" output dim "
<<
output
->
dims
()
<<
std
::
endl
;
framework
::
DDim
output_matrix_shape
=
{
output
->
dims
()[
1
],
output
->
numel
()
/
(
output
->
dims
()[
0
]
*
output
->
dims
()[
1
])};
...
...
src/operators/op_param.cpp
浏览文件 @
5d7a4caa
...
...
@@ -20,25 +20,26 @@ 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
}
// namespace paddle_mobile
src/operators/op_param.h
浏览文件 @
5d7a4caa
...
...
@@ -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"
...
...
@@ -148,7 +149,7 @@ namespace paddle_mobile {
int
groups
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ConvParam
&
conv_param
);
Print
&
operator
<<
(
Print
&
printer
,
const
ConvParam
&
conv_param
);
class
ElementwiseAddParam
:
OpParam
{
public:
...
...
test/unit-test/test_log.cpp
0 → 100644
浏览文件 @
5d7a4caa
/* 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录