Reputation: 4315
I am using C++ AMP with Visual Studio 2012 on Windows 8. I have a case where I have 2D array_view, experimentData
and a 1D array_view, experimentFactors
. I want to iterate over the first dimension of the 2D array_view and the 1 dimension of the 1D array_view. This is what I have but I constantly get errors saying there aren't overloads for this. I am wanting to iterate over the numberOfTests
which is the first dimension. I am wanting the line:
auto test = experimentData[idx];
to return the entire row of data. I think the section
method on the array_view
is the way to do this but I can't figure out how.
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 should be a 1xN section of the experimentData
array_view
. The factors
object should be a single item from the experimentFactors
array_view
.
Clarification
The experimentData
array_view has M rows and N columns
The experimentFactors
array_view has M rows
Upvotes: 4
Views: 844
Reputation: 4315
If you are someone working on C++ and you have questions like this one or with dealing projecting data to different dimensions stop and read this article:
http://blogs.msdn.com/b/nativeconcurrency/archive/2012/02/17/projections-in-c-amp.aspx
It deals with this exact problem in a beautiful way. Here is what my parallel_for loop looks like now:
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 state that it is going to be a 1D array of type int_2
. Then I use the projection technique discussed in the article to select the entire row of data with = experimentData[idx[0]];
. When you only give one index to a multidimensional array it selects all of the data held within that dimension. The article makes this clearer.
Upvotes: 4