作者 | strongerHuang
关于 uTensor 模型
模型地址:
https://github.com/uTensor/uTensor

此存储库包含核心运行时和运算符、内存管理器、调度器等的一些示例实现,核心运行时的大小仅为:2KB!

uTensor 工作原理
uTensor 工作原理大致如下图所示:

uTensor 运行时由两个主要组件组成:
uTensor Core:其中包含满足 uTensor 性能运行时契约所需的基本数据结构、接口和类型等。
uTensor 库:作为一系列基于 uTensor Core 构建的默认实现。
构建系统分别编译这两个组件,使用户能够轻松扩展和覆盖构建在 uTensor 核心之上的实现,例如自定义内存管理器、张量、运算符和错误处理程序。
SimpleErrorHandler errH(50); // Maintain a history of 50 eventsContext::get_default_context()->set_ErrorHandler(&errH);...// A bunch of allocations...// Check to make sure a rebalance has occurred inside our allocatorbool has_rebalanced = std::find(errH.begin(), errH.end(), localCircularArenaAllocatorRebalancingEvent()) != errH.end();
uint8_t myBuffer[4] = { 0xde, 0xad, 0xbe, 0xef };Tensor mTensor = new BufferTensor({2,2}, u8, myBuffer); // define a 2x2 tensor of uint8_tsuint8_t a1 = mTensor(0,0); // implicitly casts the memory referenced at this index to a uint8_tprintf("0x%hhx\n", a1); // prints 0xdeuint16_t a2 = mTensor(0,0); // implicitly casts the memory referenced at this index to a uint16_tprintf("0x%hx\n", a2); // prints 0xdeaduint32_t a3 = mTensor(0,0); // implicitly casts the memory referenced at this index to a uint32_tprintf("0x%x\n", a3); // prints 0xdeadbeef// You can also write and read values with explicit casting and get similar behaviormTensor(0,0) = static_cast<uint8_t>(0xFF);printf("0xhhx\n", static_cast<uint8_t>(mTensor(0,0)));
uTensor 构建、运行和测试
官方给出了 uTensor 构建、运行和测试的一些方法。
gitclone git@github.com:uTensor/uTensor.gitcduTensor/gitcheckout proposal/rearchgitsubmodule initgitsubmodule updatemkdirbuildcdbuild/cmake-DPACKAGE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..makemaketest
mbednew my_projectcdmy_projectmbedimport https://github.com/uTensor/uTensor.git# Create main file# Run uTensor-cli workflow and copy model directory herembedcompile # as normal
mkdir build && cd buildcmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../extern/CMSIS_5/CMSIS/DSP/gcc.cmake ..//使用 CMSIS 优化内核mkdir build && cd buildcmake -DARM_PROJECT=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../extern/CMSIS_5/CMSIS/DSP/gcc.cmake ..
