Developer World
Spresense Arduino Library v3.2.0-77d75a4
DNNRT.h
Go to the documentation of this file.
1/*
2 * DNNRT.h - Spresense Arduino DNN runtime library
3 * Copyright 2018 Sony Semiconductor Solutions Corporation
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef Dnnrt_h
21#define Dnnrt_h
22
23#ifdef SUBCORE
24#error "DNNRT library is NOT supported by SubCore."
25#endif
26
33#include <Arduino.h>
34
35#include <dnnrt/runtime.h>
36
37class DNNVariable; // forward reference
38class File;
39
50class DNNRT {
51
52public:
53 DNNRT() {};
54 ~DNNRT() {};
55
75 int begin(File &nnbfile, unsigned char cpu_num = 1);
76
82 int end();
83
92 int inputVariable(DNNVariable &var, unsigned int index);
93
101 DNNVariable& outputVariable(unsigned int index);
102
108 int forward();
109
116
123 int inputSize(unsigned int index);
124
131 int inputDimension(unsigned int index);
132
140 int inputShapeSize(unsigned int index, unsigned int shapeindex);
141
148
155 int outputSize(unsigned int index);
156
163 int outputDimension(unsigned int index);
164
172 int outputShapeSize(unsigned int index, unsigned int shapeindex);
173
174private:
175 dnn_runtime_t *_rt; // DNN runtime context
176 nn_network_t *_network; // Network data from .nnb file
177
178 void **_input; // Input data array
179 int _nr_inputs; // Number of input data
180 DNNVariable *_output; // Output data array
181 int _nr_outputs; // Number of output data
182};
183
185 friend class DNNRT;
186
187public:
188 DNNVariable(unsigned int size);
189 ~DNNVariable();
190
196 unsigned int size() {
197 return _size;
198 }
199
200 const float& operator[](unsigned int index) const {
201 return _data[index];
202 }
203
212 float *data() {
213 return _data;
214 }
215
221 int maxIndex();
222
223private:
224 DNNVariable();
225 float *_data;
226 unsigned int _size;
227 bool _allocated;
228};
229
232#endif
Definition: DNNRT.h:50
int inputShapeSize(unsigned int index, unsigned int shapeindex)
int inputDimension(unsigned int index)
int inputSize(unsigned int index)
DNNVariable & outputVariable(unsigned int index)
int outputShapeSize(unsigned int index, unsigned int shapeindex)
int forward()
int inputVariable(DNNVariable &var, unsigned int index)
int outputSize(unsigned int index)
int begin(File &nnbfile, unsigned char cpu_num=1)
int end()
int numOfInput()
int numOfOutput()
int outputDimension(unsigned int index)
Definition: DNNRT.h:184
float * data()
Definition: DNNRT.h:212
unsigned int size()
Definition: DNNRT.h:196
int maxIndex()
The File class allows for reading from and writing to individual files on the File System.
Definition: File.h:55