UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

取消
显示结果 
搜索替代 
您的意思是: 
565 次查看
注册日期: ‎06-03-2015

HLS 2018.2 2次数组打印不一致

转到解答

我用HLS2018.2,定义了2维数组,并初始化。还定义了1个2维数组和3维数组,读外部文件初始化它们。第一个2维数组,2次打印出的数值不一致。

1st printf
coef[0][0]=-4
coef[0][1]=-4
coef[0][2]=-4
coef[1][0]=-4
coef[1][1]=32
coef[1][2]=-4
coef[2][0]=-4
coef[2][1]=-4
coef[2][2]=-4
2nd printf
coef[0][0]=0
coef[0][1]=0
coef[0][2]=-4
coef[1][0]=-4
coef[1][1]=32
coef[1][2]=-4
coef[2][0]=-4
coef[2][1]=-4
coef[2][2]=-4

 

用到代码见附件,主要代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ap_int.h>

typedef ap_uint<8> u8;
typedef ap_int<8> i8;

typedef ap_uint<9> u9;
typedef ap_int<9> i9;

typedef char int8;
typedef short int16;
typedef int int32;

int main()
{
int32 i,j;

const i8 coef[3][3] = {
{-4,-4,-4},
{-4,32,-4},
{-4,-4,-4}
};

int16 temp;
i9 coef1[64][5] ;
i9 coef2[4][64][5] ;
FILE *fid;


printf("1st printf\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("coef[%d][%d]=%d\n", i,j, (int8)coef[i][j]);


}



fid = fopen("coef.txt","r");
if(fid==NULL)
{
printf("open file coef.txt failed!\n");
exit(1);
}

fseek(fid,0,SEEK_SET);
for(i=0;i<64;i++)
{
for(j=0;j<5;j++)
{
fscanf(fid, "%d", &temp);
coef1[i][j] = (i9)temp;
coef2[0][i][j] = (i9)temp;
coef2[1][i][j] = (i9)temp;
coef2[2][i][j] = (i9)temp;
coef2[3][i][j] = (i9)temp;

}
}

fclose(fid);
fid=NULL;


printf("2nd printf\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("coef[%d][%d]=%d\n", i,j, (int8)coef[i][j]);


}




}

0 项奖励
1 个已接受解答

已接受的解答
Highlighted
Xilinx Employee
Xilinx Employee
515 次查看
注册日期: ‎03-24-2010

回复: HLS 2018.2 2次数组打印不一致

转到解答

Change "fscanf(fid, "%d", &temp);" to "fscanf(fid, "%hd", &temp);".

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
3 条回复3
Highlighted
Xilinx Employee
Xilinx Employee
516 次查看
注册日期: ‎03-24-2010

回复: HLS 2018.2 2次数组打印不一致

转到解答

Change "fscanf(fid, "%d", &temp);" to "fscanf(fid, "%hd", &temp);".

Regards,
brucey
----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
477 次查看
注册日期: ‎06-03-2015

回复: HLS 2018.2 2次数组打印不一致

转到解答

Hi Brucey,

按照您的修改,问题的确得到了解决。谢谢了

0 项奖励
475 次查看
注册日期: ‎06-03-2015

回复: HLS 2018.2 2次数组打印不一致

转到解答
Hi Brucey,
按照您的修改,问题得以解决。谢谢
0 项奖励