Created
July 7, 2015 09:52
-
-
Save navyxliu/2d3662df2a0f89d82207 to your computer and use it in GitHub Desktop.
tiling parallel_for_each
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <amp.h> | |
#include <vector> | |
#include <stdlib.h> | |
using namespace Concurrency; | |
using namespace std; | |
const static int DOMAIN_SIZE = 2048; | |
const static int BLOCK_SIZE = 16; | |
void foo() { | |
Concurrency::extent<1> g(DOMAIN_SIZE); | |
vector<int> a(DOMAIN_SIZE); | |
Concurrency::array<int, 1> a_a(g); | |
parallel_for_each(a_a.get_extent().template tile<BLOCK_SIZE>(), [&] (tiled_index<BLOCK_SIZE> idx) restrict(amp) { | |
// parallel_for_each(a_a.get_extent(), [&] (index<1> idx) restrict(amp) { | |
a_a[idx] = 1; | |
}); | |
a = a_a; | |
for (int i=0; i<DOMAIN_SIZE; ++i) { | |
if (a[i] != 1) { | |
fprintf(stderr, "wrong answer idx = %d bad value= %d\n", i, a[i]); | |
exit(-1); | |
} | |
} | |
} | |
int main() { | |
foo(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment