ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnfw::ruy::ruy_support Namespace Reference

Functions

inline ::ruy::CachePolicy ToRuyCachePolicy (CachePolicy cache_policy)
 
template<typename Scalar , typename DataPointer >
void MakeRuyMatrix (const MatrixParams< Scalar > &params, DataPointer data_ptr, ::ruy::Matrix< Scalar > *dst, bool use_caching=false)
 
template<typename AccumScalar , typename DstScalar , QuantizationFlavor quantization_flavor>
void MakeRuyMulParams (const GemmParams< AccumScalar, DstScalar, quantization_flavor > &params, ::ruy::MulParams< AccumScalar, DstScalar > *ruy_mul_params)
 
template<typename DstScalar , QuantizationFlavor quantization_flavor>
void MakeRuyMulParams (const GemmParams< std::int32_t, DstScalar, quantization_flavor > &params, ::ruy::MulParams< std::int32_t, DstScalar > *ruy_mul_params)
 
template<QuantizationFlavor quantization_flavor>
void MakeRuyMulParams (const GemmParams< std::int32_t, std::int32_t, quantization_flavor > &params, ::ruy::MulParams< std::int32_t, std::int32_t > *ruy_mul_params)
 

Function Documentation

◆ MakeRuyMatrix()

template<typename Scalar , typename DataPointer >
void nnfw::ruy::ruy_support::MakeRuyMatrix ( const MatrixParams< Scalar > &  params,
DataPointer  data_ptr,
::ruy::Matrix< Scalar > *  dst,
bool  use_caching = false 
)

Definition at line 51 of file RuySupport.h.

53{
54 ::ruy::Order ruy_order =
55 params.order == Order::kColMajor ? ::ruy::Order::kColMajor : ::ruy::Order::kRowMajor;
56 ::ruy::MakeSimpleLayout(params.rows, params.cols, ruy_order, dst->mutable_layout());
57 // Note that ruy::Matrix::data is a ConstCheckingPtr, not a plain pointer.
58 // It does care whether we assign to it a Scalar* or a const Scalar*.
59 dst->set_data(data_ptr);
60 dst->set_zero_point(params.zero_point);
61 if (use_caching)
62 {
63 dst->set_cache_policy(ToRuyCachePolicy(params.cache_policy));
64 }
65}
CachePolicy cache_policy
Definition Types.h:141

References nnfw::ruy::MatrixParams< Scalar >::cache_policy, nnfw::ruy::MatrixParams< Scalar >::cols, nnfw::ruy::kColMajor, nnfw::ruy::kRowMajor, nnfw::ruy::MatrixParams< Scalar >::order, nnfw::ruy::MatrixParams< Scalar >::rows, ToRuyCachePolicy(), and nnfw::ruy::MatrixParams< Scalar >::zero_point.

Referenced by nnfw::ruy::FullyConnected().

◆ MakeRuyMulParams() [1/3]

template<typename AccumScalar , typename DstScalar , QuantizationFlavor quantization_flavor>
void nnfw::ruy::ruy_support::MakeRuyMulParams ( const GemmParams< AccumScalar, DstScalar, quantization_flavor > &  params,
::ruy::MulParams< AccumScalar, DstScalar > *  ruy_mul_params 
)

Definition at line 69 of file RuySupport.h.

71{
72 static_assert(quantization_flavor == QuantizationFlavor::kFloatingPoint, "");
73 ruy_mul_params->set_bias(params.bias);
74 ruy_mul_params->set_clamp_min(params.clamp_min);
75 ruy_mul_params->set_clamp_max(params.clamp_max);
76}
DstScalar clamp_max
Definition Types.h:222
DstScalar clamp_min
Definition Types.h:218
const AccumScalar * bias
Definition Types.h:216

References nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::bias, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_max, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_min, and nnfw::ruy::kFloatingPoint.

Referenced by nnfw::ruy::FullyConnected().

◆ MakeRuyMulParams() [2/3]

template<typename DstScalar , QuantizationFlavor quantization_flavor>
void nnfw::ruy::ruy_support::MakeRuyMulParams ( const GemmParams< std::int32_t, DstScalar, quantization_flavor > &  params,
::ruy::MulParams< std::int32_t, DstScalar > *  ruy_mul_params 
)

Definition at line 80 of file RuySupport.h.

82{
83 static_assert(sizeof(DstScalar) < sizeof(std::int32_t), "");
84 if (quantization_flavor == QuantizationFlavor::kIntegerWithUniformMultiplier)
85 {
86 ruy_mul_params->set_multiplier_fixedpoint(params.multiplier_fixedpoint);
87 ruy_mul_params->set_multiplier_exponent(params.multiplier_exponent);
88 }
89 if (quantization_flavor == QuantizationFlavor::kIntegerWithPerRowMultiplier)
90 {
91 ruy_mul_params->set_multiplier_fixedpoint_perchannel(params.multiplier_fixedpoint_perchannel);
92 ruy_mul_params->set_multiplier_exponent_perchannel(params.multiplier_exponent_perchannel);
93 }
94 ruy_mul_params->set_bias(params.bias);
95 ruy_mul_params->set_clamp_min(params.clamp_min);
96 ruy_mul_params->set_clamp_max(params.clamp_max);
97}
AccumScalar multiplier_fixedpoint
Definition Types.h:198
const int * multiplier_exponent_perchannel
Definition Types.h:214
const AccumScalar * multiplier_fixedpoint_perchannel
Definition Types.h:206

References nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::bias, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_max, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::clamp_min, nnfw::ruy::kIntegerWithPerRowMultiplier, nnfw::ruy::kIntegerWithUniformMultiplier, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::multiplier_exponent, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::multiplier_exponent_perchannel, nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::multiplier_fixedpoint, and nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::multiplier_fixedpoint_perchannel.

◆ MakeRuyMulParams() [3/3]

template<QuantizationFlavor quantization_flavor>
void nnfw::ruy::ruy_support::MakeRuyMulParams ( const GemmParams< std::int32_t, std::int32_t, quantization_flavor > &  params,
::ruy::MulParams< std::int32_t, std::int32_t > *  ruy_mul_params 
)

Definition at line 101 of file RuySupport.h.

103{
104 ruy_mul_params->set_bias(params.bias);
105}

References nnfw::ruy::GemmParams< AccumScalar, DstScalar, quantization_flavor >::bias.

◆ ToRuyCachePolicy()

inline ::ruy::CachePolicy nnfw::ruy::ruy_support::ToRuyCachePolicy ( CachePolicy  cache_policy)

Definition at line 34 of file RuySupport.h.

35{
36 switch (cache_policy)
37 {
38 case CachePolicy::kNeverCache:
39 return ::ruy::CachePolicy::kNeverCache;
40 case CachePolicy::kCacheIfLargeSpeedup:
41 return ::ruy::CachePolicy::kCacheIfLargeSpeedup;
42 case CachePolicy::kAlwaysCache:
43 return ::ruy::CachePolicy::kAlwaysCache;
44 default:
45 assert(false);
46 return ::ruy::CachePolicy::kNeverCache;
47 }
48}

References nnfw::ruy::kAlwaysCache, nnfw::ruy::kCacheIfLargeSpeedup, and nnfw::ruy::kNeverCache.

Referenced by MakeRuyMatrix().