Download presentation
Presentation is loading. Please wait.
Published byBeatrix Skinner Modified over 9 years ago
1
C++ Accelerated Massive Parallelism in Visual C++ 2012 Kate Gregory Gregory Consulting www.gregcons.com/kateblog, @gregcons DEV334
3
demo Cartoonizer
6
images source: AMD
9
void AddArrays(int n, int * pA, int * pB, int * pSum) { for (int i=0; i<n; i++) { pSum[i] = pA[i] + pB[i]; } #include using namespace concurrency; void AddArrays(int n, int * pA, int * pB, int * pSum) { array_view a(n, pA); array_view b(n, pB); array_view sum(n, pSum); parallel_for_each( sum.extent, [=](index i) restrict(amp) { sum[i] = a[i] + b[i]; } ); } void AddArrays(int n, int * pA, int * pB, int * pSum) { for (int i=0; i<n; i++) { pSum[i] = pA[i] + pB[i]; }
10
void AddArrays(int n, int * pA, int * pB, int * pSum) { array_view a(n, pA); array_view b(n, pB); array_view sum(n, pSum); parallel_for_each( sum.extent, [=](index i) restrict(amp) { sum[i] = a[i] + b[i]; } ); } array_view variables captured and associated data copied to accelerator (on demand) restrict(amp): tells the compiler to check that this code conforms to C++ AMP language restrictions parallel_for_each: execute the lambda on the accelerator once per thread extent: the number and shape of threads to execute the lambda index: the thread ID that is running the lambda, used to index into data array_view: wraps the data to operate on the accelerator
13
vector v(10); extent e(2,5); array_view a(e, v); //above two lines can also be written //array_view a(2,5,v); index i(1,3); int o = a[i]; // or a[i] = 16; //or int o = a(1, 3);
14
demo Matrix Multiplication
18
vector v(8 * 12); extent e(8,12); accelerator acc = … array a(e,acc.default_view); copy_async(v.begin(), v.end(), a); parallel_for_each(e, [&](index idx) restrict(amp) { a[idx] += 1; }); copy(a, v.begin());
32
http://blogs.msdn.com/nativeconcurrency/
34
Visual Studio Home Page :: http://www.microsoft.com/visualstudio/en-ushttp://www.microsoft.com/visualstudio/en-us Jason Zander’s Blog :: http://blogs.msdn.com/b/jasonz/http://blogs.msdn.com/b/jasonz/ Facebook :: http://www.facebook.com/visualstudiohttp://www.facebook.com/visualstudio Twitter :: http://twitter.com/#!/visualstudiohttp://twitter.com/#!/visualstudio Somasegar’s Blog :: http://blogs.msdn.com/b/somasegar/http://blogs.msdn.com/b/somasegar/
35
Connect. Share. Discuss. http://europe.msteched.com Learning Microsoft Certification & Training Resources www.microsoft.com/learning TechNet Resources for IT Professionals http://microsoft.com/technet Resources for Developers http://microsoft.com/msdn
36
Evaluations http://europe.msteched.com/sessions Submit your evals online
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.