/caial

Simple C AI algorithms

Primary LanguageCBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

CAIAL

C simple AI algorithms for testing bprof on bare metal RISC-V roscket-chip. Currently are implemented the the next AI algoritms Classification Tree (CT),K-nearest neighbors (KNN),Deep neural networks (DNN), Linear regresion (LR), Naive Bayes (NB), Suport Vector Machine (SVM) and K-Means (KMEANS). Their implementation is simple as possible and does not use any libraries.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Tested on Ubuntu 16.04

  • Ubuntu 16.04 (inital setup)
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install git -y
mkdir -p riscv/riscv-tools
  • rocket-tools requirments
sudo apt-get install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev libusb-1.0-0-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev device-tree-compiler pkg-config libexpat-dev -y
  • chistel requirments
  1. java
sudo apt-get install default-jdk -y
  1. sbt
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get install sbt -y
  1. verilator
sudo apt-get install git make autoconf g++ flex bison -y
git clone http://git.veripool.org/git/verilator
cd verilator
git checkout verilator_4_006
unset VERILATOR_ROOT
autoconf
./configure
make
sudo make install
cd
  • rocket-tools
git clone --recursive  https://github.com/freechipsproject/rocket-tools
cd rocket-tools
export RISCV=/riscv/rocket-tools
./build.sh
export PATH=$PATH:$RISCV/bin
echo "export RISCV=/riscv/rocket-tools" >> .bashrc
echo "export PATH=$PATH:$RISCV/bin" >> .bashrc
cd
  • rocket chip
git clone --recursive  https://github.com/sdcioc/rocket-chip
cd rocket-chip
export ROCKETCHIP=`pwd`
echo "export ROCKETCHIP="$ROCKETCHIP >> .bashrc
cd $ROCKETCHIP/emulator
make debug
cd
  • riscv-tests
git clone --recursive https://github.com/riscv/riscv-tests
cd riscv-tests
autoconf
./configure --prefix=$RISCV/target
make
sudo make install
export RISCVTESTS=`pwd`
echo "export RISCVTESTS="$RISCVTESTS >> .bashrc
cd
  • bprof requirments
sudo apt-get -y install python-pip
pip install numpy

Installing

  • Clone and build the repo
git clone https://github.com/sdcioc/caial.git
make
make simv
make strip
  • Test the system
python parser.py  strip_simv.log output

Running the tests

If you want to test one of the algorithms you have to do the next things: Compile the algorithm

make APP=NAME_OF_THE_ALGORITHM

Simulate the algorithm

make simv APP=NAME_OF_THE_ALGORITHM

Delete the logs that are not necesary

make strip APP=NAME_OF_THE_ALGORITHM

Run the parser

python parser.py  strip_simv.log output

Adding other programs

For adding another program just create directory with the program name. Inside the directory write you code in the file with the name the same as the directory name plus extension ".c". Example:

mkdir NEWPROGRAM
cd NEWPROGRAM
touch NEWPROGRAM
...
cd ..
make APP=NEWPROGRAM

Analyze the results

The results will be in the file with the name of the second argument to the parser plus ".csv" extension.

python parser.py  strip_simv.log output
cat output.csv

Debug with Rocket Chip Emulator and GDB

Let's take MM as an eaxmple. To see the symbols, compile with -g flag (add it to CFLAGS in Makefile.inc). For this debugging activity, I recommend using four terminals, as follows:

1> caial repository, for building the code

cd caial
make APP=MM

2> emulator - Rocket Chip Emulator with DefaultConfigRBB config

cd rocket-chip/emulator
CONFIG=DefaultConfigRBB make
./emulator-freechips.rocketchip.system-DefaultConfigRBB +jtag_rbb_enable=1 -c -r 55555 ../../caial/MM.riscv

3> opencda (with a specific config)

cd riscv-tools/bin
./openocd -f cemulator.cfg

wait for it to show something like:

...
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

4> gdb

cd riscv-tools/bin
./riscv64-unknown-elf-gdb ../../caial/MM.riscv
...
(gdb) set remotetimeout 5000
(gdb) target remote localhost:3333
(gdb) load
(gdb) cont
(gdb) x/9tx AA

Docker Deployment

If you want to use dockers. First you will have to install docker. Ubuntu 16.04 tested

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce

Build the docker image

cd docker
docker build .

Run docker with local git repo as a volume

docker run -it -v `pwd`:/caial-dev caial bash

Download docker image

docker pull sdcioc/bprofriscv:latest

Inside docker

cd caial
git pull

Built With

Directories

All directories except docker represent an algorithm that can be used. The "docker" directory has a Dockerfile necesary for building the docker image.

Experiment logic

TODO:

Implementations

TODO:

Contributing

TODO:

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

TODO:

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Ciocîrlan Ștefan-Dan - Algorithms and building the system work - sdcioc

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details

Acknowledgments

  • NUS