Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleFL
提交
af1a66bb
P
PaddleFL
项目概览
PaddlePaddle
/
PaddleFL
通知
35
Star
5
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
6
列表
看板
标记
里程碑
合并请求
4
Wiki
3
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleFL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
6
Issue
6
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
3
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
af1a66bb
编写于
8月 27, 2020
作者:
Y
yangqingyou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add compile option for truncate3
上级
7eb82e3f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
29 addition
and
10 deletion
+29
-10
CMakeLists.txt
CMakeLists.txt
+6
-0
core/privc3/fixedpoint_tensor_imp.h
core/privc3/fixedpoint_tensor_imp.h
+21
-10
core/privc3/fixedpoint_tensor_test.cc
core/privc3/fixedpoint_tensor_test.cc
+2
-0
未找到文件。
CMakeLists.txt
浏览文件 @
af1a66bb
...
...
@@ -61,6 +61,8 @@ option(USE_AES_NI "Compile with AES NI" ON)
option
(
USE_OPENMP
"Compile with OpenMP"
ON
)
option
(
USE_ABY3_TRUNC1
"Compile with ABY3 truncate 1 algorithm"
OFF
)
########################### the project build part ###############################
message
(
STATUS
"Using paddlepaddle installation of
${
paddle_version
}
"
)
message
(
STATUS
"paddlepaddle include directory:
${
PADDLE_INCLUDE
}
"
)
...
...
@@ -84,6 +86,10 @@ if (USE_OPENMP)
find_package
(
OpenMP REQUIRED
)
endif
(
USE_OPENMP
)
if
(
USE_ABY3_TRUNC1
)
add_compile_definitions
(
USE_ABY3_TRUNC1
)
endif
(
USE_ABY3_TRUNC1
)
add_subdirectory
(
core/privc3
)
add_subdirectory
(
core/paddlefl_mpc/mpc_protocol
)
add_subdirectory
(
core/paddlefl_mpc/operators
)
...
...
core/privc3/fixedpoint_tensor_imp.h
浏览文件 @
af1a66bb
...
...
@@ -166,6 +166,7 @@ void FixedPointTensor<T, N>::mul(const FixedPointTensor<T, N>* rhs,
mul_trunc
(
this
,
rhs
,
ret
,
&
TensorAdapter
<
T
>::
mul
);
}
#ifdef USE_ABY3_TRUNC1 //use aby3 trunc1
template
<
typename
T
,
size_t
N
>
void
FixedPointTensor
<
T
,
N
>::
truncate
(
const
FixedPointTensor
<
T
,
N
>*
op
,
FixedPointTensor
<
T
,
N
>*
ret
,
...
...
@@ -208,7 +209,20 @@ void FixedPointTensor<T, N>::truncate(const FixedPointTensor<T, N>* op,
return
;
}
#else // use truncate3
// Protocol. `truncate3`
// motivation:
// truncates in aby3 may cause msb error with small probability
// the reason is that before rishft op, its masked value e.g., x' - r' may overflow in int64
// so that, in `truncate3`, we limit r' in (-2^62, 2^62) to avoid the problem.
// notice:
// when r' is contrainted in (-2^62, 2^62),
// the SD (statistical distance) of x' - r' between this
// and r' in Z_{2^64} is equal to |X| / (2^63 + |X|)
// detail protocol:
// P2 randomly generates r' \in (-2^62, 2^62), randomly generates r'_0, r_0, r_1 in Z_{2^64},
// P2 compute r'_1 = r' - r'_0, r_2 = r'/2^N - r_0 - r_1, let x2 = r_2
// P2 send r_0, r'_0 to P0, send r_1, r'_1 to P1
...
...
@@ -217,7 +231,7 @@ void FixedPointTensor<T, N>::truncate(const FixedPointTensor<T, N>* op,
// P0 set x0 = r_0
// P0, P1, P2 invoke reshare() with inputs x0, x1, x2 respectively.
template
<
typename
T
,
size_t
N
>
void
FixedPointTensor
<
T
,
N
>::
truncate
3
(
const
FixedPointTensor
<
T
,
N
>*
op
,
void
FixedPointTensor
<
T
,
N
>::
truncate
(
const
FixedPointTensor
<
T
,
N
>*
op
,
FixedPointTensor
<
T
,
N
>*
ret
,
size_t
scaling_factor
)
{
if
(
scaling_factor
==
0
)
{
...
...
@@ -232,10 +246,6 @@ void FixedPointTensor<T, N>::truncate3(const FixedPointTensor<T, N>* op,
tensor_factory
()
->
template
create
<
T
>(
op
->
shape
()));
}
// r', contraint in (-2^62, 2^62)
// notice : when r' is contrainted in (-2^62, 2^62),
// the SD (statistical distance) of x - r' between this
// and r' in Z_{2^64} is equal to |X| / (2^63 + |X|)
// according to http://yuyu.hk/files/ho2.pdf
aby3_ctx
()
->
template
gen_random_private
(
*
temp
[
0
]);
int64_t
contraint_upper
=
~
((
uint64_t
)
1
<<
62
);
int64_t
contraint_low
=
(
uint64_t
)
1
<<
62
;
...
...
@@ -307,6 +317,7 @@ void FixedPointTensor<T, N>::truncate3(const FixedPointTensor<T, N>* op,
tensor_carry_in
->
scaling_factor
()
=
N
;
ret
->
add
(
tensor_carry_in
.
get
(),
ret
);
}
#endif //USE_ABY3_TRUNC1
template
<
typename
T
,
size_t
N
>
template
<
typename
MulFunc
>
...
...
@@ -345,7 +356,7 @@ void FixedPointTensor<T, N>::mul_trunc(const FixedPointTensor<T, N>* lhs,
temp
->
copy
(
ret_no_trunc
->
_share
[
0
]);
reshare
(
temp
.
get
(),
ret_no_trunc
->
_share
[
1
]);
truncate
3
(
ret_no_trunc
.
get
(),
ret
,
N
);
truncate
(
ret_no_trunc
.
get
(),
ret
,
N
);
}
template
<
typename
T
,
size_t
N
>
...
...
@@ -360,7 +371,7 @@ void FixedPointTensor<T, N>::mul(const TensorAdapter<T>* rhs,
_share
[
0
]
->
mul
(
rhs
,
temp
->
_share
[
0
]);
_share
[
1
]
->
mul
(
rhs
,
temp
->
_share
[
1
]);
truncate
3
(
temp
.
get
(),
ret
,
rhs
->
scaling_factor
());
truncate
(
temp
.
get
(),
ret
,
rhs
->
scaling_factor
());
}
template
<
typename
T
,
size_t
N
>
...
...
@@ -404,7 +415,7 @@ void FixedPointTensor<T, N>::mat_mul(const TensorAdapter<T>* rhs,
FixedPointTensor
<
T
,
N
>*
ret
)
const
{
_share
[
0
]
->
mat_mul
(
rhs
,
ret
->
_share
[
0
]);
_share
[
1
]
->
mat_mul
(
rhs
,
ret
->
_share
[
1
]);
truncate
3
(
ret
,
ret
,
rhs
->
scaling_factor
());
truncate
(
ret
,
ret
,
rhs
->
scaling_factor
());
}
template
<
typename
T
,
size_t
N
>
...
...
@@ -831,7 +842,7 @@ void FixedPointTensor<T, N>::long_div(const FixedPointTensor<T, N>* rhs,
}
for
(
size_t
i
=
1
;
i
<=
N
;
++
i
)
{
truncate
3
(
&
abs_rhs
,
&
sub_rhs
,
i
);
truncate
(
&
abs_rhs
,
&
sub_rhs
,
i
);
abs_lhs
.
gt
(
&
sub_rhs
,
&
cmp_res
);
cmp_res
.
mul
(
&
sub_rhs
,
&
sub_rhs
);
cmp_res
.
lshift
(
N
-
i
,
&
cmp_res
);
...
...
@@ -1184,7 +1195,7 @@ void FixedPointTensor<T, N>::inverse_square_root(const FixedPointTensor* op,
std
::
shared_ptr
<
FixedPointTensor
<
T
,
N
>>
x2
=
std
::
make_shared
<
FixedPointTensor
<
T
,
N
>>
(
temp
[
2
].
get
(),
temp
[
3
].
get
());
// x2 = 0.5 * op
truncate
3
(
op
,
x2
.
get
(),
1
);
truncate
(
op
,
x2
.
get
(),
1
);
assign_to_tensor
(
y
->
mutable_share
(
0
),
(
T
)(
x0
*
pow
(
2
,
N
)));
assign_to_tensor
(
y
->
mutable_share
(
1
),
(
T
)(
x0
*
pow
(
2
,
N
)));
...
...
core/privc3/fixedpoint_tensor_test.cc
浏览文件 @
af1a66bb
...
...
@@ -1267,6 +1267,7 @@ TEST_F(FixedTensorTest, mulfixed) {
EXPECT_TRUE
(
test_fixedt_check_tensor_eq
(
out0
.
get
(),
&
result
));
}
#ifndef USE_ABY3_TRUNC1 //use aby3 trunc1
TEST_F
(
FixedTensorTest
,
mulfixed_multi_times
)
{
std
::
vector
<
size_t
>
shape
=
{
100000
,
1
};
...
...
@@ -1327,6 +1328,7 @@ TEST_F(FixedTensorTest, mulfixed_multi_times) {
EXPECT_TRUE
(
test_fixedt_check_tensor_eq
(
out1
.
get
(),
out2
.
get
()));
EXPECT_TRUE
(
test_fixedt_check_tensor_eq
(
out0
.
get
(),
&
result
));
}
#endif
TEST_F
(
FixedTensorTest
,
mulfixed_overflow
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录