Created
September 25, 2018 10:20
-
-
Save Noxitu/d961889140691693072562eac08e50bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <chrono> | |
int main() | |
{ | |
using namespace std; | |
using namespace std::chrono; | |
using namespace concurrency; | |
constexpr int N = 1024; | |
vector<float> vecA(N*N), vecB(N*N), vecC(N*N); | |
concurrency::extent<2> size(N, N); | |
array_view<const float, 2> A(size, vecA.data()); | |
array_view<const float, 2> B(size, vecB.data()); | |
array_view<float, 2> C(size, vecC.data()); | |
auto before = high_resolution_clock::now(); | |
parallel_for_each(C.extent, [=](index<2> idx) restrict(amp) | |
{ | |
const int y = idx[0]; | |
const int x = idx[1]; | |
float sum = 0; | |
for (int k = 0; k < N; ++k) | |
#if 1 | |
sum += A(y, k) * B(k, x); | |
#else | |
sum += A(y, k) * B(x, k); | |
#endif | |
C[idx] = sum; | |
}); | |
auto mid = high_resolution_clock::now(); | |
C.synchronize(); | |
auto after = high_resolution_clock::now(); | |
cout << duration_cast<duration<float, milli>>(mid-before).count() << "ms" << endl; | |
cout << duration_cast<duration<float, milli>>(after-mid).count() << "ms" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment