Является ли restrict (amp) более строгим, чем код ядра CUDA? - PullRequest
7 голосов
/ 13 марта 2012

В C ++ AMP функции ядра или лямбды помечены как restrict (amp), что накладывает жесткие ограничения на допустимое подмножество C ++ (, перечисленное здесь ). Позволяет ли CUDA больше свободы для подмножества C или C ++ в функциях ядра?

1 Ответ

18 голосов
/ 13 марта 2012

Начиная с Visual Studio 11 и CUDA 4.1, функции restrict(amp) являются более строгими, чем аналогичные функции __device__ в CUDA.Наиболее заметно, что AMP более ограничен в отношении использования указателей.Это естественное следствие вычислительной основы AMP DirectX11, которая запрещает указатели в коде HLSL (графический шейдер).К слову, IR нижнего уровня CUDA имеет значение 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) здесь .Вы можете прочитать о поддержке C ++ в функциях CUDA __device__ в Приложении D Руководства по программированию CUDA C .

...