Skip to content

Commit 38fb707

Browse files
authored
Add a raw mode to code_sass. (#2019)
Reports exactly what nvdisasm outputs.
1 parent 181d9f5 commit 38fb707

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/compiler/reflection.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ function code_sass_callback(userdata::Ptr{Cvoid}, domain::CUpti_CallbackDomain,
2929
end
3030

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

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

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

0 commit comments

Comments
 (0)