基本介紹
- 中文名:C++AMP
- 外文名:C++AMP
簡介,特性,系統要求,示範程式,歷史,競爭對手,
簡介
特性
- 代碼可在GPU上調試,亦可在CPU上模擬及調試GPU代碼
系統要求
- 作業系統:Windows 7, Windows 8, Windows Server 2008 R2, 或者Windows Server 2012
- 支持DirectX 11或更新的硬體
示範程式
#include <amp.h> // C++ AMP 頭檔案#include <iostream>using namespace concurrency; //C++ AMP 命名空間const int size = 5; // 定義數組大小void TestCPPAMP() { int aCPU[] = {1, 1, 1, 1, 1}; int bCPU[] = {3, 3, 3, 3, 3}; int cCPU[size]; // 定義C++ AMP封裝對象 array_view<const int, 1> a(size, aCPU); //a是aCPU在並行計算硬體(顯示卡)上的拷貝 array_view<const int, 1> b(size, bCPU); array_view<int, 1> c(size, cCPU); parallel_for_each( // C++ AMP 並行代碼 c.extent, // 定義並行計算的大小 [=](index<1> idx) // [=]是lambda函式中的捕捉從句,index是數組下標 restrict(amp) // 通知編譯器此處為C++ AMP代碼 { c[idx] = a[idx] + b[idx]; } ); // 列印結果 for (int i = 0; i < size; i++) { std::cout << c[i] << "\n"; // 結果應為 4, 4, 4, 4, 4 }}
歷史
C++ AMP的初始版本於2012年發布。2013年,微軟在添加了一些特性後發布了C++ AMP的Microsoft Visual Studio2013版本。