@@ -2068,6 +2068,51 @@ macro jit(args...)
2068
2068
# ! format: on
2069
2069
end
2070
2070
2071
+ """
2072
+ @mlir_visualize [optimize = ...] [no_nan = <true/false>] f(args...)
2073
+
2074
+ Runs `@code_hlo` and visualizes the MLIR module using `model-explorer`. This expects the
2075
+ `model-explorer` executable to be in your `PATH`. Installation instructions can be found
2076
+ [here](https://github.com/google-ai-edge/model-explorer).
2077
+ """
2078
+ macro mlir_visualize (args... )
2079
+ default_options = Dict {Symbol,Any} (
2080
+ :optimize => true ,
2081
+ :no_nan => false ,
2082
+ :client => nothing ,
2083
+ :raise => false ,
2084
+ :raise_first => false ,
2085
+ :shardy_passes => :(:to_mhlo_shardings ),
2086
+ :assert_nonallocating => false ,
2087
+ :donated_args => :(:auto ),
2088
+ :transpose_propagate => :(:up ),
2089
+ :reshape_propagate => :(:up ),
2090
+ :optimize_then_pad => true ,
2091
+ :optimize_communications => true ,
2092
+ :cudnn_hlo_optimize => false ,
2093
+ )
2094
+ compile_expr, (; compiled) = compile_call_expr (
2095
+ __module__, compile_mlir, default_options, args...
2096
+ )
2097
+ # ! format: off
2098
+ return esc (
2099
+ :(
2100
+ if Sys. which (" model-explorer" ) === nothing
2101
+ error (" model-explorer is not in your PATH. Please install it from \
2102
+ https://github.com/google-ai-edge/model-explorer" )
2103
+ end ;
2104
+ $ (compile_expr);
2105
+ mlir_mod = $ (first)($ (compiled));
2106
+ tmpfile = tempname () * " .mlir" ;
2107
+ open (tmpfile, " w" ) do io
2108
+ print (io, mlir_mod)
2109
+ end ;
2110
+ run (` model-explorer $(tmpfile) ` )
2111
+ )
2112
+ )
2113
+ # ! format: on
2114
+ end
2115
+
2071
2116
function compile_call_expr (mod, compiler, options:: Dict , args... )
2072
2117
while length (args) > 1
2073
2118
option, args = args[1 ], args[2 : end ]
0 commit comments