码迷,mamicode.com
首页 > 其他好文 > 详细

Learn ZYNQ (7)

时间:2014-06-28 18:02:29      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:blog   http   文件   art   html   for   

矩阵相乘的例子

参考博客:http://blog.csdn.net/kkk584520/article/details/18812321

MatrixMultiply.c

    typedef int data_type;
    #define N 5

    void MatrixMultiply(data_type AA[N*N],data_type bb[N],data_type cc[N])
    {
        int i,j;
        for(i = 0;i<N;i++)
        {
            data_type sum = 0;
            for(j = 0;j<N;j++)
            {
                sum += AA[i*N+j]*bb[j];
            }
            cc[i] = sum;
        }
    }

修改后:

#include <ap_cint.h>
typedef uint15 data_type;
    #define N 5

    void MatrixMultiply(data_type AA[N*N],data_type bb[N],data_type cc[N])
    {
        int i,j;
        MatrixMultiply_label2:for(i = 0;i<N;i++)
        {
            data_type sum = 0;
            MatrixMultiply_label1:for(j = 0;j<N;j++)
            {
                sum += AA[i*N+j]*bb[j];
            }
            cc[i] = sum;
        }
    }

测试文件:TestMatrixMultiply.c:

#include <stdio.h>
#include <ap_cint.h>
typedef uint15 data_type;
#define N 5
const data_type MatrixA[] = {
    #include "a.h"
};
const data_type Vector_b[] = {
    #include "b.h"
};
const data_type MatlabResult_c[] = {
    #include "c.h"
};
data_type HLS_Result_c[N] = {0};
void CheckResult(data_type * matlab_result,data_type * your_result);

int main(void)
{
	int i;
     printf("Checking Results:\r\n");
     MatrixMultiply(MatrixA,Vector_b,HLS_Result_c);
     CheckResult(MatlabResult_c,HLS_Result_c);
     return 0;
}
void CheckResult(data_type * matlab_result,data_type * your_result)
{
     int i;
     for(i = 0;i<N;i++)
     {
    	 printf("Idx %d: Error = %d \r\n",i,matlab_result[i]-your_result[i]);
     }
}

a.h

{82},  {10},  {16},  {15},  {66},
{91},  {28},  {98},  {43},  {4},
{13},  {55},  {96},  {92},  {85},
{92},  {96},  {49},  {80},  {94},
{64},  {97},  {81},  {96},  {68}

b.h

{76},
{75},
{40},
{66},
{18}

c.h

{9800},
{15846},
{16555},
{23124},
{22939}

d

Learn ZYNQ (7),布布扣,bubuko.com

Learn ZYNQ (7)

标签:blog   http   文件   art   html   for   

原文地址:http://www.cnblogs.com/shenerguang/p/3797144.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!