Skip to content

[KernelGen][MThreads] Add mish_ Moore Threads specialized operator - #296

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

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

Conversation

@Yukun-Cui

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

Copy link
Copy Markdown
Contributor

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

Summary

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

Testing

  • Reused the existing upstream accuracy tests tests/test_mish.py (-m mish_)
  • Validated against reference on the MUSA device; specialization confirmed active via the GEMS_MTHREADS MISH_ 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).

mish_

dtype Size Torch Latency (ms) Gems Latency (ms) Speedup TFLOPS
float16 1073741824 8.436360 6.220120 1.356x 0.173
float16 64, 64 0.010440 0.006160 1.695x 0.001
float16 4096, 4096 0.132160 0.096020 1.376x 0.175
float16 64, 512, 512 0.132160 0.096080 1.376x 0.175
float16 1024, 1024, 1024 8.431400 6.283040 1.342x 0.171
float32 1073741824 6.542440 11.868400 0.551x 0.090
float32 64, 64 0.007560 0.005360 1.410x 0.001
float32 4096, 4096 0.106640 0.193800 0.550x 0.087
float32 64, 512, 512 0.106640 0.193880 0.550x 0.087
float32 1024, 1024, 1024 6.526360 11.907980 0.548x 0.090
bfloat16 1073741824 8.598480 6.172040 1.393x 0.174
bfloat16 64, 64 0.010280 0.006200 1.658x 0.001
bfloat16 4096, 4096 0.134640 0.094680 1.422x 0.177
bfloat16 64, 512, 512 0.134520 0.094160 1.429x 0.178
bfloat16 1024, 1024, 1024 8.597480 6.177200 1.392x 0.174
Operator Arithmetic Mean Speedup
mish_ 1.20x

Files Changed

  • src/flag_gems/runtime/backend/_mthreads/ops/mish_.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 | mish_:mthreads

1 similar comment
@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | mish_:mthreads

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

❌ On-demand test failed

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

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

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | mish_:mthreads

@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.

PR has merge conflicts that must be resolved before merging.

@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.

PR 添加了 mish_.py 文件,但现有的 mish.py 已经包含 mish_ 函数实现,这会导致重复代码和潜在的导入冲突。建议将优化逻辑合并到现有的 mish.py 中而不是创建新文件。

@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.

CI code-style check failed.
init.py imports mish_ twice: line 61 from .mish and line 62 from .mish_. This causes a naming conflict.
float32 performance regression: speedup 0.55x, about 82% slower than generic implementation.

The existing mish.py exports both mish and mish_; the new specialized
mish_.py also exports mish_. Import mish_ only from the new specialized
module to drop the F811 redefinition.
PR flagos-ai#296 moved the in-place mish_ into its own specialized module
mish_.py; the __init__ now imports mish_ only from mish_.py. The
mish_ definition left behind in mish.py is unreachable dead code
(and its default_mish_ import is now unused). Remove it; the shared
mish_kernel / _use_triton_kernel / _launch_mish helpers stay, as they
are still used by mish().
@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | mish_: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