Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
917c9cc6
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
917c9cc6
编写于
12月 09, 2016
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change interface and comments in Cpuid.cpp
上级
cb9ebeda
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
65 addition
and
53 deletion
+65
-53
paddle/utils/CpuId.cpp
paddle/utils/CpuId.cpp
+5
-1
paddle/utils/CpuId.h
paddle/utils/CpuId.h
+50
-41
paddle/utils/tests/test_SIMDFlags.cpp
paddle/utils/tests/test_SIMDFlags.cpp
+10
-11
未找到文件。
paddle/utils/CpuId.cpp
浏览文件 @
917c9cc6
...
@@ -51,7 +51,11 @@ SIMDFlags::SIMDFlags() {
...
@@ -51,7 +51,11 @@ SIMDFlags::SIMDFlags() {
simd_flags_
|=
cpuInfo
[
2
]
&
(
1
<<
16
)
?
SIMD_FMA4
:
SIMD_NONE
;
simd_flags_
|=
cpuInfo
[
2
]
&
(
1
<<
16
)
?
SIMD_FMA4
:
SIMD_NONE
;
}
}
const
SIMDFlags
*
SIMDFlags
::
instance
()
{
bool
SIMDFlags
::
check
(
int
flags
)
const
{
return
(
simd_flags_
&
flags
)
==
flags
;
}
SIMDFlags
const
*
SIMDFlags
::
instance
()
{
static
SIMDFlags
instance
;
static
SIMDFlags
instance
;
return
&
instance
;
return
&
instance
;
}
}
...
...
paddle/utils/CpuId.h
浏览文件 @
917c9cc6
...
@@ -15,28 +15,7 @@ limitations under the License. */
...
@@ -15,28 +15,7 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
class
SIMDFlags
final
{
enum
simd_t
{
public:
DISABLE_COPY
(
SIMDFlags
);
SIMDFlags
();
static
const
SIMDFlags
*
instance
();
inline
bool
isSSE
()
const
{
return
simd_flags_
&
SIMD_SSE
;
}
inline
bool
isSSE2
()
const
{
return
simd_flags_
&
SIMD_SSE2
;
}
inline
bool
isSSE3
()
const
{
return
simd_flags_
&
SIMD_SSE3
;
}
inline
bool
isSSSE3
()
const
{
return
simd_flags_
&
SIMD_SSSE3
;
}
inline
bool
isSSE41
()
const
{
return
simd_flags_
&
SIMD_SSE41
;
}
inline
bool
isSSE42
()
const
{
return
simd_flags_
&
SIMD_SSE42
;
}
inline
bool
isFMA3
()
const
{
return
simd_flags_
&
SIMD_FMA3
;
}
inline
bool
isFMA4
()
const
{
return
simd_flags_
&
SIMD_FMA4
;
}
inline
bool
isAVX
()
const
{
return
simd_flags_
&
SIMD_AVX
;
}
inline
bool
isAVX2
()
const
{
return
simd_flags_
&
SIMD_AVX2
;
}
inline
bool
isAVX512
()
const
{
return
simd_flags_
&
SIMD_AVX512
;}
private:
enum
simd_t
{
SIMD_NONE
=
0
,
///< None
SIMD_NONE
=
0
,
///< None
SIMD_SSE
=
1
<<
0
,
///< SSE
SIMD_SSE
=
1
<<
0
,
///< SSE
SIMD_SSE2
=
1
<<
1
,
///< SSE 2
SIMD_SSE2
=
1
<<
1
,
///< SSE 2
...
@@ -49,22 +28,52 @@ private:
...
@@ -49,22 +28,52 @@ private:
SIMD_AVX
=
1
<<
8
,
///< AVX
SIMD_AVX
=
1
<<
8
,
///< AVX
SIMD_AVX2
=
1
<<
9
,
///< AVX 2
SIMD_AVX2
=
1
<<
9
,
///< AVX 2
SIMD_AVX512
=
1
<<
10
,
///< AVX 512
SIMD_AVX512
=
1
<<
10
,
///< AVX 512
};
};
/// simd flags
class
SIMDFlags
final
{
public:
DISABLE_COPY
(
SIMDFlags
);
SIMDFlags
();
static
SIMDFlags
const
*
instance
();
bool
check
(
int
flags
)
const
;
private:
int
simd_flags_
=
SIMD_NONE
;
int
simd_flags_
=
SIMD_NONE
;
};
};
#define HAS_SSE SIMDFlags::instance()->isSSE()
/**
#define HAS_SSE2 SIMDFlags::instance()->isSSE2()
* @brief Check SIMD flags at runtime.
#define HAS_SSE3 SIMDFlags::instance()->isSSE3()
*
#define HAS_SSSE3 SIMDFlags::instance()->isSSSE3()
* For example.
#define HAS_SSE41 SIMDFlags::instance()->isSSE41()
* @code{.cpp}
#define HAS_SSE42 SIMDFlags::instance()->isSSE42()
*
#define HAS_FMA3 SIMDFlags::instance()->isFMA3()
* if (HAS_SIMD(SIMD_AVX2 | SIMD_FMA4)) {
#define HAS_FMA4 SIMDFlags::instance()->isFMA4()
* avx2_fm4_stub();
#define HAS_AVX SIMDFlags::instance()->isAVX()
* } else if (HAS_SIMD(SIMD_AVX)) {
#define HAS_AVX2 SIMDFlags::instance()->isAVX2()
* avx_stub();
#define HAS_AVX512 SIMDFlags::instance()->isAVX512()
* }
*
* @endcode
*/
#define HAS_SIMD(__flags) SIMDFlags::instance()->check(__flags)
/**
* @brief Check SIMD flags at runtime.
*
* 1. Check all SIMD flags at runtime: HAS_SSE && HAS_SSE2 && HAS_SSE3
* 2. Check one SIMD flags at runtime: HAS_SSE || HAS_SSE2 || HAS_SSE3
*/
#define HAS_SSE HAS_SIMD(SIMD_SSE)
#define HAS_SSE2 HAS_SIMD(SIMD_SSE2)
#define HAS_SSE3 HAS_SIMD(SIMD_SSE3)
#define HAS_SSSE3 HAS_SIMD(SIMD_SSSE3)
#define HAS_SSE41 HAS_SIMD(SIMD_SSE41)
#define HAS_SSE42 HAS_SIMD(SIMD_SSE42)
#define HAS_FMA3 HAS_SIMD(SIMD_FMA3)
#define HAS_FMA4 HAS_SIMD(SIMD_FMA4)
#define HAS_AVX HAS_SIMD(SIMD_AVX)
#define HAS_AVX2 HAS_SIMD(SIMD_AVX2)
#define HAS_AVX512 HAS_SIMD(SIMD_AVX512)
}
// namespace paddle
}
// namespace paddle
paddle/utils/tests/test_SIMDFlags.cpp
浏览文件 @
917c9cc6
...
@@ -32,17 +32,16 @@ TEST(SIMDFlags, gccTest) {
...
@@ -32,17 +32,16 @@ TEST(SIMDFlags, gccTest) {
}
}
TEST
(
SIMDFlags
,
normalPrint
)
{
TEST
(
SIMDFlags
,
normalPrint
)
{
auto
simd
=
SIMDFlags
::
instance
();
LOG
(
INFO
)
<<
"Has SSE: "
<<
std
::
boolalpha
<<
HAS_SSE
;
LOG
(
INFO
)
<<
"Has SSE2: "
<<
std
::
boolalpha
<<
simd
->
isSSE2
();
LOG
(
INFO
)
<<
"Has SSE2: "
<<
std
::
boolalpha
<<
HAS_SSE2
;
LOG
(
INFO
)
<<
"Has SSE3: "
<<
std
::
boolalpha
<<
simd
->
isSSE3
();
LOG
(
INFO
)
<<
"Has SSE3: "
<<
std
::
boolalpha
<<
HAS_SSE3
;
LOG
(
INFO
)
<<
"Has SSSE3: "
<<
std
::
boolalpha
<<
simd
->
isSSSE3
();
LOG
(
INFO
)
<<
"Has SSSE3: "
<<
std
::
boolalpha
<<
HAS_SSSE3
;
LOG
(
INFO
)
<<
"Has SSE4.1: "
<<
std
::
boolalpha
<<
simd
->
isSSE41
();
LOG
(
INFO
)
<<
"Has SSE4: "
<<
std
::
boolalpha
<<
HAS_SSE41
||
HAS_SSE42
;
LOG
(
INFO
)
<<
"Has SSE4.2: "
<<
std
::
boolalpha
<<
simd
->
isSSE42
();
LOG
(
INFO
)
<<
"Has FMA3: "
<<
std
::
boolalpha
<<
HAS_FMA3
;
LOG
(
INFO
)
<<
"Has FMA3: "
<<
std
::
boolalpha
<<
simd
->
isFMA3
();
LOG
(
INFO
)
<<
"Has FMA4: "
<<
std
::
boolalpha
<<
HAS_FMA4
;
LOG
(
INFO
)
<<
"Has FMA4: "
<<
std
::
boolalpha
<<
simd
->
isFMA4
();
LOG
(
INFO
)
<<
"Has AVX: "
<<
std
::
boolalpha
<<
HAS_AVX
;
LOG
(
INFO
)
<<
"Has AVX: "
<<
std
::
boolalpha
<<
simd
->
isAVX
();
LOG
(
INFO
)
<<
"Has AVX2: "
<<
std
::
boolalpha
<<
HAS_AVX2
;
LOG
(
INFO
)
<<
"Has AVX2: "
<<
std
::
boolalpha
<<
simd
->
isAVX2
();
LOG
(
INFO
)
<<
"Has AVX512: "
<<
std
::
boolalpha
<<
HAS_AVX512
;
LOG
(
INFO
)
<<
"Has AVX512: "
<<
std
::
boolalpha
<<
simd
->
isAVX512
();
}
}
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录