Zedboard zynq-7000 Opencl 浮点从类型 'double*' 到类型 'double' 的无效转换
Zedboard zynq-7000 Opencl floating point invalid cast from type 'double*' to type 'double'
我是 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 中使用它来创建架构:
Image 1
将其导出到 Vivado SDK 并使用和修改 here 中的代码后。 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;
...
}
它给我这个错误:
Error Image
从类型 'double*' 到类型 'double'
的强制转换无效
请帮助我,我想将 "a" 数组的内容传输到 OpenCL 块的 "a_addr" 数组。
您正在尝试将 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;
...
}
我是 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 中使用它来创建架构: Image 1
将其导出到 Vivado SDK 并使用和修改 here 中的代码后。 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;
...
}
它给我这个错误:
Error Image
从类型 'double*' 到类型 'double'
的强制转换无效请帮助我,我想将 "a" 数组的内容传输到 OpenCL 块的 "a_addr" 数组。
您正在尝试将 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;
...
}