re-salut,
Bon j'espère avoir une explication rationnelle à mes tests :
après quelque recherches, je suis tombé sur ceci http://developer.intel.com/Assets/PDF/manual/248966.pdf
Je cite quelques passages (3-71):
The efficiency of such optimizations depends on usage patterns. If the elements of the structure are all accessed together but the access pattern of the array is random, then ARRAY_OF_STRUCT avoids unnecessary prefetch even though it wastes memory.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 struct { /* 1600 bytes */ int a, c, e; char b, d; } array_of_struct [100]; struct { /* 1400 bytes */ int a[100], c[100], e[100]; char b[100], d[100]; } struct_of_array;
However, if the access pattern of the array exhibits locality (for example, if the array index is being swept through) then processors with hardware prefetchers will prefetch data from STRUCT_OF_ARRAY, even if the elements of the structure are accessed together.
When the elements of the structure are not accessed with equal frequency, such as when element A is accessed ten times more often than the other entries, then STRUCT_OF_ARRAY not only saves memory, but it also prevents fetching unneces- sary data items B, C, D, and E.
Using STRUCT_OF_ARRAY also enables the use of the SIMD data types by the programmer and the compiler.
quelques sélections entre la page 4-23 et 4-26
For certain algorithms, like 3D transformations and lighting, there are two basic ways to arrange vertex data. The traditional method is the array of structures (AoS) arrangement, with a structure for each vertex (Example 4-13). However this method does not take full advantage of SIMD technology capabilities.
The best processing method for code using SIMD technology is to arrange the data in an array for each coordinate (Example 4-14). This data arrangement is called struc- ture of arrays (SoA).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 typedef struct { float x,y,z; int a,b,c; } Vertex; Vertex Vertices[NumOfVertices];
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 typedef struct { float x[NumOfVertices]; float y[NumOfVertices]; float z[NumOfVertices]; int a[NumOfVertices]; int b[NumOfVertices]; int c[NumOfVertices]; } VerticesList; VerticesList Vertices;
Use of the SoA format for data structures can lead to more efficient use of caches and bandwidth. When the elements of the structure are not accessed with equal frequency, such as when element x, y, z are accessed ten times more often than the other entries, then SoA saves memory and prevents fetching unnecessary data items a, b, and c.
Partager