从arrayfire数组中检索值作为标准类型和序列化 [英] Retrieving values from arrayfire array as standard types and serialization

查看:71
本文介绍了从arrayfire数组中检索值作为标准类型和序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在GTC看到了arrayfire的表演,我想我会尝试的.这是我在尝试使用它时遇到的一些问题.我正在使用AMD App SDK 2.9-1中的OpenCL在Windows 7系统上运行Visual Studio 2013.

I recently saw arrayfire demonstrated at GTC and I thought I would try it. Here are some questions I have run into while trying to use it. I am running Visual Studio 2013 on a Windows 7 system with OpenCL from the AMD App SDK 2.9-1.

  1. 最大的麻烦是,我无法在调试器中查看数组对象的状态以查看其中的数据.我必须依靠af_print语句.太烦人了.有什么方法可以配置调试器,让我无需打印就可以查看阵列中的数据?

  1. The biggest frustration is that I cannot view the state of array objects in the debugger to see what data is in it. I must rely on the af_print statement. That is very annoying. Is there any way to configure the debugger to let me see the data in the array without having to print it out?

一旦我将数据存储在数组中,如何将值作为标准数据类型取回.一个例子如下所示.我正在尝试将元素5,0作为双精度值.该示例中的行不起作用,并且我无法将其强制转换为任何标准类型.我唯一可以将其分配给另一个数组.如何取回我的数据?

Once I have my data in an array, how do I get back values as standard data types. An example is shown below. I am trying to get back element 5,0 as a double. The line in the example does not work, and I cannot cast it to any standard type. The only thing I can assign it to is another array. How do I get my data back out?

    array test = constant(0, dim4(10, 2));
    test(span, 1) = 10.5;
    double val = test(5, 0);  //This does not compile. 

  1. 是否有一种简便的方法可以将阵列序列化/反序列化到磁盘?我没有找到执行此操作的方法,并且由于无法将值作为标准类型返回,因此我不确定如何保存它.

  1. Is there an easy way to serialize/deserialize an array to disk? I did not see a way to do this, and since I cannot get the values back out as standard types I am unsure how to save it out.

我正在查看您提供的降雨教程示例,但是似乎给出了错误的结果.例如,第52行的打印语句为"af_print(rainfall);".应该打印出每个站点的降雨量,但是其中包含所有8个数字,这是不正确的.我在cpu和opencl版本中都尝试了此操作,并得到了相同的结果.其他一些计算也不正确.代码看起来应该是正确的,所以这是错误还是代码错误?

I was going through the rainfall tutorial sample you provide, but it appears to give incorrect results. For instance, line 52 has this print statement "af_print(rainfall);." It is supposed to print out the rainfall per site, but it has all 8's in it, which is not correct. I tried this with both the cpu and opencl versions and got the same results. A few of the other calculations are incorrect as well. The code looks like it be should be correct, so is this a bug or is the code wrong?

推荐答案

以下答案:

  1. 由于ArrayFire的所有数据都位于GPU上,因此无法在VS调试器上显示出来(没有涉及NSight或其他调试工具的更先进的技术).另一种方法是将数据取回主机,然后在调试器中进行检查(如答案2所示).

  1. Because all of ArrayFire's data resides on the GPU, it is not possible to show this on the VS debugger (without much more advance techniques that would involve NSight or other debugging tools). The alternate is to fetch the data back to the host and then check it in the debugger (as in answer 2).

host()函数允许您将数据检索回主机.有两种方法可以做到这一点:

The host() function allows you to retrieve the data back to host. There are 2 ways of doing this:

// Type 1
array a = randu(3, f32);
float *host_a = a.host<float>();        // must call array::free() later
printf("host_a[2] = %f\n", host_a[2]);  // last element
af::freeHost(host_a);

// Type 2
array a = randu(3, f32);
float *host_a = new float[3];
a.host(host_a);
printf("host_a[2] = %f\n", host_a[2]);  // last element
delete [] host_a;

  • <<(ostream运算符)对于数组和dim4重载.因此,执行 std :: cout<<数组<<std :: endl; 将显示在屏幕上.fstream对象也可以使用相同的方法.

  • The << (ostream operator) is overloaded for arrays and dim4. So doing std::cout << array << std::endl; would print to screen. The same can be used with fstream objects.

    我们正在调查降雨,并且会回来.该问题应在今天解决.请留意我们的github页面.

    We're looking into rainfall and will get back. This should be fixed today. Keep a watch on our github page.

    -编辑-4. https://github.com/arrayfire/arrayfire/解决了降雨中出现的问题拉/531 .我们将很快发布新的版本.

    --Edit-- 4. The problem seen in rainfall has been fixed by https://github.com/arrayfire/arrayfire/pull/531. We will be releasing a new build out soon.

    将af :: free更改为af :: freeHost,以删除由ArrayFire分配的主机内存.

    Edit 2: Change af::free to af::freeHost to delete host memory allocated by ArrayFire.

    这篇关于从arrayfire数组中检索值作为标准类型和序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆