forked from parallel101/course
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "common.h" | ||
|
||
namespace aos_aligned { | ||
|
||
struct Point { | ||
float x; | ||
float y; | ||
float z; | ||
char padding[4]; | ||
}; | ||
|
||
Point ps[N]; | ||
|
||
void compute() { | ||
for (int i = 0; i < N; i++) { | ||
ps[i].x = ps[i].x + ps[i].y + ps[i].z; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "common.h" | ||
|
||
namespace aosoa { | ||
|
||
struct Point { | ||
float x[M]; | ||
float y[M]; | ||
float z[M]; | ||
}; | ||
|
||
Point ps[N / M]; | ||
|
||
void compute() { | ||
for (int i = 0; i < N / M; i++) { | ||
for (int j = 0; j < M; j++) { | ||
ps[i].x[j] = ps[i].x[j] + ps[i].y[j] + ps[i].z[j]; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#pragma once | ||
|
||
#define N (1<<20) | ||
#define N (1<<16) | ||
#define M (1<<4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <cstdint> | ||
#include "common.h" | ||
|
||
namespace soa_size_t { | ||
|
||
struct Point { | ||
float x[N]; | ||
float y[N]; | ||
float z[N]; | ||
}; | ||
|
||
Point ps; | ||
|
||
void compute() { | ||
for (std::size_t i = 0; i < N; i++) { | ||
ps.x[i] = ps.x[i] + ps.y[i] + ps.z[i]; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "common.h" | ||
|
||
namespace soa_unroll { | ||
|
||
struct Point { | ||
float x[N]; | ||
float y[N]; | ||
float z[N]; | ||
}; | ||
|
||
Point ps; | ||
|
||
void compute() { | ||
#if defined(__GNUC__) || defined(__clang__) | ||
#pragma GCC unroll 32 | ||
#elif defined(_MSC_VER) | ||
#pragma unroll 32 | ||
#endif | ||
for (int i = 0; i < N; i++) { | ||
ps.x[i] = ps.x[i] + ps.y[i] + ps.z[i]; | ||
} | ||
} | ||
|
||
} |