Skip to content

[KernelGen][MThreads] Add silu_backward Moore Threads specialized operator - #295

Open
Yukun-Cui wants to merge 2 commits into
flagos-ai:infra-cifrom
Yukun-Cui:pr/mthreads-silu_backward
Open

[KernelGen][MThreads] Add silu_backward Moore Threads specialized operator#295
Yukun-Cui wants to merge 2 commits into
flagos-ai:infra-cifrom
Yukun-Cui:pr/mthreads-silu_backward

Conversation

@Yukun-Cui

@Yukun-Cui Yukun-Cui commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

[KernelGen][MThreads] Add silu_backward Moore Threads specialized operator

Summary

Add a Moore Threads (MUSA) specialized Triton kernel for silu_backward, overriding the generic
implementation via runtime.replace_customized_ops(). Implements the silu backward operation.

Testing

  • Reused the existing upstream accuracy tests tests/test_silu.py (-m silu_backward)
  • Validated against reference on the MUSA device; specialization confirmed active via the
    GEMS_MTHREADS SILU_BACKWARD debug log
  • Falls back to the generic implementation for unsupported dtype/device/shape
    (fp64/int64 are not supported on Moore Threads hardware)

Performance

Compared against the generic FlagGems implementation on Moore Threads (MUSA).

silu_backward

dtype Size Torch Latency (ms) Gems Latency (ms) Speedup TFLOPS
float16 1073741824 4.484840 4.669640 0.960x 0.230
float16 64, 64 0.006560 0.003040 2.158x 0.001
float16 4096, 4096 0.109920 0.105760 1.039x 0.159
float16 64, 512, 512 0.110280 0.106560 1.035x 0.157
float16 1024, 1024, 1024 4.480120 4.618220 0.970x 0.233
float32 1073741824 9.036880 9.022460 1.002x 0.119
float32 64, 64 0.005560 0.008680 0.641x 0.000
float32 4096, 4096 0.187520 0.180520 1.039x 0.093
float32 64, 512, 512 0.187720 0.180560 1.040x 0.093
float32 1024, 1024, 1024 9.038420 9.009620 1.003x 0.119
bfloat16 1073741824 4.474480 4.788980 0.934x 0.224
bfloat16 64, 64 0.006800 0.003400 2.000x 0.001
bfloat16 4096, 4096 0.110040 0.108120 1.018x 0.155
bfloat16 64, 512, 512 0.110480 0.109000 1.014x 0.154
bfloat16 1024, 1024, 1024 4.467360 4.682340 0.954x 0.229
Operator Arithmetic Mean Speedup
silu_backward 1.12x

Files Changed

  • src/flag_gems/runtime/backend/_mthreads/ops/silu_backward.py: Moore Threads Triton kernel + fallback
  • src/flag_gems/runtime/backend/_mthreads/ops/__init__.py: Register import and __all__

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | silu_backward:mthreads

1 similar comment
@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | silu_backward:mthreads

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

❌ On-demand test failed

Operator: | silu_backward
Runner: mthreads
Backend: mthreads-musa520

The test failed to complete. Check the workflow run for details.

@Dongxu-H Dongxu-H left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dongxu-H Dongxu-H left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | silu_backward:mthreads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants