Skip to content

Commit

Permalink
Add a raw mode to code_sass. (#2019)
Browse files Browse the repository at this point in the history
Reports exactly what nvdisasm outputs.
  • Loading branch information
maleadt authored Aug 9, 2023
1 parent 181d9f5 commit 38fb707
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/compiler/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function code_sass_callback(userdata::Ptr{Cvoid}, domain::CUpti_CallbackDomain,
end

"""
code_sass([io], f, types; verbose=false)
code_sass([io], f, types; raw=false)
Prints the SASS code generated for the method matching the given generic function and type
signature to `io` which defaults to `stdout`.
The following keyword arguments are supported:
- `verbose`: enable verbose mode, which displays code generation statistics
- `raw`: dump the assembly like `nvdisasm` reports it, without post-processing;
- all keyword arguments from [`cufunction`](@ref)
See also: [`@device_code_sass`](@ref)
Expand All @@ -52,7 +52,7 @@ end
# multiple subscribers aren't supported, so make sure we only call CUPTI once
const cupti_lock = ReentrantLock()

function code_sass(io::IO, job::CompilerJob; verbose::Bool=false)
function code_sass(io::IO, job::CompilerJob; raw::Bool=false)
if !job.config.kernel
error("Can only generate SASS code for kernel functions")
end
Expand Down Expand Up @@ -97,13 +97,15 @@ function code_sass(io::IO, job::CompilerJob; verbose::Bool=false)

cmd = `$(nvdisasm()) --print-code --print-line-info $cubin_path`
for line in readlines(cmd)
# nvdisasm output is pretty verbose;
# perform some clean-up and make it look like @code_native
line = replace(line, r"/\*[0-9a-f]{4}\*/" => " ") # strip inst addr
line = replace(line, r"^[ ]{30}" => " ") # reduce leading spaces
line = replace(line, r"[\s+]//##" => ";") # change line info tag
line = replace(line, r"^\." => "\n.") # break before new BBs
line = replace(line, r"; File \"(.+?)\", line (\d+)" => s"; Location \1:\2") # rename line info
if !raw
# nvdisasm output is pretty verbose;
# perform some clean-up and make it look like @code_native
line = replace(line, r"/\*[0-9a-f]{4}\*/" => " ") # strip inst addr
line = replace(line, r"^[ ]{30}" => " ") # reduce leading spaces
line = replace(line, r"[\s+]//##" => ";") # change line info tag
line = replace(line, r"^\." => "\n.") # break before new BBs
line = replace(line, r"; File \"(.+?)\", line (\d+)" => s"; Location \1:\2") # rename line info
end
println(io, line)
end
end
Expand Down

0 comments on commit 38fb707

Please sign in to comment.