Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions openequivariance/openequivariance/templates/loop_unroll_tp.cuh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- from 'macros.jinja' import layout_load, layout_store, reg_store with context %}
{%- from 'macros.jinja' import layout_load, layout_store, reg_store,
l2_smem_index with context %}
{%- from 'wmm.cuh' import generate_matmul %}

{%- macro generate_segment_kernel_forward(id, segment, warp_size) %}
Expand Down Expand Up @@ -51,7 +52,7 @@ __device__ __forceinline__ void forward_loop_unroll_{{id}}(IRREP_T* __restrict__

#pragma unroll
for(int j = 0; j < {{L2[v].ir.dim}}; j++)
l2_vec[j] = L2_smem[j + {{L2.slices()[v].start}} + k * {{L2[v].ir.dim}}] * weight;
l2_vec[j] = L2_smem[{{ l2_smem_index(problem.layout, L2[v].mul, L2[v].ir.dim, L2.slices()[v].start, 'k', 'j') }}] * weight;
{%- elif problem.instructions[k].connection_mode == "uvw" %}
{# Stream weights here #}
{%- set slice_size = L3[w].mul * L1[u].mul %}
Expand All @@ -61,7 +62,7 @@ __device__ __forceinline__ void forward_loop_unroll_{{id}}(IRREP_T* __restrict__
}
#pragma unroll
for(int j = 0; j < {{L2[v].ir.dim}}; j++)
l2_vec[j] = L2_smem[j + {{L2.slices()[v].start}} + k * {{L2[v].ir.dim}}];
l2_vec[j] = L2_smem[{{ l2_smem_index(problem.layout, L2[v].mul, L2[v].ir.dim, L2.slices()[v].start, 'k', 'j') }}];
{%- endif %}

// ----------------- CORE CALCULATION -----------------
Expand Down Expand Up @@ -184,11 +185,11 @@ __device__ __forceinline__ void forward_loop_unroll_{{id}}(IRREP_T* __restrict__
{%- if k == 0 or interactions[k][1] != interactions[k-1][1] or L2[v].mul > 1 or L1[u].mul != L1[interactions[k-1][0]].mul %}
#pragma unroll
for(int j = 0; j < {{L2[v].ir.dim}}; j++) {
l2_vec[j] = L2_smem[j + {{L2.slices()[v].start}} + k * {{L2[v].ir.dim}}];
l2_vec[j] = L2_smem[{{ l2_smem_index(problem.layout, L2[v].mul, L2[v].ir.dim, L2.slices()[v].start, 'k', 'j') }}];
l2_grad[j] = 0.0;

{%- if double_bwd %}
l2_original[j] = L2_original[j + {{L2.slices()[v].start}} + k * {{L2[v].ir.dim}}];
l2_original[j] = L2_original[{{ l2_smem_index(problem.layout, L2[v].mul, L2[v].ir.dim, L2.slices()[v].start, 'k', 'j') }}];
{%- endif %}
}
{%- endif %}
Expand Down Expand Up @@ -287,7 +288,7 @@ __device__ __forceinline__ void forward_loop_unroll_{{id}}(IRREP_T* __restrict__
if(lane_id == 0) {
#pragma unroll
for(int j = 0; j < {{L2[v].ir.dim}}; j++)
L2_grad_smem[j + {{L2.slices()[v].start}} + k * {{L2[v].ir.dim}}] += l2_grad[j];
L2_grad_smem[{{ l2_smem_index(problem.layout, L2[v].mul, L2[v].ir.dim, L2.slices()[v].start, 'k', 'j') }}] += l2_grad[j];
}
{%- endif %}

Expand Down
8 changes: 8 additions & 0 deletions openequivariance/openequivariance/templates/macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ Keys map to lists of tuples with (name, dtype, num_elements) of each subarray.
{%- endif %}
{%- endmacro %}

{%- macro l2_smem_index(layout, mul, dim, start, mul_var, dim_var) -%}
{%- if layout == "ir_mul" -%}
{{mul_var}} + {{start}} + {{dim_var}} * {{mul}}
{%- else -%}
{{dim_var}} + {{start}} + {{mul_var}} * {{dim}}
{%- endif -%}
{%- endmacro %}

{%- macro declare_smem_variables(segment, smem_base) %}
{%- for name in segment.smem %}
{%- if name != "total" %}
Expand Down
36 changes: 36 additions & 0 deletions tests/batch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,42 @@ class TestIrMul(TPCorrectness):
internal_weights=False,
label="ir_mul_repr_13x1x13_l535",
),
oeq.TPProblem(
"32x1e",
"3x1e",
"32x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul3_l111",
),
oeq.TPProblem(
"32x1e",
"2x2e",
"32x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul2_l121",
),
oeq.TPProblem(
"16x2e",
"8x2e",
"16x2e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul8_l222",
),
oeq.TPProblem(
"16x1e",
"40x1e",
"16x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul40_l111",
),
]

@pytest.fixture(params=tpps, ids=lambda x: x.label, scope="class")
Expand Down
36 changes: 36 additions & 0 deletions tests/conv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,42 @@ class TestIrMulLayout(ConvCorrectness):
internal_weights=False,
label="ir_mul_repr_13x1x13_l535",
),
oeq.TPProblem(
"32x1e",
"3x1e",
"32x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul3_l111",
),
oeq.TPProblem(
"32x1e",
"2x2e",
"32x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul2_l121",
),
oeq.TPProblem(
"16x2e",
"8x2e",
"16x2e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul8_l222",
),
oeq.TPProblem(
"16x1e",
"40x1e",
"16x1e",
[(0, 0, 0, "uvu", True)],
shared_weights=False,
internal_weights=False,
label="ir_mul_L2mul40_l111",
),
]

@pytest.fixture(params=production_model_tpps, ids=lambda x: x.label, scope="class")
Expand Down
Loading