2012-03-12 12 views
7

In C++ AMP, le funzioni del kernel o lambdas sono contrassegnate con restrizioni (amp), che impone severe restrizioni sul sottoinsieme consentito di C++ (listed here). CUDA consente più libertà sul sottoinsieme di C o C++ nelle funzioni del kernel?La restrizione (amp) è più restrittiva del codice del kernel CUDA?

+1

Può essere correlato alla seguente domanda. http://stackoverflow.com/questions/4899425/what-are-the-real-c-language-constructs-supported-by-cuda-device-code –

+0

Buona domanda, anche se temo che non sia realmente comparabile (forse migrate a programmers.SE?): nvcc non supporta ancora il C++ 11, quindi quando parliamo di lambda voi ovviamente non andate molto lontano! D'altra parte, AMP ha restrizioni completamente diverse, a partire dal fatto che è Microsoft; che (o, forse più correttamente, l'attuale mancanza di un'implementazione non DirectX) lo rende completamente inutilizzabile per molti, ad es. applicazioni scientifiche. Ma suppongo tu intenda solo restrizioni _lingue? – leftaroundabout

+0

@leftaroundabout: Sì, sto solo parlando delle restrizioni _lingua e sto bene con C++ 03. Ho menzionato lambda solo perché è il meccanismo prescritto per l'avvio del codice del kernel con C++ AMP. – Eugene

risposta

18

A partire da Visual Studio 11 e CUDA 4.1, le funzioni restrict(amp) sono più restrittive delle analoghe funzioni di CUDA. Il più notevolmente, AMP è più restrittivo su come i puntatori possono essere usati. Questa è una conseguenza naturale del substrato computazionale DirectX11 di AMP, che non consente l'uso di puntatori nel codice HLSL (shader grafico). Per contrasto, l'IR di livello inferiore di CUDA è PTX, che è più generico di HLSL.

Ecco una linea di confronto riga:

| 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       | 

Si può leggere di più su restrizioni l' restrict(amp)here. È possibile leggere il supporto C++ nelle funzioni CUDA __device__ nell'appendice D dello CUDA C Programming Guide.

+0

IIRC c'è una discussione qui su funzionalità che C++ AMP avrebbe potuto abilitare ma non ha fatto, a volte basate su scelte esplicite per incoraggiare buone pratiche nel calcolo parallelo: http://channel9.msdn.com/Shows/Going+Deep/C- AMP-The-sviluppo-team-tecnico-Tavola rotonda –

Problemi correlati