7

C++ AMP では、カーネル関数またはラムダは restrict(amp) でマークされます。これにより、C++ の許可されたサブセット (ここにリストされています)に厳しい制限が課されます。CUDA では、カーネル関数内の C または C++ のサブセットでこれ以上の自由が許可されますか?

4

1 に答える 1

18

Visual Studio 11 および CUDA 4.1 の時点で、restrict(amp)関数は CUDA の類似関数よりも制限が厳しくなってい__device__ます。最も顕著なのは、AMP がポインターの使用方法をより制限していることです。これは、 HLSL (グラフィック シェーダー) コードでポインターを許可しない AMP の DirectX11 計算基板の当然の結果です。対照的に、CUDA の下位レベルの IR はPTXであり、HLSL よりも汎用的です。

行ごとの比較は次のとおりです。

| VS 11 AMP restrict(amp) functions     | CUDA 4.1 sm_2x __device__ functions  |
|------------------------------------------------------------------------------|
|* can only call functions that have    |* can only call functions that have   |
|  the restrict(amp) clause             |  the __device__ decoration           |
|* The function must be inlinable       |* need not be inlined                 |
|* The function can declare only        |* Class types are allowed             |
|  POD variables                        |                                      |
|* Lambda functions cannot              |* Lambdas are not supported, but      |
|  capture by reference and             |  user functors can hold pointers     |
|  cannot capture pointers              |                                      |
|* References and single-indirection    |* References and multiple-indirection |
|  pointers are supported only as       |  pointers are supported              |
|  local variables and function         |                                      |
|* No recursion                         |* Recursion OK                        |
|* No volatile variables                |* Volatile variables OK               |
|* No virtual functions                 |* Virtual functions OK                |
|* No pointers to functions             |* Pointers to functions OK            |
|* No pointers to member functions      |* Pointers to member functions OK     |
|* No pointers in structures            |* Pointers in structures OK           |
|* No pointers to pointers              |* Pointers to pointers OK             |
|* No goto statements                   |* goto statements OK                  |
|* No labeled statements                |* Labeled statements OK               |
|* No try, catch, or throw statements   |* No try, catch, or throw statements  |
|* No global variables                  |* Global __device__ variables OK      |
|* Static variables through tile_static |* Static variables through __shared__ |
|* No dynamic_cast                      |* No dynamic_cast                     |
|* No typeid operator                   |* No typeid operator                  |
|* No asm declarations                  |* asm declarations (inline PTX) OK    |
|* No varargs                           |* No varargs                          |

restrict(amp)の制限について詳しくは、こちらをご覧ください。CUDA 関数の C++ サポートについては、 CUDA C プログラミング ガイド__device__の付録 D を参照してください。

于 2012-03-12T21:04:26.977 に答える