Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
12a3cea0
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看板
提交
12a3cea0
编写于
3月 01, 2018
作者:
C
chengduo
提交者:
Abhinav Arora
2月 28, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tuple type (#8519)
* add the type of tuple * add lod_tensor to tuple
上级
d3fbede9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
141 addition
and
0 deletion
+141
-0
paddle/fluid/framework/CMakeLists.txt
paddle/fluid/framework/CMakeLists.txt
+1
-0
paddle/fluid/framework/framework.proto
paddle/fluid/framework/framework.proto
+4
-0
paddle/fluid/framework/tuple.h
paddle/fluid/framework/tuple.h
+71
-0
paddle/fluid/framework/tuple_test.cc
paddle/fluid/framework/tuple_test.cc
+65
-0
未找到文件。
paddle/fluid/framework/CMakeLists.txt
浏览文件 @
12a3cea0
...
...
@@ -96,5 +96,6 @@ cc_test(op_kernel_type_test SRCS op_kernel_type_test.cc DEPS place device_contex
cc_test
(
cow_ptr_tests SRCS details/cow_ptr_test.cc
)
cc_test
(
channel_test SRCS channel_test.cc
)
cc_test
(
tuple_test SRCS tuple_test.cc
)
cc_test
(
concurrency_test SRCS concurrency_test.cc DEPS go_op channel_close_op channel_create_op
channel_send_op channel_recv_op sum_op elementwise_add_op executor proto_desc
)
paddle/fluid/framework/framework.proto
浏览文件 @
12a3cea0
...
...
@@ -117,6 +117,7 @@ message VarType {
// raw variables should manage their own allocations
// in operators like nccl_op
RAW
=
17
;
TUPLE
=
18
;
}
required
Type
type
=
1
;
...
...
@@ -148,6 +149,9 @@ message VarType {
required
int64
capacity
=
2
;
}
optional
ChannelDesc
channel
=
6
;
message
Tuple
{
repeated
Type
element_type
=
1
;
}
optional
Tuple
tuple
=
7
;
}
message
VarDesc
{
...
...
paddle/fluid/framework/tuple.h
0 → 100644
浏览文件 @
12a3cea0
/* 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. */
#pragma once
#include <stdexcept>
#include <string>
#include <vector>
#include "paddle/fluid/framework/channel.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/var_desc.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/variant.h"
namespace
paddle
{
namespace
framework
{
typedef
boost
::
variant
<
int
,
int64_t
,
float
,
double
,
std
::
string
,
Tensor
,
LoDTensor
/*, ChannelHolder*/
>
ElementVar
;
class
Tuple
{
public:
using
ElementVars
=
std
::
vector
<
ElementVar
>
;
Tuple
(
std
::
vector
<
ElementVar
>&
var
,
std
::
vector
<
VarDesc
>&
var_desc
)
:
var_
(
var
),
var_desc_
(
var_desc
)
{}
Tuple
(
std
::
vector
<
ElementVar
>&
var
)
:
var_
(
var
)
{}
ElementVar
get
(
int
idx
)
const
{
return
var_
[
idx
];
};
ElementVar
&
get
(
int
idx
)
{
return
var_
[
idx
];
};
bool
isSameType
(
Tuple
&
t
)
const
;
size_t
getSize
()
const
{
return
var_
.
size
();
};
private:
ElementVars
var_
;
std
::
vector
<
VarDesc
>
var_desc_
;
};
bool
Tuple
::
isSameType
(
Tuple
&
t
)
const
{
size_t
tuple_size
=
getSize
();
if
(
tuple_size
!=
t
.
getSize
())
{
return
false
;
}
for
(
size_t
j
=
0
;
j
<
tuple_size
;
++
j
)
{
auto
type1
=
get
(
j
).
which
();
auto
type2
=
t
.
get
(
j
).
which
();
if
(
type1
!=
type2
)
return
false
;
}
return
true
;
}
Tuple
*
make_tuple
(
std
::
vector
<
ElementVar
>
tuple
)
{
return
new
Tuple
(
tuple
);
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/tuple_test.cc
0 → 100644
浏览文件 @
12a3cea0
/* 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 <sstream>
#include <vector>
#include "gtest/gtest.h"
#include "paddle/fluid/framework/tuple.h"
TEST
(
Tuple
,
Make
)
{
std
::
vector
<
paddle
::
framework
::
ElementVar
>
element_type
;
element_type
.
push_back
(
12
);
element_type
.
push_back
(
12.0
f
);
element_type
.
push_back
(
"ElementVar"
);
paddle
::
framework
::
Tuple
*
tuple
=
paddle
::
framework
::
make_tuple
(
element_type
);
EXPECT_EQ
(
boost
::
get
<
int
>
(
tuple
->
get
(
0
)),
12
);
EXPECT_EQ
(
boost
::
get
<
float
>
(
tuple
->
get
(
1
)),
12.0
f
);
EXPECT_EQ
(
boost
::
get
<
std
::
string
>
(
tuple
->
get
(
2
)),
"ElementVar"
);
delete
tuple
;
}
TEST
(
Tuple
,
IsTheSameType
)
{
std
::
vector
<
paddle
::
framework
::
ElementVar
>
element_type1
;
std
::
vector
<
paddle
::
framework
::
ElementVar
>
element_type2
;
std
::
vector
<
paddle
::
framework
::
ElementVar
>
element_type3
;
element_type1
.
push_back
(
12
);
element_type1
.
push_back
(
12.0
f
);
element_type1
.
push_back
(
"Tuple1"
);
element_type2
.
push_back
(
13
);
element_type2
.
push_back
(
13.0
f
);
element_type2
.
push_back
(
"Tuple2"
);
element_type3
.
push_back
(
14.0
f
);
element_type3
.
push_back
(
14
);
element_type3
.
push_back
(
"Tuple3"
);
paddle
::
framework
::
Tuple
*
tuple1
=
paddle
::
framework
::
make_tuple
(
element_type1
);
paddle
::
framework
::
Tuple
*
tuple2
=
paddle
::
framework
::
make_tuple
(
element_type2
);
paddle
::
framework
::
Tuple
*
tuple3
=
paddle
::
framework
::
make_tuple
(
element_type3
);
EXPECT_TRUE
(
tuple1
->
isSameType
(
*
tuple2
));
EXPECT_FALSE
(
tuple1
->
isSameType
(
*
tuple3
));
delete
tuple1
;
delete
tuple2
;
delete
tuple3
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录