0

我是 Xilinx 开发的新手,我正在用 zedboard 准备我的硕士学位。我正在尝试使用 Vivado HLS 在 Zedboard 上使用 Opencl 开发卷积加速器。

我创建了 OpenCL 块。

#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#include <clc.h>
__kernel void __attribute__ ((reqd_work_group_size(26,1,1)))
conv_openCL( __global double*a, __global double*c) {
int i = get_global_id(0);
c[i] = a[i] * 2 ;

}

然后我在 Vivado 中使用它来创建架构: 图 1

将其导出到 Vivado SDK 并从此处使用和修改代码后。OpenCL 块没有正确执行,我不知道它的原因。

所以我的问题是为什么当我用 float 或 double 替换 int 类型时,它会给我一个错误。

旧代码:

volatile char *control = (volatile char*)0x43C00000;
volatile int *wg_x   = (volatile int*)0x43C00010;
volatile int *wg_y   = (volatile int*)0x43C00018;
volatile int *wg_z   = (volatile int*)0x43C00020;
volatile int *o_x    = (volatile int*)0x43C00028;
volatile int *o_y    = (volatile int*)0x43C00030;
volatile int *o_z    = (volatile int*)0x43C00038;
volatile int *a_addr = (volatile int*) 0x43C00040;
volatile int *c_addr = (volatile int*)0x43C00048;

...
void main(){
...

int* a;
int*c;

a = (int*)malloc(WG_SIZE_X *sizeof(int));
c = (int*)malloc(WG_SIZE_X *sizeof(int));

*a_addr =(unsigned int)a;
*c_addr =(unsigned int)c;
...




}

我的代码:

volatile char *control = (volatile char*)0x43C00000;
volatile int *wg_x   = (volatile int*)0x43C00010;
volatile int *wg_y   = (volatile int*)0x43C00018;
volatile int *wg_z   = (volatile int*)0x43C00020;
volatile int *o_x    = (volatile int*)0x43C00028;
volatile int *o_y    = (volatile int*)0x43C00030;
volatile int *o_z    = (volatile int*)0x43C00038;
volatile double *a_addr = (volatile double*) 0x43C00040;
volatile double *c_addr = (volatile double*)0x43C00048;

...
void main(){
...

int* a;
int*c;

a = (double*)malloc(WG_SIZE_X *sizeof(double));
c = (double*)malloc(WG_SIZE_X *sizeof(double));

*a_addr =(double)a;
*c_addr =(double)c;
...

}

它给了我这个错误:

错误图像

从“double *”类型到“double”类型的无效转换

请帮帮我,我想将“a”数组的内容传输到 OpenCL 块的“a_addr”数组。

4

1 回答 1

0

您正在尝试将int*, a, 转换为double. 这不能完成,因为指针存储地址 - 整数。

您需要将代码修改为:

volatile double **a_addr = (volatile double**) 0x43C00040;
volatile double **c_addr = (volatile double**)0x43C00048;

...
void main(){
...

double* a;
double* c;

a = (double*)malloc(WG_SIZE_X *sizeof(double));
c = (double*)malloc(WG_SIZE_X *sizeof(double));

*a_addr =a;
*c_addr =c;
...
}

还是您想以与原始代码类似的方式执行此操作:

volatile int *a_addr = (volatile int*) 0x43C00040;
volatile int *c_addr = (volatile int*)0x43C00048;

...
void main(){
...

double* a;
double* c;

a = (double*)malloc(WG_SIZE_X *sizeof(double));
c = (double*)malloc(WG_SIZE_X *sizeof(double));

*a_addr =(int)a;
*c_addr =(int)c;
...
}
于 2020-05-17T02:09:37.683 回答