-
Notifications
You must be signed in to change notification settings - Fork 0
/
TopSynthFunction.cpp
55 lines (43 loc) · 1.35 KB
/
TopSynthFunction.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <limits>
#include "Neural.h"
#include "TopSynthFunction.h"
void TopFun(ioDataType inputData[inputsize], ioDataType outputData[outputsize], ap_uint<2> instruction){
static MOJNN::Layer<dataType, 2, 2, MOJNN::hyperbolicTangent> firstLayer;
static MOJNN::Layer<dataType, 2, 2, MOJNN::hyperbolicTangent> secondLayer;
dataType bufferOne[inputsize] = {0};
dataType bufferTwo[inputsize] = {0};
dataType outputErrorDerivative[2] = {0};
static bool isInit = false;
if (isInit == false)
{
firstLayer.layersSetBiases(MOJNN::FirstgetBiasBuffer);
secondLayer.layersSetBiases(MOJNN::SecondgetBiasBuffer);
isInit = true;
}
//Load input Data to buffers
for (int i = 0; i < inputsize; i++)
{
bufferOne[i]=inputData[i];
};
//Start Propagation
firstLayer.layerPropagate(bufferOne, bufferTwo);
secondLayer.layerPropagate(bufferTwo, bufferOne);
//Check if backpropagation is enabled
if (instruction == 1)
{
MOJNN::calculateError<1>(bufferOne, outputData, outputErrorDerivative);
/*Odwrotna kolejnosc podawanych funkcji*/
MOJNN::BackPropagate<
dataType, 2, 2, MOJNN::hyperbolicTangent,
dataType, 2, 2, MOJNN::hyperbolicTangent>(outputErrorDerivative, &secondLayer, &firstLayer);
}
if (instruction == 0)
{
//Send data back to user
for (int i = 0; i < outputsize; i++)
{
outputData[i]=bufferOne[i];
};
}
};