Skip to content

Commit

Permalink
Port sort fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinxc committed Dec 1, 2023
1 parent ef086fe commit e08ae39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions libspu/kernel/hal/permute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ std::vector<spu::Value> BitonicSort(SPUContext *ctx,
// make a copy for inplace sort
std::vector<spu::Value> ret;
for (auto const &input : inputs) {
ret.emplace_back(input.clone());
if (input.isPublic()) {
// we can not linear_scatter a secret value to a public operand
ret.emplace_back(_p2s(ctx, input).setDtype(input.dtype()));
} else {
ret.emplace_back(input.clone());
}
}

// sort by per network layer for memory optimizations, sorting N elements
Expand Down Expand Up @@ -515,7 +520,7 @@ std::vector<spu::Value> sort1d(SPUContext *ctx,
for (const auto &input : inputs) {
ret.push_back(Permute1D(ctx, input, indices_to_sort));
}
} else {
} else if (comparator_ret_vis == VIS_SECRET) {
SPU_ENFORCE(!is_stable,
"Stable sort is unsupported if comparator return is secret.");

Expand Down Expand Up @@ -591,7 +596,12 @@ std::vector<spu::Value> simple_sort1d(SPUContext *ctx,
return result;
};

auto ret = sort1d(ctx, inputs, comp_fn, inputs[0].vtype(), false);
Visibility vis =
std::all_of(inputs.begin(), inputs.begin() + num_keys,
[](const spu::Value &v) { return v.isPublic(); })
? VIS_PUBLIC
: VIS_SECRET;
auto ret = sort1d(ctx, inputs, comp_fn, vis, false);
return ret;
}
}
Expand Down
8 changes: 4 additions & 4 deletions libspu/mpc/cheetah/yacl_ot/yacl_ote_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ void YaclFerretOTeAdapter::Bootstrap() {
yacl::AlignedVector<uint128_t> send_ot(ot_buff_.begin(),
ot_buff_.begin() + reserve_num_);
auto send_ot_store = yc::MakeCompactOtSendStore(std::move(send_ot), Delta);
yc::FerretOtExtSend_Cheetah(ctx_, send_ot_store, lpn_param_, lpn_param_.n,
yc::FerretOtExtSend_cheetah(ctx_, send_ot_store, lpn_param_, lpn_param_.n,
absl::MakeSpan(ot_buff_.data(), lpn_param_.n));
} else {
yacl::AlignedVector<uint128_t> recv_ot(ot_buff_.begin(),
ot_buff_.begin() + reserve_num_);
auto recv_ot_store = yc::MakeCompactOtRecvStore(std::move(recv_ot));
yc::FerretOtExtRecv_Cheetah(ctx_, recv_ot_store, lpn_param_, lpn_param_.n,
yc::FerretOtExtRecv_cheetah(ctx_, recv_ot_store, lpn_param_, lpn_param_.n,
absl::MakeSpan(ot_buff_.data(), lpn_param_.n));
}
auto end = std::chrono::high_resolution_clock::now();
Expand All @@ -244,11 +244,11 @@ void YaclFerretOTeAdapter::BootstrapInplace(absl::Span<uint128_t> ot,
auto begin = std::chrono::high_resolution_clock::now();
if (is_sender_) {
auto send_ot_store = yc::MakeCompactOtSendStore(std::move(ot_tmp), Delta);
yc::FerretOtExtSend_Cheetah(ctx_, send_ot_store, lpn_param_, lpn_param_.n,
yc::FerretOtExtSend_cheetah(ctx_, send_ot_store, lpn_param_, lpn_param_.n,
data);
} else {
auto recv_ot_store = yc::MakeCompactOtRecvStore(std::move(ot_tmp));
yc::FerretOtExtRecv_Cheetah(ctx_, recv_ot_store, lpn_param_, lpn_param_.n,
yc::FerretOtExtRecv_cheetah(ctx_, recv_ot_store, lpn_param_, lpn_param_.n,
data);
}
auto end = std::chrono::high_resolution_clock::now();
Expand Down

0 comments on commit e08ae39

Please sign in to comment.