Skip to content

[KernelGen][MThreads] Add log10_ Moore Threads specialized operator - #299

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

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

Conversation

@Yukun-Cui

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

Copy link
Copy Markdown
Contributor

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

Summary

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

Testing

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

log10_

dtype Size Torch Latency (ms) Gems Latency (ms) Speedup TFLOPS
float16 4096, 4096 0.061200 0.056880 1.076x 0.295
float16 64, 512, 512 0.055780 0.056400 0.989x 0.297
float16 1024, 65536 0.206600 0.213280 0.969x 0.315
float32 4096, 4096 0.108480 0.106800 1.016x 0.157
float32 64, 512, 512 0.107520 0.105960 1.015x 0.158
float32 1024, 65536 0.414460 0.413960 1.001x 0.162
bfloat16 4096, 4096 0.055520 0.056900 0.976x 0.295
bfloat16 64, 512, 512 0.055840 0.056520 0.988x 0.297
bfloat16 1024, 65536 0.208000 0.213220 0.976x 0.315
Operator Arithmetic Mean Speedup
log10_ 1.00x

Files Changed

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

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

❌ On-demand test failed

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

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

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | log10_:mthreads

1 similar comment
@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | log10_: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. The mthreads ops init.py imports log10_ from both .log10 and .log10_ modules, which could cause confusion. Consider removing the duplicate import from .log10 if log10_ is intended to use the specialized implementation.

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

常数命名 LOG10_2 容易产生歧义,建议改为 LOG10_OF_2 或类似更清晰的名称。Arithmetic Mean Speedup 为 1.00x,几乎没有性能提升,请确认是否需要保留这个特化实现。

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

In init.py, both from .log10 import log10, log10_, log10_out and from .log10_ import log10_ are imported. This creates duplicate imports of log10_ which could be confusing. The specialized backend log10_ should override the default one, but the import order matters. Consider removing log10_ from the log10 import line to make the override explicit.

…it__

The existing log10.py exports log10, log10_ and log10_out; the new
specialized log10_.py also exports log10_. Import log10_ only from the
new specialized module to drop the F811 redefinition.
@Dongxu-H

Copy link
Copy Markdown
Collaborator

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