Skip to content

Commit

Permalink
[Inductor] add inductor config: masked_vec (pytorch#134566)
Browse files Browse the repository at this point in the history
This PR adds inductor config: masked_vec to control enable/disable masked vectorization for the tail_loop, and enable by default.

Pull Request resolved: pytorch#134566
Approved by: https://github.com/jgong5, https://github.com/jansel
  • Loading branch information
jiayisunx authored and pytorchmergebot committed Aug 29, 2024
1 parent c5f1147 commit cccb121
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 6 additions & 2 deletions torch/_inductor/codegen/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,11 @@ def run(kernel):
)
main_loop.set_kernel(vec_kernel)
main_loop.simd_vec = True
if could_masked_vec and (tail_loop.size - tail_loop.offset) >= 4:
if (
config.cpp.enable_loop_tail_vec
and could_masked_vec
and (tail_loop.size - tail_loop.offset) >= 4
):
tail_loop.steps = tail_loop.size - tail_loop.offset
masked_vec_kernel = codegen_kernel(
CppVecKernel,
Expand Down Expand Up @@ -3818,7 +3822,7 @@ def run(kernel):
)
inner_main_loop.set_kernel(tile2d_kernel)

if could_masked_vec:
if config.cpp.enable_loop_tail_vec and could_masked_vec:
(
inner_main_loop_of_outer_tail_loop,
inner_tail_loop_of_outer_tail_loop,
Expand Down
3 changes: 3 additions & 0 deletions torch/_inductor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,9 @@ class cpp:
# decomposed into 7x4x2 thread blocks along MxNxK of a GEMM.
gemm_thread_factors = os.environ.get("TORCHINDUCTOR_CPP_GEMM_THREAD_FACTORS", None)

# Whether to enable masked vectorization for the tail_loop.
enable_loop_tail_vec = True


# config specific to codegen/triton.py
class triton:
Expand Down

0 comments on commit cccb121

Please sign in to comment.