Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
66e82b98
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
66e82b98
编写于
5月 14, 2018
作者:
Y
yuyang18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change implementation to fit sphinx model
上级
715c933d
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
26 addition
and
26 deletion
+26
-26
paddle/fluid/framework/data_type.cc
paddle/fluid/framework/data_type.cc
+26
-26
未找到文件。
paddle/fluid/framework/data_type.cc
浏览文件 @
66e82b98
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/data_type.h"
#include <stdint.h>
#include <stdint.h>
#include <mutex> // NOLINT
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_map>
...
@@ -28,20 +27,27 @@ struct DataTypeMap {
...
@@ -28,20 +27,27 @@ struct DataTypeMap {
std
::
unordered_map
<
std
::
type_index
,
size_t
>
cpp_to_size_
;
std
::
unordered_map
<
std
::
type_index
,
size_t
>
cpp_to_size_
;
};
};
static
DataTypeMap
g_data_type_map_
;
static
DataTypeMap
*
InitDataTypeMap
();
static
DataTypeMap
&
gDataTypeMap
()
{
static
DataTypeMap
*
g_data_type_map_
=
InitDataTypeMap
();
return
*
g_data_type_map_
;
}
template
<
typename
T
>
template
<
typename
T
>
static
inline
void
RegisterType
(
proto
::
VarType
::
Type
proto_type
,
static
inline
void
RegisterType
(
DataTypeMap
*
map
,
const
std
::
string
&
name
)
{
proto
::
VarType
::
Type
proto_type
,
g_data_type_map_
.
proto_to_cpp_
.
emplace
(
static_cast
<
int
>
(
proto_type
),
const
std
::
string
&
name
)
{
typeid
(
T
));
map
->
proto_to_cpp_
.
emplace
(
static_cast
<
int
>
(
proto_type
),
typeid
(
T
));
g_data_type_map_
.
cpp_to_proto_
.
emplace
(
typeid
(
T
),
proto_type
);
map
->
cpp_to_proto_
.
emplace
(
typeid
(
T
),
proto_type
);
g_data_type_map_
.
proto_to_str_
.
emplace
(
static_cast
<
int
>
(
proto_type
),
name
);
map
->
proto_to_str_
.
emplace
(
static_cast
<
int
>
(
proto_type
),
name
);
g_data_type_map_
.
cpp_to_size_
.
emplace
(
typeid
(
T
),
sizeof
(
T
));
map
->
cpp_to_size_
.
emplace
(
typeid
(
T
),
sizeof
(
T
));
}
}
static
int
RegisterAllTypes
()
{
static
DataTypeMap
*
InitDataTypeMap
()
{
#define RegType(cc_type, proto_type) RegisterType<cc_type>(proto_type, #cc_type)
auto
retv
=
new
DataTypeMap
();
#define RegType(cc_type, proto_type) \
RegisterType<cc_type>(retv, proto_type, #cc_type)
// NOTE: Add your customize type here.
// NOTE: Add your customize type here.
RegType
(
platform
::
float16
,
proto
::
VarType
::
FP16
);
RegType
(
platform
::
float16
,
proto
::
VarType
::
FP16
);
...
@@ -52,24 +58,20 @@ static int RegisterAllTypes() {
...
@@ -52,24 +58,20 @@ static int RegisterAllTypes() {
RegType
(
bool
,
proto
::
VarType
::
BOOL
);
RegType
(
bool
,
proto
::
VarType
::
BOOL
);
#undef RegType
#undef RegType
return
0
;
return
retv
;
}
}
static
std
::
once_flag
register_once_flag_
;
proto
::
VarType
::
Type
ToDataType
(
std
::
type_index
type
)
{
proto
::
VarType
::
Type
ToDataType
(
std
::
type_index
type
)
{
std
::
call_once
(
register_once_flag_
,
RegisterAllTypes
);
auto
it
=
gDataTypeMap
().
cpp_to_proto_
.
find
(
type
);
auto
it
=
g_data_type_map_
.
cpp_to_proto_
.
find
(
type
);
if
(
it
!=
gDataTypeMap
().
cpp_to_proto_
.
end
())
{
if
(
it
!=
g_data_type_map_
.
cpp_to_proto_
.
end
())
{
return
it
->
second
;
return
it
->
second
;
}
}
PADDLE_THROW
(
"Not support %s as tensor type"
,
type
.
name
());
PADDLE_THROW
(
"Not support %s as tensor type"
,
type
.
name
());
}
}
std
::
type_index
ToTypeIndex
(
proto
::
VarType
::
Type
type
)
{
std
::
type_index
ToTypeIndex
(
proto
::
VarType
::
Type
type
)
{
std
::
call_once
(
register_once_flag_
,
RegisterAllTypes
);
auto
it
=
gDataTypeMap
().
proto_to_cpp_
.
find
(
static_cast
<
int
>
(
type
));
auto
it
=
g_data_type_map_
.
proto_to_cpp_
.
find
(
static_cast
<
int
>
(
type
));
if
(
it
!=
gDataTypeMap
().
proto_to_cpp_
.
end
())
{
if
(
it
!=
g_data_type_map_
.
proto_to_cpp_
.
end
())
{
return
it
->
second
;
return
it
->
second
;
}
}
PADDLE_THROW
(
"Not support proto::VarType::Type(%d) as tensor type"
,
PADDLE_THROW
(
"Not support proto::VarType::Type(%d) as tensor type"
,
...
@@ -77,9 +79,8 @@ std::type_index ToTypeIndex(proto::VarType::Type type) {
...
@@ -77,9 +79,8 @@ std::type_index ToTypeIndex(proto::VarType::Type type) {
}
}
std
::
string
DataTypeToString
(
const
proto
::
VarType
::
Type
type
)
{
std
::
string
DataTypeToString
(
const
proto
::
VarType
::
Type
type
)
{
std
::
call_once
(
register_once_flag_
,
RegisterAllTypes
);
auto
it
=
gDataTypeMap
().
proto_to_str_
.
find
(
static_cast
<
int
>
(
type
));
auto
it
=
g_data_type_map_
.
proto_to_str_
.
find
(
static_cast
<
int
>
(
type
));
if
(
it
!=
gDataTypeMap
().
proto_to_str_
.
end
())
{
if
(
it
!=
g_data_type_map_
.
proto_to_str_
.
end
())
{
return
it
->
second
;
return
it
->
second
;
}
}
PADDLE_THROW
(
"Not support proto::VarType::Type(%d) as tensor type"
,
PADDLE_THROW
(
"Not support proto::VarType::Type(%d) as tensor type"
,
...
@@ -87,9 +88,8 @@ std::string DataTypeToString(const proto::VarType::Type type) {
...
@@ -87,9 +88,8 @@ std::string DataTypeToString(const proto::VarType::Type type) {
}
}
size_t
SizeOfType
(
std
::
type_index
type
)
{
size_t
SizeOfType
(
std
::
type_index
type
)
{
std
::
call_once
(
register_once_flag_
,
RegisterAllTypes
);
auto
it
=
gDataTypeMap
().
cpp_to_size_
.
find
(
type
);
auto
it
=
g_data_type_map_
.
cpp_to_size_
.
find
(
type
);
if
(
it
!=
gDataTypeMap
().
cpp_to_size_
.
end
())
{
if
(
it
!=
g_data_type_map_
.
cpp_to_size_
.
end
())
{
return
it
->
second
;
return
it
->
second
;
}
}
PADDLE_THROW
(
"Not support %s as tensor type"
,
type
.
name
());
PADDLE_THROW
(
"Not support %s as tensor type"
,
type
.
name
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录