Retrieving values from arrayfire array as standard types and serialization
Asked Answered
S

1

6

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. 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?

  2. 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. 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.

  2. 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?

Seleta answered 23/3, 2015 at 12:21 Comment(0)
I
6

Answers below:

  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).

  2. 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;
    
  3. 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.

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

--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.

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

Impressionist answered 23/3, 2015 at 14:32 Comment(2)
I was just testing trying to write the array to file and what you said in point 3 above does not appear to work.<br/> <br/> array Vdelta = constant(0, dim4(5, 5));<br/> std::cout << Vm << std::endl<br/> <br/> This will not compile. It says that "no operator found which takes a right-hand operand of type 'af::array' (or there is no acceptable conversion)"Seleta
Ah it looks like we missed adding that back. I'm working on it right away. Follow github.com/arrayfire/arrayfire/issues/533Impressionist

© 2022 - 2024 — McMap. All rights reserved.