问题
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.
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?
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.
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.
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:
Answers below:
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).
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;
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.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.
来源:https://stackoverflow.com/questions/29210097/retrieving-values-from-arrayfire-array-as-standard-types-and-serialization