共用方式為


限制 (C++ AMP)

限制規範可以套用和 Lambda 函式宣告。 它會強制執行限制在函式的程式碼和函式的行為會使用 C++ Accelerated Massive Parallelism 的應用程式 (C++ AMP) 執行階段。

注意事項注意事項

如需為 __declspec 儲存類別屬性的 restrict 關鍵字的詳細資訊,請參閱 restrict

restrict 子句的格式如下:

子句

描述

restrict(cpu)

函式可以使用完整的 C++ 語言。 宣告的其他函式限制 (cpu) 函式可以呼叫函式。

restrict(amp)

函式只能使用 C++ AMP 可以加速 C++ 語言的子集。

restrict(cpu) 和 restrict(amp)序列。

函式必須遵守 restrict(cpu) 和 restrict(amp)的限制。 函式可由使用 restrict(cpu)、 restrict(amp)、 restrict(cpu, amp)或 restrict(amp, cpu),宣告的函式呼叫。

表單 restrict(A) restrict(B) 可以寫成 restrict(A,B)。

備註

restrict 關鍵字是內容關鍵字。 限制規範、 cpu 和 amp 不是保留字。 規範清單不是可擴充的。 不具 restrict 子句的函式與有 restrict(cpu) 子句的函式。

有 restrict(amp) 子句的函式具有下列限制:

  • 函式會呼叫具有 restrict(amp) 子句只的函式。

  • 函式必須 inlinable。

  • 函式可以宣告 int、 unsigned int、 float和 double 只包含這些型別的變數以及僅限類別和結構。 bool 也允許,不過,必須四位元組對齊時,如果您在複合型別使用。

  • Lambda 函式不是以傳址方式捕捉,且無法擷取指標。

  • 參考和單一間接指標只支援為區域變數,函式引數,並且傳回型別。

  • 下列不允許:

    • 遞迴。

    • 變數宣告使用 volatile 關鍵字。

    • 虛擬函式。

    • 函式的指標。

    • 對成員函式的指標。

    • 在結構的指標。

    • 指標的指標。

    • goto 陳述式。

    • 標記的陳述式。

    • try、 catch或 throw 陳述式。

    • 全域變數。

    • 靜態變數。 請改用 tile_static 關鍵字

    • dynamic_cast 轉型。

    • typeid 運算子。

    • asm 宣告。

    • Varargs。

如需函式限制的討論,請參閱 限制 (amp) 限制

範例

下列範例顯示如何使用 restrict(amp) 子句。

void functionAmp() restrict(amp) {} 
void functionNonAmp() {} 

void callFunctions() restrict(amp) 
{ 
    // int is allowed.
    int x;
    // long long int is not allowed in an amp-restricted function. This generates a compiler error.
    // long long int y; 

    // Calling an amp-restricted function is allowed.
    functionAmp(); 

    // Calling a non-amp-restricted function is not allowed.
    // functionNonAmp(); 

}

請參閱

其他資源

C++ AMP (C++ Accelerated Massive Parallelism)