Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

using fixed point design in vivado SDK

Status
Not open for further replies.

sai_shashi

Junior Member level 3
Joined
Jan 20, 2017
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
240
Hello there,

I need to deal with fixed point data types in Vivado SDK to send data to a fixed poing IP core.
Does anyone has any idea.?

Thank you
 

Basically, you need to have fixed point libraries to deal with fixed point operations. If you only need to fetch data to the IP core, you still have to use the fixed-point library to convert the data to the fixed point verison before sending to the fixed point IP core.
I made a tutorial on my blog about fixed-point matrix multiplication. It also used a Memory IP core from Xilinx.
You can take a look if it can help you.
https://www.fpga4student.com/2016/12/fixed-point-matrix-multiplication-in-Verilog.html
 

Thank you.. i went through the code. It is really helpful.
What i am still not clear is that how do i send Fixed point data typed to IP core through SDK and display the FP data. I have added fixed point library from HLS to SDK but the result gives me only random values. can you please help me out here.?

I have attached here the SDK code:



Code C - [expand]
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <stdio.h>
#include "xil_io.h"
#include "xparameters.h"
#include "xaxidma.h"
#include "xmatrixmul.h"
#undef str
#include "ap_fixed.h"
 
#define DIM    3
#define SIZE  ((DIM)*(DIM))
 
#include "xil_printf.h"
 
typedef ap_fixed<22,10> mat_a_t;
typedef ap_fixed<22,10> mat_b_t;
typedef ap_fixed<22,10> result_t;
 
 
XAxiDma AxiDma;
 
 
XMatrixmul XMatrixmul_dev;
XMatrixmul_Config XMatrixmul_config = { 0, XPAR_MATRIXMUL_0_S_AXI_CONTROL_BUS_BASEADDR};
 
int init_dma(){
    XAxiDma_Config *CfgPtr;
    int status;
 
    CfgPtr = XAxiDma_LookupConfig(XPAR_AXI_DMA_0_DEVICE_ID);
    if(!CfgPtr){
        print("Error looking for AXI DMA config\n\r");
        return XST_FAILURE;
    }
    status = XAxiDma_CfgInitialize(&AxiDma,CfgPtr);
    if(status != XST_SUCCESS){
        print("Error initializing DMA\n\r");
        return XST_FAILURE;
    }
    //check for scatter gather mode
    if(XAxiDma_HasSg(&AxiDma)){
        print("Error DMA configured in SG mode\n\r");
        return XST_FAILURE;
    }
    /* Disable interrupts, we use polling mode */
    XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DEVICE_TO_DMA);
    XAxiDma_IntrDisable(&AxiDma, XAXIDMA_IRQ_ALL_MASK,XAXIDMA_DMA_TO_DEVICE);
 
    return XST_SUCCESS;
}
//---------------------------------------------------------------------------
 
void print_accel_status(void)
{
    int isDone, isIdle, isReady;
 
    isDone = XMatrixmul_IsDone(&XMatrixmul_dev);
    isIdle = XMatrixmul_IsIdle(&XMatrixmul_dev);
    isReady = XMatrixmul_IsReady(&XMatrixmul_dev);
    xil_printf("MatMultAccel Status: isDone %d, isIdle %d, isReady%d\r\n", isDone, isIdle, isReady);
}
//---------------------------------------------------------------------------
 
int main()
{
 
    int i, j;
        int status, err=0;
 
        mat_a_t res_hw[DIM][DIM], res_sw[DIM][DIM];
 
        mat_a_t dma_size = SIZE * sizeof(mat_a_t);
 
 
    xil_printf("\r********************************\n\r");
        xil_printf("\r MATRIX MULT in Vivado HLS + DMA\n\n\r");
      // Init DMA
        status = init_dma();
 
        if(status != XST_SUCCESS){
            print("\rError: DMA init failed\n");
            return XST_FAILURE;
        }
        print("\rDMA Init done\n\r");
 
        // input data; Matrix Initiation
        mat_a_t A[3][3] = { {1.1, 2.2, 3.3},{4.4, 5.5, 6.6},{7.7, 8.8, 9.9} };
        mat_b_t  B[3][3] = {{1, 2, 3},{4, 5, 6},{7, 8, 9} };
 
         // Run the HW Accelerator;
         status = XMatrixmul_CfgInitialize(&XMatrixmul_dev, &XMatrixmul_config);
            if(status != XST_SUCCESS){
                xil_printf("Error: example setup failed\r\n");
                return XST_FAILURE;
            }
            // the interruption are not connected in fact.
                XMatrixmul_InterruptGlobalDisable(&XMatrixmul_dev);
                XMatrixmul_InterruptDisable(&XMatrixmul_dev,1);
 
                XMatrixmul_Start(&XMatrixmul_dev);
 
                //flush the cache
                Xil_DCacheFlushRange((u32)A,dma_size);
                Xil_DCacheFlushRange((u32)B,dma_size);
                Xil_DCacheFlushRange((u32)res_hw,dma_size);
                print("\rCache cleared\n\r");
 
                //transfer A to the Vivado HLS block
                    status = XAxiDma_SimpleTransfer(&AxiDma, (u32) A, dma_size, XAXIDMA_DMA_TO_DEVICE);
                    if (status != XST_SUCCESS) {
                        xil_printf("Error: DMA transfer matrix A to Vivado HLS block failed\n");
                        return XST_FAILURE;
                    }
 
                    while (XAxiDma_Busy(&AxiDma, XAXIDMA_DMA_TO_DEVICE)) ;
 
                    //transfer B to the Vivado HLS block
                        status = XAxiDma_SimpleTransfer(&AxiDma, (u32) B, dma_size, XAXIDMA_DMA_TO_DEVICE);
                        if (status != XST_SUCCESS) {
                            xil_printf("Error: DMA transfer matrix B to Vivado HLS block failed\n");
                            return XST_FAILURE;
                        }
                        while (XAxiDma_Busy(&AxiDma, XAXIDMA_DMA_TO_DEVICE)) ;
 
                        //get results from the Vivado HLS block
                            status = XAxiDma_SimpleTransfer(&AxiDma, (mat_a_t) res_hw, dma_size, XAXIDMA_DEVICE_TO_DMA);
                            if (status != XST_SUCCESS) {
                                xil_printf("Error: DMA transfer from Vivado HLS block failed\n");
                                return XST_FAILURE;
                            }
                            while (XAxiDma_Busy(&AxiDma, XAXIDMA_DEVICE_TO_DMA)) ;
 
                            Xil_DCacheFlushRange((u32)res_hw,dma_size);
                            for (i = 0; i < DIM; i++){
                                                            for (j = 0; j < DIM; j++){
                                                                printf("%f\n",(float)res_hw[i][j]);
                                                            }
                                                    }
                            printf("\r Done\n\r");
 
    return 0;
}

 

Hi,

I am glad that it is helpful to you.
For your questions, it seems that you are trying to use a Matrix Multiplication Core (Fixed-Point type) as an Accelarator (IP) and then use SDK (MicroBlaze) to read the output. Correct me if I am not wrong.
In this case, you need to make sure that the fixed point type of your SDK is completely the same as the fixed point library you have in your RTL code for correct writing input to and reading output from the IP core. Otherwise, you need to add some conversion code to the interface to make sure that the fixed point data in core and SDK are not different.
I guess you should run the core alone to see how it work and verify it first. Then you can have a good understanding how to connect it to the SDK.
Hope it helps.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top