Matrix operations may not be important to most programmers, so the following is a more popular version of AMP:
1 #include <iostream>
2 #include <amp.h>
3
4 int main()
5 {
6 int nickName[6]{'a', 96, 'd', 'r', 'j', 'x'};
7 concurrency::array_view<int> myView(6, nickName);
8 concurrency::parallel_for_each(myView.extent,
9 [=] (concurrency::index<1> idx) restrict(amp)
10 {
11 myView[idx] += 1;
12 }
13 );
14 for(int i = 0; i<6; ++i)
15 std::cout<<(char)myView[i];
16 return 0;
17 }
Do you know what the input is before running? First, let's talk about the meaning of the answer ".
First, you cannot compile it. Because Line 6 uses the initialization method in c ++ 11. By default, compilation fails.
int nickName[6] = {'a', 96, 'd', 'r', 'j', 'x'};
Yes. Currently, vs11 does not support initialize list.
Next, you may ask why nickName is of the int type instead of char type. The most straightforward answer is that array_view does not support char, at least int.
For details, see the statement of array_view:
Template <typename _ Value_type, int _ Rank = 1>
Class array_view: public _ Array_view_base <_ Rank, sizeof (_ Value_type)/sizeof (int)>
{
// The code is omitted for ease of reading
}
As mentioned in the previous article, array_view reiterated that it is similar to an iterator in general. It provides the index interface required for parallel_for_each.
Restrict is a non-reserved character. It only works in the current context. This "prompt" tells the compiler what program the programmer intends to generate. Is it cpu or amp, which means to use the accelerator.
What is an accelerator )? It is another device that supports parallel computing, such as your graphics GPU, and other vector processors that support SIMD, such as those that you use the OS driver to simulate. In addition, the predecessor of the early amp is the string "direct3d", which is now replaced with the amp. Don't be surprised if you see direct3d.
Kernel is the code to run on the accelerator.
In this example, the kernel is as follows:
myView[idx] += 1;
Obviously, it is for all the characters of myNickName + 1. Now you should understand what is output?
The following shows the VS11 support for c ++ 11 (visual studio only $ _ $ ):
C ++ 11 Core Language Features |
VC10 |
VC11 |
Rvalue references v0.1, v1.0, v2.0, v2.1, v3.0 |
V2.0 |
V2.1 * |
Ref-qualifiers |
No |
No |
Non-static data member initializers |
No |
No |
Variadic templates v0.9, v1.0 |
No |
No |
Initializer lists |
No |
No |
Static_assert |
Yes |
Yes |
Auto v0.9, v1.0 |
V1.0 |
V1.0 |
Trailing return types |
Yes |
Yes |
Lambdas v0.9, v1.0, v1.1 |
V1.0 |
V1.1 |
Decltype v1.0, v1.1 |
V1.0 |
V1.1 ** |
Right angle brackets |
Yes |
Yes |
Default template arguments for function templates |
No |
No |
Expression SFINAE |
No |
No |
Alias templates |
No |
No |
Extern templates |
Yes |
Yes |
Nullptr |
Yes |
Yes |
Stronugly typed enums |
Partial |
Yes |
Forward declared enums |
No |
Yes |
Attributes |
No |
No |
Constexpr |
No |
No |
Alignment |
TR1 |
Partial |
Delegating constructors |
No |
No |
Inheriting constructors |
No |
No |
Explicit conversion operators |
No |
No |
Char16_t and char32_t |
No |
No |
Unicode string literals |
No |
No |
Raw string literals |
No |
No |
Universal character names in literals |
No |
No |
User-defined literals |
No |
No |
Standard-layout and trivial types |
No |
Yes |
Defaulted and deleted functions |
No |
No |
Extended friend declarations |
Yes |
Yes |
Extended sizeof |
No |
No |
Inline namespaces |
No |
No |
Unrestricted unions |
No |
No |
Local and unnamed types as template arguments |
Yes |
Yes |
Range-based for-loop |
No |
Yes |
Override and final v0.8, v0.9, v1.0 |
Partial |
Yes |
Minimal GC support |
Yes |
Yes |
Notest |
No |
No |
C ++ 11 Core Language Features: Concurrency |
VC10 |
VC11 |
Reworded sequence points |
N/ |
N/ |
Atomics |
No |
Yes |
Strong compare and exchange |
No |
Yes |
Bidirectional fences |
No |
Yes |
Memory model |
N/ |
N/ |
Data-dependency ordering |
No |
Yes |
Data-dependency ordering: function annotation |
No |
No |
Prediction_ptr |
Yes |
Yes |
Quick_exit and at_quick_exit |
No |
No |
Atomics in signal handlers |
No |
No |
Thread-local storage |
Partial |
Partial |
Magic statics |
No |
No |
C ++ 11 Core Language Features: C99 |
VC10 |
VC11 |
_ Func __ |
Partial |
Partial |
C99 preprocessor |
Partial |
Partial |
Long |
Yes |
Yes |
Extended integer types |
N/ |
N/ |