Compute e ^ x for float values ​​in System Verilog?

I create a neural network running on FPGA, and the last piece of the puzzle runs a sigmoid function in the hardware. It is either:

1/(1 + e^-x) 

or

 (atan(x) + 1) / 2 

Unfortunately, x here is the float value (the real value in SystemVerilog).

Are there any tips for using any of these features in SystemVerilog?

This really confuses me, because both of these functions are complex, and I don’t even know where to start their implementation due to the extra complexity of the float values.

+5
source share
2 answers

Another easy way is to create a memory / array for this function. However, this option can be very inefficient.

x must be the input address for the memory, and the value at this location may be the output of the function.

Suppose the meaning of your function is as follows. (This is just an example)

 x = 0 => f(0) = 1 x = 1 => f(0) = 2 x = 2 => f(0) = 3 x = 3 => f(0) = 4 

So, you can create an array for this that saved the output values.

 int a[4] = `{1, 2, 3, 4}; 
0
source

I just finished Vivado HLS, which allows me to write schemes in C. Here is my C code.

 #include math.h void exp(float a[10],b[10]) { int i; for(i=0;i<10;i++) { b[i] = exp(a[i]); } } 

But the question arises that it is impossible to create a custom matrix. Perhaps there is another way that I do not know.

0
source

Source: https://habr.com/ru/post/1260059/


All Articles