通过 host() 从 af::array 检索数据会导致错误的数据
Retrieving data from af::array via host() results in wrong data
当尝试通过host()
从设备从af::array
(arrayfire(检索数据时,我在主机上的输出数据是错误的(即错误的值(。为了测试这一点,我编写了一个小代码示例(基于 https://stackoverflow.com/a/29212923/2546099(:
int main(void) {
size_t vector_size = 16;
af::array in_test_array = af::constant(1., vector_size), out_test_array = af::constant(0., vector_size);
af_print(in_test_array);
double *local_data_ptr = new double[vector_size]();
for(int i = 0; i < vector_size; ++i)
std::cout << local_data_ptr[i] << 't';
std::cout << 'n';
in_test_array.host(local_data_ptr);
for(int i = 0; i < vector_size; ++i)
std::cout << local_data_ptr[i] << 't';
std::cout << 'n';
delete[] local_data_ptr;
out_test_array = in_test_array;
af_print(out_test_array);
return 0;
}
我的输出是
in_test_array
[16 1 1 1]
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0.007813 0.007813 0.007813 0.007813 0.007813 0.007813 0.007813 0.007813 0 0 0 0 0 0 0 0
out_test_array
[16 1 1 1]
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
为什么指针中的一半值设置为0.007813
,而不是所有值都设置为1
?将in_test_array
的默认值更改为2
时,一半的值设置为2
,对于3
,这些值设置为32
。为什么会这样?
arrayfire 和 C 之间的数据类型是冲突的。
浮子使用:
af::array in_test_array = af::constant(1., vector_size),
out_test_array = af::constant(0., vector_size);
float *local_data_ptr = new float[vector_size]();
双重使用:
af::array in_test_array = af::constant(1., vector_size, f64),
out_test_array = af::constant(0., vector_size, f64)
double *local_data_ptr = new double[vector_size]();
在上述两种情况下,您都会看到 ARRAYFIRE 将在 local_data_ptr 缓冲区中返回 1.0,尽管数据类型不同。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 使用 char* 存储数据和产生的错误
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 创建服务失败0x6f7存根收到错误数据
- 通过 host() 从 af::array 检索数据会导致错误的数据
- OpenCV C++ 3 维垫数据访问错误值
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- 错误 - 自定义数据类型作为有效负载,带有提升::几何
- 类方法 - 数据结构中 For 循环的运行时错误
- 从文件中读取的数据,但发生核心转储错误
- 如果在 C++ 构造函数中以错误的顺序初始化对象数据,会发生什么类型的错误
- 删除使数据处于"错误状态"的默认构造函数的模式?
- 服务器客户端通过原始数据错误C 发送接收结构
- 对象无法访问其私人数据.错误:在这种情况下私有
- SVM训练数据错误
- 库单元测试的覆盖率数据错误
- Unix套接字发送接收客户端到服务器大块数据错误
- 无法通过windows UDP套接字发送数据:错误代码10035
- 着色器存储缓冲区发送的数据错误