summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>2019-04-15 23:44:19 (GMT)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>2019-04-15 23:44:19 (GMT)
commit83d66c0551e0ecf01316b88fc672f8155fdef939 (patch)
tree95c1d40eb39da27df1016015e6a0bfa97c988f58
parent8352c6431b910b8f630e4af0437d180559286557 (diff)
downloadnnfw-83d66c0551e0ecf01316b88fc672f8155fdef939.zip
nnfw-83d66c0551e0ecf01316b88fc672f8155fdef939.tar.gz
nnfw-83d66c0551e0ecf01316b88fc672f8155fdef939.tar.bz2
Move gemmlowp code in cker (#4998)
Move gemmlowp code in cker into cker/gemmlowp Add namespace for gemmlowp Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
-rw-r--r--libs/cker/include/cker/Utils.h9
-rw-r--r--libs/cker/include/cker/gemmlowp/FixedPoint.h (renamed from libs/cker/include/cker/FixedPoint.h)3
-rw-r--r--libs/cker/include/cker/operation/SoftMax.h16
3 files changed, 16 insertions, 12 deletions
diff --git a/libs/cker/include/cker/Utils.h b/libs/cker/include/cker/Utils.h
index af98fd8..6734239 100644
--- a/libs/cker/include/cker/Utils.h
+++ b/libs/cker/include/cker/Utils.h
@@ -21,7 +21,7 @@
#include <algorithm>
#include <cstdint>
-#include "cker/FixedPoint.h"
+#include "cker/gemmlowp/FixedPoint.h"
namespace nnfw
{
@@ -38,14 +38,15 @@ inline int32_t MultiplyByQuantizedMultiplier(int32_t x, int32_t quantized_multip
{
int left_shift = shift > 0 ? shift : 0;
int right_shift = shift > 0 ? 0 : -shift;
- return RoundingDivideByPOT(
- SaturatingRoundingDoublingHighMul(x * (1 << left_shift), quantized_multiplier), right_shift);
+ return gemmlowp::RoundingDivideByPOT(
+ gemmlowp::SaturatingRoundingDoublingHighMul(x * (1 << left_shift), quantized_multiplier),
+ right_shift);
}
inline int32_t MultiplyByQuantizedMultiplierGreaterThanOne(int32_t x, int32_t quantized_multiplier,
int left_shift)
{
- return SaturatingRoundingDoublingHighMul(x * (1 << left_shift), quantized_multiplier);
+ return gemmlowp::SaturatingRoundingDoublingHighMul(x * (1 << left_shift), quantized_multiplier);
}
inline int CountLeadingZeros(uint32_t integer_input)
diff --git a/libs/cker/include/cker/FixedPoint.h b/libs/cker/include/cker/gemmlowp/FixedPoint.h
index 653a56d..da9d25b 100644
--- a/libs/cker/include/cker/FixedPoint.h
+++ b/libs/cker/include/cker/gemmlowp/FixedPoint.h
@@ -25,6 +25,8 @@ namespace nnfw
{
namespace cker
{
+namespace gemmlowp
+{
inline int32_t RoundingHalfSum(int32_t a, int32_t b)
{
@@ -282,6 +284,7 @@ inline FixedPoint<0> one_over_one_plus_x_for_x_in_0_1(FixedPoint<0> a)
return Rescale<0>(ExactMulByPot<-1>(x));
}
+} // namespace gemmlowp
} // namespace cker
} // namespace nnfw
diff --git a/libs/cker/include/cker/operation/SoftMax.h b/libs/cker/include/cker/operation/SoftMax.h
index d3082f7..322f5d5 100644
--- a/libs/cker/include/cker/operation/SoftMax.h
+++ b/libs/cker/include/cker/operation/SoftMax.h
@@ -20,7 +20,7 @@
#include "cker/Shape.h"
#include "cker/Utils.h"
-#include "cker/FixedPoint.h"
+#include "cker/gemmlowp/FixedPoint.h"
#include <cmath>
@@ -89,9 +89,9 @@ inline void Softmax(const SoftmaxParams &params, const Shape &input_shape,
// accumulation, but exp(-16) definitely is.
static const int kScaledDiffIntegerBits = 5;
static const int kAccumulationIntegerBits = 12;
- using FixedPointScaledDiff = FixedPoint<kScaledDiffIntegerBits>;
- using FixedPointAccum = FixedPoint<kAccumulationIntegerBits>;
- using FixedPoint0 = FixedPoint<0>;
+ using FixedPointScaledDiff = gemmlowp::FixedPoint<kScaledDiffIntegerBits>;
+ using FixedPointAccum = gemmlowp::FixedPoint<kAccumulationIntegerBits>;
+ using FixedPoint0 = gemmlowp::FixedPoint<0>;
const int trailing_dim = input_shape.DimensionsCount() - 1;
const int outer_size = MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape);
@@ -115,8 +115,8 @@ inline void Softmax(const SoftmaxParams &params, const Shape &input_shape,
input_diff, input_beta_multiplier, input_beta_left_shift);
const FixedPointScaledDiff scaled_diff_f8 =
FixedPointScaledDiff::FromRaw(input_diff_rescaled);
- sum_of_exps =
- sum_of_exps + Rescale<kAccumulationIntegerBits>(exp_on_negative_values(scaled_diff_f8));
+ sum_of_exps = sum_of_exps + gemmlowp::Rescale<kAccumulationIntegerBits>(
+ exp_on_negative_values(scaled_diff_f8));
}
}
@@ -144,8 +144,8 @@ inline void Softmax(const SoftmaxParams &params, const Shape &input_shape,
FixedPointScaledDiff::FromRaw(input_diff_rescaled);
FixedPoint0 exp_in_0 = exp_on_negative_values(scaled_diff_f8);
- int32_t unsat_output =
- RoundingDivideByPOT((shifted_scale * exp_in_0).raw(), num_bits_over_unit + 31 - 8);
+ int32_t unsat_output = gemmlowp::RoundingDivideByPOT((shifted_scale * exp_in_0).raw(),
+ num_bits_over_unit + 31 - 8);
output_data[i * depth + c] = static_cast<uint8_t>(
std::max(std::min(unsat_output, static_cast<int32_t>(255)), static_cast<int32_t>(0)));