HLS实现浮点数乘法

HLS Code

编写HLS代码如下

#include
float float_test(volatile float *src1,volatile float *src2,volatile float *dest){
#pragma HLS INTERFACE m_axi depth=10 port=src1 offset=slave bundle=MASTER_BUS1
#pragma HLS INTERFACE m_axi depth=10 port=src2 offset=slave bundle=MASTER_BUS2
#pragma HLS INTERFACE m_axi depth=10 port=dest offset=slave bundle=MASTER_BUS3
#pragma HLS INTERFACE s_axilite port=return bundle=CRTL_BUS
float buff1[10];
float buff2[10];
float buff3[10];
memcpy(buff1,(const float*)src1,10*sizeof(float));
memcpy(buff2,(const float*)src2,10*sizeof(float));
int i;
for(i=0;i<10;i++){
	buff3[i]=buff1[i]*buff2[i];
}
memcpy((float*)dest,(const float*)buff3,10*sizeof(float));
return buff1[0]*buff2[0];
}



Block Design

HLS实现浮点数乘法_第1张图片

SDK代码

#include 
#include
#include "platform.h"
#include "xil_printf.h"
#include "xfloat_test_hw.h"
#include "xfloat_test.h"
int main()
{
    init_platform();
    Xil_DCacheDisable();
    int i;
    float arr1[10]={1.2,1.1,0.5,4.5,3.2,-0.8,-2.5,1.6,3.5,7.8};
    float arr2[10]={1.3,2.2,0.4,3.3,2.2,-8.5,0.8,2.2,3.3,4.4};
    for(i=0;i<10;i++){
    	Xil_Out32(XPAR_PS7_DDR_0_S_AXI_BASEADDR+i*4,*((u32*)&arr1[i]));
        Xil_Out32(XPAR_PS7_DDR_0_S_AXI_BASEADDR+i*4+40,*((u32*)&arr2[i]));
    }
    for(i=0;i<10;i++)
    {
        u32 rev1=Xil_In32(XPAR_PS7_DDR_0_S_AXI_BASEADDR+i*4);
        printf("%f\n",*((float*)&rev1));
    }
    printf("***************************************\n");
    for(i=0;i<10;i++)
        {
            u32 rev2=Xil_In32(XPAR_PS7_DDR_0_S_AXI_BASEADDR+i*4+40);
            printf("%f\n",*((float*)&rev2));
        }
    XFloat_test HlsXfloat_test;
    XFloat_test_Config *ExamplePtr;
    printf("Look Up the device configuration.\n");
    ExamplePtr = XFloat_test_LookupConfig(XPAR_FLOAT_TEST_0_DEVICE_ID);
    if (!ExamplePtr) {
    printf("ERROR: Lookup of accelerator configuration failed.\n\r");
    return XST_FAILURE;
    }
    printf("Initialize the Device\n");
    long status = XFloat_test_CfgInitialize(&HlsXfloat_test, ExamplePtr);
    if (status != XST_SUCCESS) {
    printf("ERROR: Could not initialize accelerator.\n\r");
    return(-1);
    }
    XFloat_test_Set_src1(&HlsXfloat_test,XPAR_PS7_DDR_0_S_AXI_BASEADDR);
    XFloat_test_Set_src2(&HlsXfloat_test,XPAR_PS7_DDR_0_S_AXI_BASEADDR+40);
    XFloat_test_Set_dest(&HlsXfloat_test,XPAR_PS7_DDR_0_S_AXI_BASEADDR+80);
    XFloat_test_Start(&HlsXfloat_test);
    while (XFloat_test_IsDone(&HlsXfloat_test) == 0);


    for(i=0;i<10;i++){
        	u32 rev=Xil_In32(XPAR_PS7_DDR_0_S_AXI_BASEADDR+4*i+80);
        	printf("%f\n",*((float*)&rev));
        }
    u32 r=XFloat_test_Get_return(&HlsXfloat_test);
    printf("*****************************\n");
    printf("%f\n",*((float*)&r));
    cleanup_platform();
    return 0;
}

运行结果

HLS实现浮点数乘法_第2张图片

你可能感兴趣的:(HLS实现浮点数乘法)