Skip to content
Snippets Groups Projects

[Feat] Add quantized exports for Resnet18 and LeNet

Merged Axel Farrugia requested to merge feat_add_quantized_export into dev
Compare and
69 files
+ 2907
849
Compare changes
  • Side-by-side
  • Inline
Files
69
#ifndef __AIDGE_EXPORT_CPP_KERNELS_ACTIVATION__
#define __AIDGE_EXPORT_CPP_KERNELS_ACTIVATION__
#include <type_traits>
#include "network/typedefs.hpp"
#include "network/utils.hpp"
#include "kernels/rescaling.hpp"
template<typename Output_T, typename T,
typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr>
__attribute__((always_inline)) inline
Output_T saturate (T value, int32_t /*sat*/)
{
return value;
}
template<typename Output_T, typename T,
typename std::enable_if<!std::is_floating_point<T>::value>::type* = nullptr>
__attribute__((always_inline)) inline
Output_T saturate (T value, uint32_t sat)
{
if (std::is_unsigned<Output_T>::value) {
return clamp(value, T(0), (T(1) << sat) - 1);
} else {
return clamp(value, -(T(1) << (sat - 1)), (T(1) << (sat - 1)) - 1);
}
}
template<typename Output_T,
typename Sum_T,
typename Rescaling_T>
__attribute__((always_inline)) inline
Output_T activation_forward_value (Sum_T weightedSum,
int output,
ActivationFunction_T func,
const Rescaling_T& __restrict rescaling)
{
switch(func) {
case Linear:
case Saturation: {
break;
}
case Rectifier: {
if(weightedSum <= 0) weightedSum = 0;
break;
}
default:
// Unsupported activation function
break;
}
// Value fixed here for now but it should be generated by
// the export module or determined by the type of Output_T
// For now only works for int8_t and uint8_t
const uint32_t NB_BITS = 8;
return saturate<Output_T>(rescaling(weightedSum, output), NB_BITS);
}
#include "network/activation_utils.hpp"
#include "network/rescaling_utils.hpp"
template<int NB_DATA,
ActivationFunction_T ACTIVATION,
Loading