C ++ AMP, iterating over arrays with different sizes

I am using C ++ AMP with Visual Studio 2012 on Windows 8. I have a case where I have 2D array_view, experimentData and 1D array_view, experimentFactors . I want to iterate over the first size of a 2D array and 1 size of a 1D array_view. This is what I have, but I constantly get errors saying that there are no overloads for this. I want to numberOfTests over numberOfTests , which is the first dimension. I want a line:

 auto test = experimentData[idx]; 

to return the entire row of data. I think the section method on array_view is a way to do this, but I can't figure out how to do this.

 array_view<int_2, 2> experimentData(numberOfTests, numberOfSolutions, initialConditionSet); array_view<float_2, 1> experimentFactors(numberOfTests, factorData); extent<1> e_size(numberOfTests); parallel_for_each(e_size, [=] (index<1> idx) restrict(amp) { auto test = experimentData.section(idx); auto factors = experimentFactors[idx]; analysisAlgorithm(test, factors); }); 

The test object must be a 1xN section of the experimentData array_view . The factors object must be one element of the experimentFactors array_view .

Explanation

experimentData array_view has M rows and N columns

experimentFactors array_view has M rows

+4
source share
1 answer

If you are working in C ++, and you have questions such as this one, or with the processing of projected data in different sizes, stop and read this article:

http://blogs.msdn.com/b/nativeconcurrency/archive/2012/02/17/projections-in-c-amp.aspx

He handles this exact problem in a beautiful way. This is what my parallel_for loop looks like:

 parallel_for_each(e_size, [=] (index<1> idx) restrict(amp) { array_view<int_2, 1> test = experimentData[idx[0]]; auto factors = experimentFactors[idx]; analysisAlgorithm(test, factors); }); 

Notice how the creation of the test array has changed. I maintain that it will be a 1D array of type int_2 . Then I use the forecasting method discussed in the article to select the entire row of data using = experimentData[idx[0]]; . When you point to only one pointer to a multidimensional array, it selects all the data stored in this dimension. The article makes this clearer.

+4
source

All Articles