-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enabled all combinations of pre and post streaming in native cuda template #251
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,3 @@ exclude_patterns: | |
- "**/vendor/" | ||
- "**/*_test.go" | ||
- "**/*.d.ts" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,12 @@ def invoke(simulation): | |
using index_t = int; | ||
using byte_t = unsigned char; | ||
|
||
constexpr inline index_t clamp(index_t x, index_t max) {{ | ||
[[unlikely]] if (x < 0) return x + max; | ||
[[unlikely]] if (x >= max) return x - max; | ||
return x; | ||
}} | ||
|
||
#define d {d} | ||
#define q {q} | ||
#define cs {cs} | ||
|
@@ -157,19 +163,52 @@ def invoke(simulation): | |
#endif | ||
|
||
#if d == 1 | ||
#define node_coord(x_, y_, z_) (x_) | ||
#define node() (index[0]) | ||
#elif d == 2 | ||
#define node() (index[0] * dimension[1] + index[1]) | ||
#elif d == 3 | ||
#define node() ((index[0] * dimension[1] + index[1]) * dimension[2] + index[2]) | ||
#endif | ||
|
||
#if d == 1 | ||
#define distribution(q_) (q_ * dimension[0] + index[0]) | ||
#elif d == 2 | ||
#define node_coord(x_, y_, z_) (x_ * dimension[1] + y_) | ||
#define distribution(q_) ((q_ * dimension[0] + index[0]) * dimension[1] + index[1]) | ||
#elif d == 3 | ||
#define node_coord(x_, y_, z_) ((x_ * dimension[1] + y_) * dimension[2] + z_) | ||
#define distribution(q_) (((q_ * dimension[0] + index[0]) * dimension[1] + index[1]) * dimension[2] + index[2]) | ||
#endif | ||
|
||
#if d == 1 | ||
#define dist_coord(q_, x_, y_, z_) (q_ * dimension[0] + x_) | ||
#define neighbour(q_, sign_) (q_ * dimension[0] + clamp(index[0] sign_ e[q_][0], dimension[0])) | ||
#elif d == 2 | ||
#define dist_coord(q_, x_, y_, z_) ((q_ * dimension[0] + x_) * dimension[1] + y_) | ||
#define neighbour(q_, sign_) ((q_ * dimension[0] + clamp(index[0] sign_ e[q_][0], dimension[0])) * dimension[1] + clamp(index[1] sign_ e[q_][1], dimension[1])) | ||
#elif d == 3 | ||
#define dist_coord(q_, x_, y_, z_) (((q_ * dimension[0] + x_) * dimension[1] + y_) * dimension[2] + z_) | ||
#define neighbour(q_, sign_) (((q_ * dimension[0] + clamp(index[0] sign_ e[q_][0], dimension[0])) * dimension[1] + clamp(index[1] sign_ e[q_][1], dimension[1])) * dimension[2] + clamp(index[2] sign_ e[q_][2], dimension[2])) | ||
#endif | ||
|
||
#define read_(q_) f_reg[q_] = f[dist_index[q_]]; ((void)0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new definitions for reading / writing / streaming |
||
#define write_(q_) f_next[dist_index[q_]] = f_reg[q_]; ((void)0) | ||
#define stream_read_(q_) f_reg[q_] = f[neighbour(q_, -)]; ((void)0) | ||
#define stream_write_(q_) f_next[neighbour(q_, +)] = f_reg[q_]; ((void)0) | ||
|
||
#if {enable_pre_streaming} | ||
#if {support_no_streaming_mask} | ||
#define read(q_) {{ if (no_streaming_mask[dist_index[q_]]) {{ read_(q_); }} else {{ stream_read_(q_); }} }} ((void)0) | ||
#else | ||
#define read(q_) {{ stream_read_(q_); }} ((void)0) | ||
#endif | ||
#else | ||
#define read(q_) {{ read_(q_); }} ((void)0) | ||
#endif | ||
|
||
#if {enable_post_streaming} | ||
#if {support_no_streaming_mask} | ||
#define write(q_) {{ if (no_streaming_mask[dist_index[q_]]) {{ write_(q_); }} else {{ stream_write_(q_); }} }} ((void)0) | ||
#else | ||
#define write(q_) {{ stream_write_(q_); }} ((void)0) | ||
#endif | ||
#else | ||
#define write(q_) {{ write_(q_); }} ((void)0) | ||
#endif | ||
|
||
template<typename scalar_t> | ||
|
@@ -190,6 +229,8 @@ def invoke(simulation): | |
#endif | ||
{kernel_parameter}) | ||
{{ | ||
constexpr index_t e[q][d] = {e}; | ||
constexpr scalar_t w[q] = {w}; | ||
|
||
const index_t index[d] = {{ | ||
static_cast<index_t>(blockIdx.x * blockDim.x + threadIdx.x) | ||
|
@@ -212,27 +253,18 @@ def invoke(simulation): | |
}}; | ||
|
||
#if {support_no_collision_mask} | ||
const index_t node_index = node_coord(index[0], index[1], index[2]); | ||
const index_t node_index = node(); | ||
#endif | ||
|
||
#if {support_no_streaming_mask} | ||
index_t dist_index[q]; | ||
#pragma unroll | ||
for (index_t i = 0; i < q; ++i) {{ | ||
dist_index[i] = dist_coord(i, index[0], index[1], index[2]); | ||
}} | ||
scalar_t f_reg[q]; | ||
#pragma unroll | ||
for (index_t i = 0; i < q; ++i) | ||
f_reg[i] = f[dist_index[i]]; | ||
#else | ||
dist_index[i] = distribution(i); | ||
|
||
scalar_t f_reg[q]; | ||
#pragma unroll | ||
for (index_t i = 0; i < q; ++i) | ||
f_reg[i] = f[dist_coord(i, index[0], index[1], index[2])]; | ||
#endif | ||
|
||
constexpr index_t e[q][d] = {e}; | ||
constexpr scalar_t w[q] = {w}; | ||
read(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key change: simplified template body by shifting the streaming logic into a macro definition |
||
|
||
scalar_t rho = f_reg[0]; | ||
#pragma unroll | ||
|
@@ -264,34 +296,8 @@ def invoke(simulation): | |
{pipeline_buffer} | ||
|
||
#pragma unroll | ||
for (index_t i = 0; i < q; ++i) {{ | ||
|
||
#if {support_no_streaming_mask} | ||
if (no_streaming_mask[dist_index[i]]) | ||
f_next[dist_index[i]] = f_reg[i]; | ||
else | ||
#endif | ||
|
||
{{ | ||
index_t neighbor_x = index[0] + e[i][0]; | ||
if (neighbor_x < 0) neighbor_x += dimension[0]; | ||
else if (neighbor_x >= dimension[0]) neighbor_x -= dimension[0]; | ||
|
||
#if d > 1 | ||
index_t neighbor_y = index[1] + e[i][1]; | ||
if (neighbor_y < 0) neighbor_y += dimension[1]; | ||
else if (neighbor_y >= dimension[1]) neighbor_y -= dimension[1]; | ||
#endif | ||
|
||
#if d > 2 | ||
index_t neighbor_z = index[2] + e[i][2]; | ||
if (neighbor_z < 0) neighbor_z += dimension[2]; | ||
else if (neighbor_z >= dimension[2]) neighbor_z -= dimension[2]; | ||
#endif | ||
|
||
f_next[dist_coord(i, neighbor_x, neighbor_y, neighbor_z)] = f_reg[i]; | ||
}} | ||
}} | ||
for (index_t i = 0; i < q; ++i) | ||
write(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key change: simplified template body by shifting the streaming logic into a macro definition |
||
}} | ||
|
||
void | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new flags for controling the streaming in the generated kernel