-
Notifications
You must be signed in to change notification settings - Fork 33
vendor optimize #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vendor optimize #703
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -412,6 +412,56 @@ AddKernelStatePass() = LLVM.NewPMModulePass("AddKernelStatePass", kern_pass) | |||||
| LowerKernelStatePass() = LLVM.NewPMFunctionPass("LowerKernelStatePass", noop_pass) | ||||||
| CleanupKernelStatePass() = LLVM.NewPMModulePass("CleanupKernelStatePass", noop_pass) | ||||||
|
|
||||||
| # From https://github.com/JuliaGPU/GPUCompiler.jl/blob/7b9322faa34685026c4601a5084eecf5a5d7f3fe/src/ptx.jl#L149 | ||||||
| function vendored_optimize_module!(@nospecialize(job), | ||||||
| mod::LLVM.Module, | ||||||
| instcombine::Bool=false | ||||||
| ) | ||||||
| tm = GPUCompiler.llvm_machine(job.config.target) | ||||||
| # TODO: Use the registered target passes (JuliaGPU/GPUCompiler.jl#450) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
giordano marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| LLVM.@dispose pb=LLVM.NewPMPassBuilder() begin | ||||||
| LLVM.register!(pb, GPUCompiler.NVVMReflectPass()) | ||||||
|
|
||||||
| LLVM.add!(pb, LLVM.NewPMFunctionPassManager()) do fpm | ||||||
| # TODO: need to run this earlier; optimize_module! is called after addOptimizationPasses! | ||||||
| LLVM.add!(fpm, GPUCompiler.NVVMReflectPass()) | ||||||
|
|
||||||
| # needed by GemmKernels.jl-like code | ||||||
| LLVM.add!(fpm, LLVM.SpeculativeExecutionPass()) | ||||||
|
|
||||||
| # NVPTX's target machine info enables runtime unrolling, | ||||||
| # but Julia's pass sequence only invokes the simple unroller. | ||||||
| LLVM.add!(fpm, LLVM.LoopUnrollPass(; job.config.opt_level)) | ||||||
| if instcombine | ||||||
| LLVM.add!(fpm, LLVM.InstCombinePass()) # clean-up redundancy | ||||||
| else | ||||||
| LLVM.add!(fpm, LLVM.InstSimplifyPass()) # clean-up redundancy | ||||||
| end | ||||||
| LLVM.add!(fpm, LLVM.NewPMLoopPassManager(; use_memory_ssa=true)) do lpm | ||||||
| LLVM.add!(lpm, LLVM.LICMPass()) # the inner runtime check might be | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||
| # outer loop invariant | ||||||
| end | ||||||
|
|
||||||
| # the above loop unroll pass might have unrolled regular, non-runtime nested loops. | ||||||
| # that code still needs to be optimized (arguably, multiple unroll passes should be | ||||||
| # scheduled by the Julia optimizer). do so here, instead of re-optimizing entirely. | ||||||
| if job.config.opt_level == 2 | ||||||
| LLVM.add!(fpm, LLVM.GVNPass()) | ||||||
| elseif job.config.opt_level == 1 | ||||||
| LLVM.add!(fpm, LLVM.EarlyCSEPass()) | ||||||
| end | ||||||
| LLVM.add!(fpm, LLVM.DSEPass()) | ||||||
|
|
||||||
| LLVM.add!(fpm, LLVM.SimplifyCFGPass()) | ||||||
| end | ||||||
|
|
||||||
| # get rid of the internalized functions; now possible unused | ||||||
| LLVM.add!(pb, LLVM.GlobalDCEPass()) | ||||||
|
|
||||||
| LLVM.run!(pb, mod, tm) | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| # compile to executable machine code | ||||||
| function compile(job) | ||||||
| # lower to PTX | ||||||
|
|
@@ -452,7 +502,7 @@ function compile(job) | |||||
| end | ||||||
| LLVM.run!(pb, mod, tm) | ||||||
| end | ||||||
| GPUCompiler.optimize_module!(job, mod) | ||||||
| vendored_optimize_module!(job, mod) | ||||||
| LLVM.run!(CUDA.GPUCompiler.DeadArgumentEliminationPass(), mod, tm) | ||||||
|
|
||||||
| for fname in ("gpu_report_exception", "gpu_signal_exception") | ||||||
|
|
||||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶