-
Notifications
You must be signed in to change notification settings - Fork 57
Add snoopl() to snoop time in LLVM optimization #135
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
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
893d5bd
Add snoopl() to snoop time in LLVM optimization
NHDaly e800692
Comment out version check for snoopl for now, so that we can use it w…
NHDaly 1870b09
Note that the LLVM info function should be YAML
NHDaly e0e46b1
Add parcel_snoopl.jl to read the results of snoopl.
NHDaly cf3c194
Merge branch 'origin/master' into nhd-snoopl
NHDaly 7745459
Add [compat] bounds for CSV,YAML
NHDaly 637f766
Fix version bounds for `snoopl`
NHDaly 1572927
Improve comments and CSV reading
NHDaly 52b2d94
Change read_snoopl to return time in seconds; add tmin_secs filter
NHDaly 31d9869
Add tests for `snoopl`
NHDaly 9cd1ca9
Disable github fail fast
NHDaly bfc2815
Fix uninferrable constructor in src/parcel_snoopl.jl
NHDaly c11f595
Remove TODO(PR) comment after agreeing in PR review
NHDaly bd40036
Remove dep on CSV which was causing problems.
NHDaly 79d4537
Merge branch 'master' into nhd-snoopl
NHDaly 4cd915c
Improve snoopl docstrings / examples
NHDaly 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
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
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| export @snoopl | ||
|
|
||
| using Serialization | ||
|
|
||
| """ | ||
| ``` | ||
| @snoopl "func_names.csv" "llvm_timings.yaml" begin | ||
| # Commands to execute, in a new process | ||
| end | ||
| ``` | ||
| causes the julia compiler to emit the LLVM optimization times for | ||
| of executing the commands to the files "func_names.csv" and "llvm_timings.yaml". These files | ||
| can be used for the input to `SnoopCompile.read_snoopl("func_names.csv", "llvm_timings.yaml")` | ||
| """ | ||
| macro snoopl(flags, func_file, llvm_file, commands) | ||
| return :(snoopl($(esc(flags)), $(esc(func_file)), $(esc(llvm_file)), $(QuoteNode(commands)))) | ||
| end | ||
| macro snoopl(func_file, llvm_file, commands) | ||
| return :(snoopl(String[], $(esc(func_file)), $(esc(llvm_file)), $(QuoteNode(commands)))) | ||
| end | ||
|
|
||
| function snoopl(flags, func_file, llvm_file, commands) | ||
| println("Launching new julia process to run commands...") | ||
| # addprocs will run the unmodified version of julia, so we | ||
| # launch it as a command. | ||
| code_object = """ | ||
| using Serialization | ||
| while !eof(stdin) | ||
| Core.eval(Main, deserialize(stdin)) | ||
| end | ||
| """ | ||
| process = open(`$(Base.julia_cmd()) $flags --eval $code_object`, stdout, write=true) | ||
| serialize(process, quote | ||
| let func_io = open($func_file, "w"), llvm_io = open($llvm_file, "w") | ||
| ccall(:jl_dump_emitted_mi_name, Nothing, (Ptr{Nothing},), func_io.handle) | ||
| ccall(:jl_dump_llvm_opt, Nothing, (Ptr{Nothing},), llvm_io.handle) | ||
| try | ||
| $commands | ||
| finally | ||
| ccall(:jl_dump_emitted_mi_name, Nothing, (Ptr{Nothing},), C_NULL) | ||
| ccall(:jl_dump_llvm_opt, Nothing, (Ptr{Nothing},), C_NULL) | ||
| close(func_io) | ||
| close(llvm_io) | ||
| end | ||
| end | ||
| exit() | ||
| end) | ||
| wait(process) | ||
| println("done.") | ||
| nothing | ||
| end |
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
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """ | ||
| times, info = SnoopCompile.read_snoopl("func_names.csv", "llvm_timings.yaml") | ||
|
|
||
| Reads the log file produced by the compiler and returns the structured representations. | ||
| """ | ||
| function read_snoopl(func_csv_file, llvm_yaml_file; tmin_secs=0.0) | ||
| func_csv = CSV.File(func_csv_file, header=false, delim='\t', types=[String, String]) | ||
| llvm_yaml = YAML.load_file(llvm_yaml_file) | ||
|
|
||
| jl_names = Dict(r[1] => r[2] for r in func_csv) | ||
|
NHDaly marked this conversation as resolved.
Outdated
|
||
|
|
||
| try_get_jl_name(name) = if name in keys(jl_names) | ||
| jl_names[name] | ||
| else | ||
| @warn "Couldn't find $name" | ||
| name | ||
| end | ||
|
|
||
| time_secs(llvm_module) = llvm_module["time_ns"] / 1e9 | ||
|
|
||
| times = [ | ||
| time_secs(llvm_module) => [ | ||
| try_get_jl_name(name) | ||
| for (name,_) in llvm_module["before"] | ||
| ] for llvm_module in llvm_yaml | ||
| if time_secs(llvm_module) > tmin_secs | ||
| ] | ||
|
|
||
| info = Dict( | ||
| try_get_jl_name(name) => (; | ||
| before = (; | ||
| instructions = before_stats["instructions"], | ||
| basicblocks = before_stats["basicblocks"], | ||
| ), | ||
| after = (; | ||
| instructions = after_stats["instructions"], | ||
| basicblocks = after_stats["basicblocks"], | ||
| ), | ||
| ) | ||
| for llvm_module in llvm_yaml | ||
| for (name, before_stats) in llvm_module["before"] | ||
| for (name, after_stats) in llvm_module["after"] | ||
| if time_secs(llvm_module) > tmin_secs | ||
| ) | ||
|
|
||
|
|
||
| # sort times so that the most costly items are displayed last | ||
| return (sort(times), info) | ||
| end | ||
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.
Uh oh!
There was an error while loading. Please reload this page.