TensorFlow Lite for Microcontrollers 的依赖和相关的macro

TensorFlow Lite for Microcontrollers 的依赖和相关的macro,第1张

TensorFlow Lite for Microcontrollers 的依赖相关的macro

如果要移植tflm代码到一个单独工程上去编译,要主要这些依赖库,因为这些库是动态下载的,执行某些脚本才有对应的文件,要特别注意

-I./third_party/gemmlowp
-I./third_party/flatbuffers/include
-I./third_party/ruy
 

flatbuffer(tflite model)

**FlatBuffers** is a cross platform serialization library architected for 
maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.

gemmlowp

# gemmlowp: a small self-contained low-precision GEMM library      

gemmlowp概述                                                                                       

[![Build Status](https://secure.travis-ci.org/google/gemmlowp.png)](http://travis-ci.org/google/gemmlowp)

This is not a full linear algebra library, only a GEMM library: it only does
general matrix multiplication ("GEMM").

The meaning of "low precision" is detailed in this document:
[doc/low-precision.md](doc/low-precision.md)

Some of the general design is explained in [doc/design.md](doc/design.md).

**Warning:** This library goes very slow if compiled incorrectly; see below.

## Disclaimer

This is not an official Google product (experimental or otherwise), it is just
code that happens to be owned by Google.

## Mailing list

gemmlowp-related discussion, about either development or usage, is welcome on
this Google Group (mailing list / forum):

https://groups.google.com/forum/#!forum/gemmlowp

## Portability, target platforms/architectures

Should be portable to any platform with some C++11 and POSIX support, while we
have optional optimized code paths for specific architectures.

Required:

*   C++11 (a small conservative subset of it)

Required for some features: 为一些feature如pthreads/sysconf而提出的要求

*   Some POSIX interfaces:
    *   pthreads (for multi-threaded operation and for profiling).
    *   sysconf (for multi-threaded operation to detect number of cores; may be
        bypassed).

gemmlowp在tflite/tflm中使用

lite/kernels/internal/common.h

gemmlowp/fixedpoint/fixedpoint.h

inline int32_t MultiplyByQuantizedMultiplier(int32_t x, int32_t quantized_multiplier, int shift) {

        using gemmlowp::RoundingDivideByPOT;

       using gemmlowp::SaturatingRoundingDoublingHighMul;

       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);

}

gemmlowp资料

GEMMLOWP的一二_apllo_新浪博客

通用矩阵乘(GEMM)优化算法 | 黎明灰烬 博客

ruy (TfLM没有使用?)

# The ruy matrix multiplication library                                                                                                                                  

This is not an officially supported Google product.

ruy is a matrix multiplication library. Its focus is to cover the matrix
multiplication needs of neural network inference engines. Its initial user has
been TensorFlow Lite, where it is used by default on the ARM CPU architecture.

ruy supports both floating-point and 8bit-integer-quantized matrices.

## Efficiency

ruy is designed to achieve maximal performance not just on very large sizes, as
is the focus of many established libraries, but on whatever are the actual sizes
and shapes of matrices most critical in current TensorFlow Lite applications.
This often means quite small sizes, e.g. 100x100 or even 50x50, and all sorts of
rectangular shapes.

ruy is currently only optimized for the ARM architectures (both 64-bit and
32-bit code). Optimization for the Intel x86 architecture is in progress.

ruy is currently optimized only for the following combination of storage orders:
LHS = row-major, RHS = column-major, destination = column-major. All other
combinations of storage orders fall back to slow reference code at the moment.
 

tflite micro相关的宏 TF_LITE_STATIC_MEMORY 

                                                                                                         

这个宏对tflm而言并不是必须的,bazel 默认就没有使用这个宏,但如果是tflm要定义这个宏如make的编译方式

// NOTE: This flag is opt-in only at compile time.
//
// Specific reduced TfLiteTensor struct for TF Micro runtime. This struct
// contains only the minimum fields required to initialize and prepare a micro
// inference graph. The fields in this struct have been ordered from
// largest-to-smallest for optimal struct sizeof.
//
// This struct does not use:
// - allocation
// - buffer_handle
// - data_is_stale
// - delegate
// - dims_signature
// - name
// - sparsity
 

TF_LITE_STRIP_ERROR_STRINGS

不要直接调用int Report(const char* format, ...); 而是使用 TF_LITE_REPORT_ERROR

macro: TF_LITE_REPORT_ERROR 因为这种方法能关闭log 输出

// You should not make bare calls to the error reporter, instead use the
// TF_LITE_REPORT_ERROR macro, since this allows message strings to be
// stripped when the binary size has to be optimized. If you are looking to
// reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and
// every call will be stubbed out, taking no memory.
#ifndef TF_LITE_STRIP_ERROR_STRINGS
#define TF_LITE_REPORT_ERROR(reporter, ...)                            
  do {                                                                  
    static_cast(reporter)->Report(__VA_ARGS__);
  } while (false)
#else  // TF_LITE_STRIP_ERROR_STRINGS
#define TF_LITE_REPORT_ERROR(reporter, ...)
#endif  // TF_LITE_STRIP_ERROR_STRINGS
 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4951493.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-13
下一篇 2022-11-13

发表评论

登录后才能评论

评论列表(0条)

保存