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

Functions

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 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::cker::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}
ruy::CachePolicy ToRuyCachePolicy(CachePolicy cache_policy)
Definition RuySupport.h:34
CachePolicy cache_policy
Definition Types.h:456

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

◆ MakeRuyMulParams() [1/2]

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

Definition at line 69 of file RuySupport.h.

71{
72 static_assert(sizeof(DstScalar) < sizeof(std::int32_t), "");
73 if (quantization_flavor == QuantizationFlavor::kIntegerWithUniformMultiplier)
74 {
75 ruy_mul_params->set_multiplier_fixedpoint(params.multiplier_fixedpoint);
76 ruy_mul_params->set_multiplier_exponent(params.multiplier_exponent);
77 }
78 if (quantization_flavor == QuantizationFlavor::kIntegerWithPerRowMultiplier)
79 {
80 ruy_mul_params->set_multiplier_fixedpoint_perchannel(params.multiplier_fixedpoint_perchannel);
81 ruy_mul_params->set_multiplier_exponent_perchannel(params.multiplier_exponent_perchannel);
82 }
83 ruy_mul_params->set_bias(params.bias);
84 ruy_mul_params->set_clamp_min(params.clamp_min);
85 ruy_mul_params->set_clamp_max(params.clamp_max);
86}
DstScalar clamp_max
Definition Types.h:537
AccumScalar multiplier_fixedpoint
Definition Types.h:513
const AccumScalar * bias
Definition Types.h:531
const int * multiplier_exponent_perchannel
Definition Types.h:529
DstScalar clamp_min
Definition Types.h:533
const AccumScalar * multiplier_fixedpoint_perchannel
Definition Types.h:521

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

◆ MakeRuyMulParams() [2/2]

template<QuantizationFlavor quantization_flavor>
void nnfw::cker::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 90 of file RuySupport.h.

92{
93 ruy_mul_params->set_bias(params.bias);
94}

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

◆ ToRuyCachePolicy()

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

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::cker::kAlwaysCache, nnfw::ruy::kAlwaysCache, nnfw::cker::kCacheIfLargeSpeedup, nnfw::ruy::kCacheIfLargeSpeedup, nnfw::cker::kNeverCache, and nnfw::ruy::kNeverCache.

Referenced by MakeRuyMatrix().