[KernelGen][Iluvatar] Add log_normal_ vendor specialization with fused kernel - #112
Merged
Dongxu-H merged 2 commits intoJul 27, 2026
Merged
Conversation
…d kernel Co-authored-by: yzw1128 <yzw1128@users.noreply.github.com>
Co-authored-by: yzw1128 <yzw1128@users.noreply.github.com>
Collaborator
|
/test | log_normal_:iluvatar |
❌ On-demand test failedOperator: The test failed to complete. Check the workflow run for details. |
Collaborator
|
/test | log_normal__vendor_specialization_with_fused_kernel:iluvatar |
❌ On-demand test failedOperator: The test failed to complete. Check the workflow run for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimize
log_normal_operator for Iluvatar backend by fusing Philox random number generation, Box-Muller normal sampling, and log-normal transformation into a single Triton kernel. This eliminates the temporary float32 buffer and halves the kernel launch count compared to the generic two-kernel path.Key optimizations
tl.exp/tl.lognum_stages=1and BLOCK_SIZE ranging from 512 to 32768Correctness Verification
Tested with shape
(10000, 1024)and default parameters (mean=1.0,std=2.0). Expected mean of log-normal distribution:exp(mean + std²/2)= 20.0855.All float16 log-normal values are positive, though some may overflow to inf for large std values due to float16 range limitation (~65504). This is an inherent numerical property of the log-normal distribution, not specific to this implementation.
Performance
Benchmarked on Iluvatar BI-V150 with 36 configurations (3 dtypes × 12 shapes, element counts from 64 to 1B+).
Verification parameters:
CUDA_VISIBLE_DEVICES=6 python3 -m pytest benchmark/test_log_normal_.py -v -s(1073741824,),(64,64),(4096,4096),(64,512,512),(1024,1024,1024),(268435456,),(10000,1),(10000,256),(10000,65536),(100,1,100),(100,256,100),(100,65536,100)torch.float16,torch.float32,torch.bfloat16mean=1.0,std=2.0All 36 test cases show speedup ≥ 1.0. The fused kernel shows consistent gains across all shapes and dtypes, with the greatest benefits on large tensors where the eliminated temporary buffer had the most impact.
Files Changed
src/flag_gems/runtime/backend/_iluvatar/ops/log_normal_.pysrc/flag_gems/runtime/backend/_iluvatar/ops/__init__.pylog_normal_in Iluvatar backend ops (+2 lines)