I've enocuntered a very strange exception when writting code in C++Amp. I define two concurrency::array objects as follows:
concurrency::array<float, 2> img_amp_data(11, 11, image_data.begin());
concurrency::array<float> a_amp_result(121, empty_vec.begin());
When I want to access the elements of the first of them
std::cout << img_amp_data[0][0] << std::endl;
everything runs properly, but when I want to access the second one
std::cout << a_amp_result[0] << std::endl;
I get a following exception:
Exception: (The array is not accessible on CPU)
It is a very odd situatuon because I can access 2+ dimensional arrays and it is forbidden to access only one dimensional array? Any ideas?
You are running into a syntax quirk.
For an
arrayof rank larger than 1,operator[]with integral parameter returns anarray_viewreferring to the slice of the originalarray. The subsequentoperator[]operates on thearray_viewobject, which is allowed on the host -- and in your case causes an implicit data copy before returning a reference to the element.For an
arrayof rank 1operator[]with integral parameter, oroperator[]withindexparameter for anyarray, return a reference to the element. Both are allowed only on the location where thearrayis resident - by default it is the defaultaccelerator_view, however you can request to create thearrayin the CPU memory as well.Unless you want to have fine-grained control on the data movement between the host and the
accelerator_view, it is suggested to use thearray_viewtype ubiquitously.