aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-06-11 21:00:19 +0200
committerAdrian Kummerlaender2019-06-11 21:00:19 +0200
commit4f8e5c51f41b404b7db0df32820d0c68b3b61543 (patch)
tree6fe1ec5c72251d2a25acd678271debacc4770462
parent81b9c7d6541c3c377bfb2332e21ecd71028e5666 (diff)
downloadsymlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar.gz
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar.bz2
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar.lz
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar.xz
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.tar.zst
symlbm_playground-4f8e5c51f41b404b7db0df32820d0c68b3b61543.zip
Move index calculation to compile time
-rw-r--r--codegen_lbm.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/codegen_lbm.py b/codegen_lbm.py
index c1ccd00..3e1865c 100644
--- a/codegen_lbm.py
+++ b/codegen_lbm.py
@@ -50,30 +50,16 @@ collide_opt = cse(collide, optimizations='basic')
kernel = """
__constant float tau = ${tau};
-unsigned int indexOfDirection(int i, int j) {
- return (i+1) + 3*(1-j);
-}
-
-unsigned int indexOfCell(int x, int y)
-{
- return y * ${nX} + x;
-}
-
-unsigned int idx(int x, int y, int i, int j) {
- return indexOfDirection(i,j)*${nCells} + indexOfCell(x,y);
-}
-
-__global float f_i(__global __read_only float* f, int x, int y, int i, int j) {
- return f[idx(x,y,i,j)];
-}
+<%
+def direction_index(c_i):
+ return (c_i[0]+1) + 3*(1-c_i[1])
+%>
__kernel void collide_and_stream(__global __write_only float* f_a,
__global __read_only float* f_b,
__global __read_only int* material)
{
- const unsigned int gid = indexOfCell(get_global_id(0), get_global_id(1));
-
- const uint2 cell = (uint2)(get_global_id(0), get_global_id(1));
+ const unsigned int gid = get_global_id(1)*${nX} + get_global_id(0);
const int m = material[gid];
@@ -82,7 +68,7 @@ __kernel void collide_and_stream(__global __write_only float* f_a,
}
% for i, c_i in enumerate(c):
- const float f_curr_${i} = f_i(f_b, cell.x-(${c_i[0]}), cell.y-(${c_i[1]}), ${c_i[0]}, ${c_i[1]});
+ const float f_curr_${i} = f_b[${direction_index(c_i)*nCells}u + (get_global_id(1)-(${c_i[1]}))*${nX} + get_global_id(0)-(${c_i[0]})];
% endfor
% for i, expr in enumerate(moments_helper):
@@ -114,12 +100,10 @@ __kernel void collide_and_stream(__global __write_only float* f_a,
__kernel void collect_moments(__global __read_only float* f,
__global __write_only float* moments)
{
- const unsigned int gid = indexOfCell(get_global_id(0), get_global_id(1));
-
- const uint2 cell = (uint2)(get_global_id(0), get_global_id(1));
+ const unsigned int gid = get_global_id(1)*${nX} + get_global_id(0);
% for i in range(0,len(c)):
- const float f_curr_${i} = f[${i*nCells} + gid];
+ const float f_curr_${i} = f[${i*nCells}u + gid];
% endfor
% for i, expr in enumerate(moments_helper):