cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
295 Views
Registered: ‎04-25-2020

Run C Synthesis

Jump to solution

Hello I am trying to do Synthesis to my algorithm but when it finishes the latency bar is fulled with "?"

latency.png

I want to correct it so it gives numbers instead of "?"

Here below my algorithm 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;

void demarche (float W[100][100],float W1[100][100],float X[100],float Sd[100],int n1,int n2,int n3){
	    float l,nu,e,Somme;
    float E[100],Y[100],E1[100],Y1[100],Deltaj[100],Deltak[100],es[100],Wa[100][100],Wa1[100][100];
    int t;
       nu=0.6;
        t=0;
        Somme=0;
        
	
	 do
    {
    	t+=1;
        for (int j=0;j<n2;j++)
        {
    
            	 for (int h=0;h<n1;h++)
                     {
                         E[j] += (X[h]*W[h][j]);
                     }
                
                Y[j]=1/(1+(exp(-E[j])));
            
        }

        for (int k=0;k<n3;k++)
        {
            
            	for (int h=0;h<n2;h++)
                     {
                         E1[k] += (Y[h]*W1[h][k]);
                     }
                     
                Y1[k]=1/(1+(exp(-E1[k])));
                es[k]=Y1[k];
            
        } // Calcul du Sc

        e=0;
        for (int k=0;k<n3;k++)	{
            e+=(es[k]-Sd[k])*(es[k]-Sd[k])*0.5;
        } // calcul d'erreur quadratique
             

        for (int j=0;j<n2;j++)
        {
        	Somme=0;
            for (int i=0;i<n1;i++)
            {
            	
            	for (int h=0 ; h<n3;h++)
                {
                 Somme += es[h]*W1[j][h];
                }
                Deltaj[j]=Y[j]*(1-Y[j])*Somme;
                Wa[i][j]=W[i][j]+nu*Deltaj[j]*X[i];
            }
        } // calcul des nouveaux poids Wa


        for (int k=0;k<n3;k++)
        {
            for (int j=0;j<n2;j++)
            {
                Deltak[k]=Y1[k]*(1-Y1[k])*(Sd[k]-Y1[k]);
                Wa1[j][k]=W1[j][k]+nu*Deltaj[j]*Y1[k];
            }
        } // calcul des nouveaux poids Wa1

        for (int j=0;j<n2;j++)
        {
            for (int i=0;i<n1;i++)
            {
                W[i][j]=Wa[i][j];
            }
        } // Changement des poids W

        for (int k=0;k<n3;k++)
        {
            for (int j=0;j<n2;j++)
            {
                W1[j][k]=Wa1[j][k];
            }
        } 
        
		
	
		
			
		// Changement des poids W1
    cout<<e<<endl;
    } while ((e>0.001)&&(t<200));
	
}








void calcul (float W[100][100],float W1[100][100],int n1 , int n2 ,int n3){
	    for (int i=0;i<n1;i++){
        for (int j=0;j<n2;j++){
            W[i][j]= (float)rand() / (float)RAND_MAX;
        }
    } // calcul des poids du couche cachée

    for (int i=0;i<n2;i++){
        for (int j=0;j<n3;j++){
            W1[i][j]= (float)rand() / (float)RAND_MAX;
        }
    } 
}










int main()
{

    float X[100],W[100][100],W1[100][100],Sd[100];


    int n1,n2,n3;

   /* std::cout<<"donnez n1 : "<<endl;
    std::cin >> n1;
    std::cout<<"donnez n2 : "<<endl;
    std::cin >> n2;
    std::cout<<"donnez n3 : "<<endl;
    std::cin >> n3;

    for (int i=0;i<n1;i++){
        cout<<"inserez la valeur "<<i+1<<" dans X "<<endl;
        cin >> X[i];
    } // Calcul des entrées

    for (int i=0;i<n3;i++){
        cout<<"inserez la valeur "<<i+1<<" dans Sd "<<endl;
        cin >> Sd[i];
*/ n1=4;
        n2=3;
        n3=2;
        X[0]=5;
        X[1]=2;
        X[2]=0.2;
        X[3]=12;
        Sd[0]=0.2;
        Sd[1]=0.02;
     
    // Calcul des sorties desirées

 // calcul des poids du couche sortie
 calcul(W,W1,n1,n2,n3);
 demarche (W,W1,X,Sd,n1,n2,n3);



    return 0;
}

Thanks for responding 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Voyager
Voyager
265 Views
Registered: ‎06-20-2012

Re: Run C Synthesis

Jump to solution

Cosim: simulate the VHDL/Verilog with the C testbench.

You can also include

#pragma HLS LOOP_TRIPCOUNT min=10 max=20 avg=15

For every for loop without fixed interations.

== If this was helpful, please feel free to give Kudos, and close if it answers your question ==

View solution in original post

0 Kudos
3 Replies
Highlighted
Voyager
Voyager
282 Views
Registered: ‎06-20-2012

Re: Run C Synthesis

Jump to solution

The while loop does not have a fixed number of iterations at compile time.
Latency cannot be known without simulation.
Do a cosim and you will know the latency for your example.

== If this was helpful, please feel free to give Kudos, and close if it answers your question ==
0 Kudos
Highlighted
Visitor
Visitor
271 Views
Registered: ‎04-25-2020

Re: Run C Synthesis

Jump to solution

I changed the do loop to a for loop with 100 iterations, Unfortenantly it doesn't work

cosim ?? I am sorry what's that ?

0 Kudos
Highlighted
Voyager
Voyager
266 Views
Registered: ‎06-20-2012

Re: Run C Synthesis

Jump to solution

Cosim: simulate the VHDL/Verilog with the C testbench.

You can also include

#pragma HLS LOOP_TRIPCOUNT min=10 max=20 avg=15

For every for loop without fixed interations.

== If this was helpful, please feel free to give Kudos, and close if it answers your question ==

View solution in original post

0 Kudos