2012-03-12 2 views
7

C++ AMP에서 커널 함수 또는 람다는 restrict (amp)로 표시되며 C++의 허용 된 하위 집합 (listed here)에 심각한 제한을 적용합니다. CUDA는 커널 기능에서 C 또는 C++의 하위 집합에 대해 더 많은 자유를 허용합니까?CUDA 커널 코드보다 restrict (amp)가 더 제한적입니까?

+1

다음 질문과 관련이있을 수 있습니다. http://stackoverflow.com/questions/4899425/what-are-the-real-c-language-constructs-supported-by-cuda-device-code –

+0

좋은 질문입니다. 실제로는 그렇지 않습니다. 프로그래머로 마이그레이션하십시오 .SE?) : nvcc는 C++ 11을 아직 지원하지 않으므로 람다에 관해 말할 때 분명히 멀리 떨어져 있지 않습니다. 반면에 AMP는 완전히 다른 제약을 가지고 있습니다. DirectX 구현이 아닌 현재의 부족으로 인해 많은 사람들이 완전히 사용할 수 없게됩니다. 과학적 응용. 하지만 당신은 _language_ 제한만을 의미한다고 생각합니까? – leftaroundabout

+0

@leftaroundabout : 예, _language_ 제한 사항에 대해서만 말씀 드리며 C++ 03 내에서 사용하는 것이 좋습니다. C++ AMP로 커널 코드를 시작하기위한 규정 된 메커니즘이기 때문에 lambdas에 대해서만 언급했습니다. – Eugene

답변

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)의 제한 here에 대한 자세한 내용을보실 수 있습니다 :

여기에 라인 비교하여 라인입니다. CUDA __device__ 함수의 C++ 지원은 부록 D의 CUDA C Programming Guide에서 읽을 수 있습니다.

+0

IIRC 여기에는 C++ AMP가 활성화 할 수 있었지만하지 못했던 기능에 대한 설명이 있습니다. 병렬 컴퓨팅의 우수 사례를 장려하기위한 명시 적 선택에 기반하고 있습니다. http://channel9.msdn.com/Shows/Going+Deep/C- AMP - 개발 - 팀 - 기술 - 원탁 –