3 ms·
Slides: http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro.pdf http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro... === Code example ===
by palish 15y ago
Slides: http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro.pdf http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro...
=== Code example ===
Original, CPU-only code:
void AddArrays(int n, int * pA, int * pB, int * pC)
{
for (int i=0; i<n; i++)
{
pC[i] = pA[i] + pB[i];
}
}
GPU optimized code:
#include <amp.h>
using namespace concurrency;
void AddArrays(int n, int * pA, int * pB, int * pC)
{
array_view<int,1> a(n, pA);
array_view<int,1> b(n, pB);
array_view<int,1> sum(n, pC);
parallel_for_each(
sum.grid,
[=](index<1> idx) restrict(direct3d)
{
sum[idx] = a[idx] + b[idx];
}
);
}
First impressions: I like it.
- deleted 15y ago[deleted]
- DocSavage 15y agoSeems like it's more focused on multidimensional data compared to Thrust (http://code.google.com/p/thrust/ http://code.google.com/p/thrust/), a C++/STL-like language also for GPU computing. == Compare to Thrust below == #include <thrust/host_vector.h> #include <thrust/device_vector.h> #include <thrust/generate.h> #include <thrust/sort.h> #include <thrust/copy.h> #include <cstdlib> int main(void) { // generate 32M random numbers on the host thrust::host_vector<int> h_vec(32 << 20); thrust::generate(h_vec.begin(), h_vec.end(), rand); // transfer data to the device thrust::device_vector<int> d_vec = h_vec; // sort data on the device (846M keys per second on GeForce GTX 480) thrust::sort(d_vec.begin(), d_vec.end()); // transfer data back to host thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); return 0; }
- wlievens 15y agoWith some decent DFA you can automate this stuff.