Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
194ce2e9
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
194ce2e9
编写于
12月 12, 2018
作者:
T
tensor-tang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add benchmark
上级
d538513f
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
158 addition
and
14 deletion
+158
-14
paddle/fluid/operators/jit/CMakeLists.txt
paddle/fluid/operators/jit/CMakeLists.txt
+2
-1
paddle/fluid/operators/jit/benchmark.cc
paddle/fluid/operators/jit/benchmark.cc
+152
-0
paddle/fluid/operators/jit/gen/jitcode.h
paddle/fluid/operators/jit/gen/jitcode.h
+0
-4
paddle/fluid/operators/jit/helper.h
paddle/fluid/operators/jit/helper.h
+4
-0
paddle/fluid/operators/jit/test.cc
paddle/fluid/operators/jit/test.cc
+0
-9
未找到文件。
paddle/fluid/operators/jit/CMakeLists.txt
浏览文件 @
194ce2e9
...
...
@@ -8,7 +8,7 @@ file(APPEND ${jit_file} "\#include \"paddle/fluid/operators/jit/registry.h\"\n\n
set
(
JIT_KERNEL_DEPS cpu_info cblas gflags enforce place
)
file
(
GLOB jit_kernel_cc_srcs RELATIVE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
"
"*.cc"
)
list
(
REMOVE_ITEM jit_kernel_cc_srcs test.cc
)
list
(
REMOVE_ITEM jit_kernel_cc_srcs test.cc
benchmark.cc
)
cc_library
(
jit_kernel_base SRCS
${
jit_kernel_cc_srcs
}
DEPS
${
JIT_KERNEL_DEPS
}
)
# refer must go first
...
...
@@ -20,3 +20,4 @@ endif()
cc_library
(
jit_kernel_helper SRCS
${
jit_kernel_cc_srcs
}
DEPS
${
JIT_KERNEL_DEPS
}
)
cc_test
(
jit_kernel_test SRCS test.cc DEPS jit_kernel_helper
)
cc_binary
(
jit_kernel_benchmark SRCS benchmark.cc DEPS jit_kernel_helper
)
paddle/fluid/operators/jit/benchmark.cc
0 → 100644
浏览文件 @
194ce2e9
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
// #include <cstring> // for memcpy
// #include <random>
#include <iostream>
#include <string>
#include <vector>
#include "gflags/gflags.h"
#include "glog/logging.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/port.h"
DEFINE_int32
(
burning
,
10
,
"Burning times."
);
DEFINE_int32
(
repeat
,
3000
,
"Repeat times."
);
DEFINE_int32
(
max_size
,
1000
,
"The Max size would be tested."
);
inline
double
GetCurrentUS
()
{
struct
timeval
time
;
gettimeofday
(
&
time
,
NULL
);
return
1e+6
*
time
.
tv_sec
+
time
.
tv_usec
;
}
template
<
typename
T
>
void
RandomVec
(
const
int
n
,
T
*
a
,
const
T
lower
=
static_cast
<
T
>
(
-
20.
f
),
const
T
upper
=
static_cast
<
T
>
(
20.
f
))
{
static
unsigned
int
seed
=
100
;
std
::
mt19937
rng
(
seed
++
);
std
::
uniform_real_distribution
<
double
>
uniform_dist
(
0
,
1
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
a
[
i
]
=
static_cast
<
T
>
(
uniform_dist
(
rng
)
*
(
upper
-
lower
)
+
lower
);
}
}
std
::
vector
<
int
>
TestSizes
()
{
std
::
vector
<
int
>
s
;
for
(
int
i
=
1
;
i
<=
FLAGS_max_size
;
++
i
)
{
s
.
push_back
(
i
);
}
return
s
;
}
// return this function avg time
template
<
typename
T
,
typename
Func
>
double
BenchTartgetFunc
(
const
Func
tgt
,
const
std
::
vector
<
T
>&
x
,
const
std
::
vector
<
T
>&
y
,
std
::
vector
<
T
>&
z
)
{
// NOLINT
const
T
*
x_data
=
x
.
data
();
const
T
*
y_data
=
y
.
data
();
const
int
d
=
z
.
size
();
T
*
z_data
=
z
.
data
();
for
(
int
i
=
0
;
i
<
FLAGS_burning
;
++
i
)
{
tgt
(
x_data
,
y_data
,
z_data
,
d
);
}
auto
start
=
GetCurrentUS
();
for
(
int
i
=
0
;
i
<
FLAGS_repeat
;
++
i
)
{
tgt
(
x_data
,
y_data
,
z_data
,
d
);
}
auto
end
=
GetCurrentUS
();
return
(
end
-
start
)
/
FLAGS_repeat
;
}
// Benchmark all jit kernels including jitcode, mkl and refer.
// To use this tool, run command: ./benchmark [options...]
// Options:
// --burning: the burning time before count
// --repeat: the repeat times
// --max_size: the max size would be tested
int
main
(
int
argc
,
char
*
argv
[])
{
gflags
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
google
::
InitGoogleLogging
(
argv
[
0
]);
using
T
=
float
;
using
PlaceType
=
paddle
::
platform
::
CPUPlace
;
namespace
jit
=
paddle
::
operators
::
jit
;
const
auto
KT
=
jit
::
vmul
;
LOG
(
INFO
)
<<
"Burning "
<<
FLAGS_burning
<<
" times, Repeat "
<<
FLAGS_repeat
<<
" times."
;
for
(
int
d
:
TestSizes
())
{
// for (kernels type) { // TODO(TJ): more jit::KernelType
std
::
vector
<
std
::
pair
<
std
::
string
,
double
>>
infos
;
std
::
vector
<
T
>
x
(
d
),
y
(
d
),
z
(
d
);
RandomVec
<
T
>
(
d
,
x
.
data
());
RandomVec
<
T
>
(
d
,
y
.
data
());
// refer
auto
refer
=
jit
::
GetRefer
<
KT
,
T
,
jit
::
VMulTuples
<
T
>::
func_type
,
jit
::
VMulTuples
<
T
>::
attr_type
>
();
if
(
refer
)
{
auto
res
=
BenchTartgetFunc
<
T
,
jit
::
VMulTuples
<
T
>::
func_type
>
(
refer
,
x
,
y
,
z
);
infos
.
push_back
(
std
::
make_pair
(
"Refer"
,
res
));
}
// test jitcode
auto
jitcode
=
jit
::
GetJitCode
<
KT
,
T
,
jit
::
VMulTuples
<
T
>::
func_type
,
jit
::
VMulTuples
<
T
>::
attr_type
,
PlaceType
>
(
d
);
if
(
jitcode
)
{
auto
res
=
BenchTartgetFunc
<
T
,
jit
::
VMulTuples
<
T
>::
func_type
>
(
jitcode
,
x
,
y
,
z
);
infos
.
push_back
(
std
::
make_pair
(
"JitCode"
,
res
));
}
// test all impls in more
jit
::
KernelKey
kkey
(
KT
,
PlaceType
());
auto
&
pool
=
jit
::
KernelPool
().
Instance
().
AllKernels
();
auto
iter
=
pool
.
find
(
kkey
);
if
(
iter
!=
pool
.
end
())
{
auto
&
impls
=
iter
->
second
;
for
(
auto
&
impl
:
impls
)
{
auto
i
=
dynamic_cast
<
const
jit
::
KernelImpl
<
T
,
jit
::
VMulTuples
<
T
>::
func_type
,
jit
::
VMulTuples
<
T
>::
attr_type
>*>
(
impl
.
get
());
if
(
i
&&
i
->
UseMe
(
d
))
{
auto
more
=
i
->
GetFunc
();
auto
res
=
BenchTartgetFunc
<
T
,
jit
::
VMulTuples
<
T
>::
func_type
>
(
more
,
x
,
y
,
z
);
infos
.
push_back
(
std
::
make_pair
(
"More"
,
res
));
}
}
}
// Test result from Get function
auto
tgt
=
jit
::
Get
<
KT
,
T
,
jit
::
VMulTuples
<
T
>::
func_type
,
jit
::
VMulTuples
<
T
>::
attr_type
,
PlaceType
>
(
d
);
if
(
!
tgt
)
{
LOG
(
ERROR
)
<<
"Target can not be empty!"
;
}
auto
res
=
BenchTartgetFunc
<
T
,
jit
::
VMulTuples
<
T
>::
func_type
>
(
tgt
,
x
,
y
,
z
);
infos
.
push_back
(
std
::
make_pair
(
"Target"
,
res
));
// print
std
::
ostringstream
loginfos
;
loginfos
<<
"Kernel Type: "
<<
KT
<<
", size "
<<
d
<<
": "
;
for
(
auto
pair
:
infos
)
{
loginfos
<<
pair
.
first
<<
" takes "
<<
pair
.
second
<<
" us; "
;
}
LOG
(
INFO
)
<<
loginfos
.
str
();
// }
}
}
paddle/fluid/operators/jit/gen/jitcode.h
浏览文件 @
194ce2e9
...
...
@@ -60,10 +60,6 @@ typedef enum {
#define YMM_FLOAT_BLOCK 8
#define ZMM_FLOAT_BLOCK 16
#define SIGMOID_THRESHOLD_MIN -40.0
#define SIGMOID_THRESHOLD_MAX 13.0
#define EXP_MAX_INPUT 40.0
#define DECLARE_JIT_CODE(codename) \
const char* name() const override { return #codename; }
...
...
paddle/fluid/operators/jit/helper.h
浏览文件 @
194ce2e9
...
...
@@ -28,6 +28,10 @@ namespace paddle {
namespace
operators
{
namespace
jit
{
#define SIGMOID_THRESHOLD_MIN -40.0
#define SIGMOID_THRESHOLD_MAX 13.0
#define EXP_MAX_INPUT 40.0
template
<
KernelType
KT
,
typename
T
,
typename
Func
,
typename
Attr
,
typename
PlaceType
>
inline
Func
GetJitCode
(
Attr
attr
)
{
...
...
paddle/fluid/operators/jit/test.cc
浏览文件 @
194ce2e9
...
...
@@ -21,15 +21,6 @@
#include "gtest/gtest.h"
#include "paddle/fluid/operators/jit/kernels.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/port.h"
constexpr
int
repeat
=
20000
;
inline
double
GetCurrentUS
()
{
struct
timeval
time
;
gettimeofday
(
&
time
,
NULL
);
return
1e+6
*
time
.
tv_sec
+
time
.
tv_usec
;
}
template
<
typename
T
>
void
RandomVec
(
const
int
n
,
T
*
a
,
const
T
lower
=
static_cast
<
T
>
(
-
20.
f
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录