-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from negishubham/cnn-support
New feature added - weight and input quantization.
- Loading branch information
Showing
7 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2019 IMPACT Research Group, University of Illinois. | ||
* All rights reserved. | ||
* | ||
* This file is covered by the LICENSE.txt license file in the root directory. | ||
* | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <string> | ||
#include <vector> | ||
#include <iostream> | ||
|
||
#include "puma.h" | ||
#include "fully-connected-layer.h" | ||
|
||
int main(int argc, char** argv) { | ||
|
||
//Model model = Model::create("fully-connected-layer"); | ||
|
||
// Process parameters | ||
unsigned int in_size; | ||
unsigned int out_size; | ||
if(argc == 4) { | ||
in_size = atoi(argv[1]); | ||
out_size = atoi(argv[2]); | ||
} | ||
|
||
std:: string str=std::string("fully") + argv[3] + std::string("-connected-layer"); | ||
Model model = Model::create(str); | ||
|
||
// Input | ||
auto in = InputVector::create(model, "in", in_size); | ||
|
||
// Output | ||
auto out = OutputVector::create(model, "out", out_size); | ||
|
||
// Layer | ||
out = fully_connected_layer(model, "", in_size, out_size, in); | ||
|
||
// Compile | ||
model.compile(); | ||
|
||
// Bind data | ||
ModelInstance modelInstance = ModelInstance::create(model); | ||
float* weights = new float[in_size*out_size]; | ||
fully_connected_layer_bind(modelInstance, "", weights); | ||
modelInstance.generateData(); | ||
|
||
// Destroy model | ||
model.destroy(); | ||
delete[] weights; | ||
|
||
return 0; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2019 IMPACT Research Group, University of Illinois. | ||
* All rights reserved. | ||
* | ||
* This file is covered by the LICENSE.txt license file in the root directory. | ||
* | ||
*/ | ||
|
||
#ifndef _PUMA_TEST_FULLY_CONNECTED_LAYER_ | ||
#define _PUMA_TEST_FULLY_CONNECTED_LAYER_ | ||
|
||
#include "puma.h" | ||
|
||
static Vector fully_connected_layer(Model model, std::string layerName, unsigned int in_size, unsigned int out_size, Vector in) { | ||
|
||
ConstantMatrix mat = ConstantMatrix::create(model, layerName + "mat", in_size, out_size); | ||
|
||
return sig(mat*in); | ||
|
||
} | ||
|
||
static void fully_connected_layer_bind(ModelInstance modelInstance, std::string layerName, float* weights) { | ||
modelInstance.bind(layerName + "mat", weights); | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
set -v | ||
set -e | ||
path=`pwd` #path to your puma directory | ||
echo $path | ||
cppfile=fully-connected-layer #name for cpp file that you want to compile ex- mlp_l4_mnist.cpp, conv-layer.cpp, convmax-layer.cpp | ||
name=fully #name for the folder generated by compiler | ||
pumaenv=pumaenv #name for the environment | ||
fileno=0 | ||
name=$name$fileno | ||
|
||
#layer parameter | ||
in=64 | ||
out=10 | ||
|
||
|
||
#copying mlp config file | ||
rm ${path}/puma-simulator/include/config.py #remove existing config file | ||
cp ${path}/puma-simulator/include/example-configs/config-mlp.py ${path}/puma-simulator/include/config.py #copy the mlp config file to include | ||
#copying model file | ||
rm ${path}/puma-compiler/test/${cppfile}.cpp ${path}/puma-compiler/test/${cppfile}.h | ||
cp ${path}/puma-simulator/test/mlp_l4_mnist/${cppfile}.cpp ${path}/puma-compiler/test/${cppfile}.cpp #copy the mlp config file to include | ||
cp ${path}/puma-simulator/test/mlp_l4_mnist/${cppfile}.h ${path}/puma-compiler/test/${cppfile}.h #copy the mlp config file to include | ||
|
||
cd ${path}/puma-compiler/src | ||
source ~/.bashrc | ||
conda activate ${pumaenv} | ||
|
||
make clean | ||
make | ||
|
||
cd ${path}/puma-compiler/test | ||
make clean | ||
make ${cppfile}.test | ||
export LD_LIBRARY_PATH=`pwd`/../src:$LD_LIBRARY_PATH | ||
./${cppfile}.test ${in} ${out} ${fileno} | ||
echo $cppfile | ||
./generate-py.sh | ||
cp -r ${name} ../../puma-simulator/test/testasm | ||
|
||
cd ${path}/puma-simulator/src | ||
|
||
|
||
python dpe.py -n ${name} | ||
|
||
|
||
|