Skip to content

Commit

Permalink
Revert "Revert the updated bitpack"
Browse files Browse the repository at this point in the history
This reverts commit f20f159.
  • Loading branch information
daquexian committed Aug 20, 2019
1 parent ddf6a6f commit 0cbd770
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tools/onnx2bnn/OnnxConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,23 @@ OnnxConverter::BTensor OnnxConverter::bitpack(OnnxConverter::FTensor ftensor) {
static_assert(std::is_same<bin_t, uint64_t>::value,
"bitpack requires bin_t is 64 bit");

auto c = Shaper::kc(ftensor.shape);

BNN_ASSERT(c % 64 == 0, ftensor.shape);
const auto N = Shaper::kn(ftensor.shape);
const auto HWC = Shaper::total(ftensor.shape) / N;

vector<bin_t> packed_data;
bin_t tmp;

FORZS(i, Shaper::total(ftensor.shape), 64) {
pack_64_bitset(&ftensor.data[i], &tmp);
packed_data.push_back(tmp);
FORZ(n, N) {
FORZS(i, HWC, 128) {
const size_t eff_bits = std::max<size_t>(HWC - i, 128);
pack_64_bitset(&ftensor.data[n * HWC + i], &tmp,
std::min<size_t>(eff_bits, 64));
packed_data.push_back(tmp);
pack_64_bitset(
&ftensor.data[n * HWC + i + 64], &tmp,
std::min<size_t>(std::max<size_t>(0, eff_bits - 64), 64));
packed_data.push_back(tmp);
}
}

Shape shape = {ftensor.shape[0], ftensor.shape[1], ftensor.shape[2],
Expand Down

0 comments on commit 0cbd770

Please sign in to comment.