2. Run first simulation - eliyahudev/mannix GitHub Wiki

Initial Helloworld Simulation

create helloworld file

In this section we are going to build the "mannix helloworld" app. Software that prints a mannix matrix struct From the mannix root folder, go to Software-> riskv_simul->source. This will be the library of the simulation environment.

include files

We first include the lib files '#include "../include/cnn_inc.h"'. it contains:

  • Standard libreries (only in github environment).
  • enics libraries (only in gitlab environment)
  • '../config/man_def.h' - configuration file, more details in the next section.
  • 'man_struct.h' - mannix structures header file, more details in the next section.
  • 'read_csv.h' - Used when the user reads input data and parameters from csv files, more details in the next section.
  • 'mannixlib.h' - Allocation of memory. The mannix program assigns data at runtime, more details in the next section.
  • 'mannix_matrix.h', 'mannix_tensor.h', 'mannix_4dtensor.h' - mannix structures function file, more details in the next section.
  • 'mannix_accelerator' - accelerator lib. (only in gitlab environment)

initial setup - memory allocation and management

create main function: 'int main() {' Inside the main function add '#include "../include/tensor_allocation_setup.h"' which is the memory management setting file. This file contains two section:

  1. bytes arrays - the memory needed for the program.
  2. Allocators - Structure for managing the bytes arrays. The allocator returns the pointer for the next free memory in the array or an error if it has no space.

Create mannix struct

The simplest structure in mannix lib is the mannix matrix. it has 3 different types:

  1. Matrix_int8 - number between -128 to 127.
  2. Matrix_uint8 - number between 0 to 255.
  3. Matrix_int32 - integer number.

We first define an instance: 'Matrix_int8 fc_weight[1];' We then define the matrix size (width and height) and allocate memory (with the allocator we define earlier): 'creatMatrix_int8(4, 3, &fc_weight[2], (Allocator_int8*) al);' This matrix contains 4 rows and 3 columns.

Fill the matrix with data

we can load data to the matrix in two ways:

  1. read the data from csv file.
  2. read the data from database file (text file). we will focus in the first method. Before doing so, you can create a csv file. For this example it would look like this: ---- matrix.csv ----- 1, 2, 3 4, 5, 6 7, 8, 9 10, 11, 12 --------------------- now lets read the file: 'FILE* fd = fopen("FULL PATH TO THE matrix.csv FILE","r");' and load the data to the matrix: 'int label[1]; label[0] = 0; // for matrices with label , define here to avoid errors' 'getMatrix_int8(weight, fd, label,-1, 1); // ignore the last 3 argument for now'

print the result matrix

lastly we need to print the results: '**printMatrix_int8(fc_weight);' 'return 0;' '}'