Jump to content
  • 0

Question when using vivado sdk to call IP generated by HLS


dddddddq

Question

Hello, I am writing code in Vivado SDK 2018.3 to drive the IP core generated by HLS to realize handwritten digit recognition. Now there is no problem with the result of a single call, but the first result is correct and the subsequent results are wrong when the loop is called multiple times. For example, I recognize the number 0 now, and he is correct. But I recognize multiple pictures in a row, only the first result is correct, and the other results are all wrong, and I need to reprogram the fpga to recognize it correctly. I have checked the input and tested each image individually, and they are all right. What may be the reason? Here are part of my codes:

// 10 * 28 * 28 imgs
float img[10][784]={
#include "./data/0_0.h"
#include "./data/1_0.h"
#include "./data/2_0.h"
#include "./data/3_0.h"
#include "./data/4_0.h"
#include "./data/5_0.h"
#include "./data/6_0.h"
#include "./data/7_0.h"
#include "./data/8_0.h"
#include "./data/9_0.h"
};

int main()
{
    init_platform();

    Xil_DCacheDisable();
    //========= Initialize IP=================
    XMylenet mylenet;
    XMylenet_Initialize(&mylenet,XPAR_MYLENET_0_DEVICE_ID);
    for (int set = 0; set < 10; set++){
        //========= input =================
        int *img_fixed =(int*)malloc(784*sizeof(int));
        int *out =(int*)malloc(10*sizeof(int));
        for(int i = 0; i < 784; i++)
            img_fixed[i] = 0;
        for (int i = 0; i < 10; i++)
            out[i] = 0;
        for(int i=0;i<784;i++)
            img_fixed[i] = img[set][i]*65536;
        //========= set IP input output =================
        XMylenet_Set_img_in_V(&mylenet,img_fixed);
        XMylenet_Set_out_V(&mylenet,out);
        //========== start IP =============
        XMylenet_Start(&mylenet);
        while(XMylenet_IsDone(&mylenet)==0);
        //========== print result =============
        int max = 0;
        int max_index;
        for(int i=0;i<10;i++){
            float tmp = (float)out[i]/65536.0f;
            printf("number %d predicted out: %f\n", i, tmp);
            if(tmp>max){
                max_index = i;
                max = tmp;
            }
        }
        printf("lenet predict out: %d label: %d\n",max_index, set);

        free(img_fixed);
        free(out);
    }

    cleanup_platform();
    return 0;
}

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @dddddddq,
See this recommend flow for working with AXI4-Lite interfaces from the Vivado HLS user guide (p 109).
https://docs.xilinx.com/v/u/2018.3-English/ug902-vivado-high-level-synthesis
According to this, you will need to use XMylenet_Get_out_V in order to retrieve the prediction. Maybe this is why subsequent calls are not working?

image.png

Link to comment
Share on other sites

  • 0
On 4/20/2023 at 7:58 PM, Niță Eduard said:

Hi @dddddddq,
See this recommend flow for working with AXI4-Lite interfaces from the Vivado HLS user guide (p 109).
https://docs.xilinx.com/v/u/2018.3-English/ug902-vivado-high-level-synthesis
According to this, you will need to use XMylenet_Get_out_V in order to retrieve the prediction. Maybe this is why subsequent calls are not working?

image.png

Hi,@Niță Eduard.Thanks for the suggestion, now I have solved the problem. My problem is that some local variables are not initialized when writing code in HLS. As a beginner, I didn't realize this. Now I found it and solved it successfully. Thanks also for the advice!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...