Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
aff10174
Commit
aff10174
authored
Apr 06, 2022
by
umangyadav
Browse files
dump IR passes into seperate files, dump modules passes into seperate directories
parent
671f24be
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
45 additions
and
38 deletions
+45
-38
src/CMakeLists.txt
src/CMakeLists.txt
+0
-3
src/include/migraphx/program.hpp
src/include/migraphx/program.hpp
+1
-1
src/include/migraphx/tracer.hpp
src/include/migraphx/tracer.hpp
+18
-11
src/pass_manager.cpp
src/pass_manager.cpp
+18
-14
src/program.cpp
src/program.cpp
+3
-4
src/quantization.cpp
src/quantization.cpp
+1
-1
src/targets/cpu/include/migraphx/cpu/lowering.hpp
src/targets/cpu/include/migraphx/cpu/lowering.hpp
+1
-1
src/targets/gpu/include/migraphx/gpu/lowering.hpp
src/targets/gpu/include/migraphx/gpu/lowering.hpp
+1
-1
src/targets/ref/include/migraphx/ref/lowering.hpp
src/targets/ref/include/migraphx/ref/lowering.hpp
+1
-1
test/verify/run_verify.cpp
test/verify/run_verify.cpp
+1
-1
No files found.
src/CMakeLists.txt
View file @
aff10174
...
...
@@ -201,10 +201,7 @@ rocm_install_targets(
)
check_cxx_linker_flag
(
-lstdc++fs HAS_LIB_STD_FILESYSTEM
)
if
(
HAS_LIB_STD_FILESYSTEM
)
target_link_libraries
(
migraphx PRIVATE -lstdc++fs
)
endif
()
target_link_libraries
(
migraphx PRIVATE -ldl
)
...
...
src/include/migraphx/program.hpp
View file @
aff10174
...
...
@@ -61,7 +61,7 @@ struct program
instruction_ref
validate
()
const
;
void
compile
(
const
target
&
t
,
compile_options
options
=
compile_options
{});
void
compile
(
const
target
&
t
,
compile_options
options
=
compile_options
{}
,
std
::
string
ir_dump_path
=
"passes"
);
bool
is_compiled
()
const
;
...
...
src/include/migraphx/tracer.hpp
View file @
aff10174
#ifndef MIGRAPHX_GUARD_RTGLIB_TRACER_HPP
#define MIGRAPHX_GUARD_RTGLIB_TRACER_HPP
#include <
o
stream>
#include <
f
stream>
#include <migraphx/functional.hpp>
#include <migraphx/config.hpp>
#include <migraphx/filesystem.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
...
@@ -12,24 +12,31 @@ struct tracer
{
tracer
()
{}
tracer
(
std
::
o
str
eam
&
s
)
:
os
(
&
s
)
{}
tracer
(
std
::
str
ing
dump_directory
)
:
dump_dir
(
dump_directory
),
counter
(
0
)
{}
bool
enabled
()
const
{
return
os
!=
nullptr
;
}
bool
enabled
()
const
{
return
!
dump_dir
.
empty
()
;
}
template
<
class
...
Ts
>
void
operator
()(
const
Ts
&
...
xs
)
const
{
if
(
os
!=
nullptr
)
void
operator
()(
const
std
::
string
&
program_name
,
const
Ts
&
...
xs
)
{
swallow
{
*
os
<<
xs
...};
*
os
<<
std
::
endl
;
if
(
this
->
enabled
())
{
fs
::
path
dir_path
=
fs
::
current_path
()
/
this
->
dump_dir
;
if
(
not
fs
::
exists
(
dir_path
))
{
fs
::
create_directories
(
dir_path
);
}
fs
::
path
ir_file_path
=
dir_path
/
(
std
::
to_string
(
this
->
counter
++
)
+
"_"
+
program_name
+
".mxr"
);
std
::
ofstream
ofs
(
ir_file_path
);
swallow
{
ofs
<<
xs
...};
ofs
<<
std
::
endl
;
ofs
.
close
();
}
}
std
::
string
dump_dir
;
private:
std
::
ostream
*
os
=
nullpt
r
;
uint
counte
r
;
};
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
...
...
src/pass_manager.cpp
View file @
aff10174
...
...
@@ -10,6 +10,7 @@
#include <iostream>
#include <sstream>
#include <algorithm>
#include <unordered_map>
#include <utility>
namespace
migraphx
{
...
...
@@ -17,13 +18,12 @@ inline namespace MIGRAPHX_INLINE_NS {
MIGRAPHX_DECLARE_ENV_VAR
(
MIGRAPHX_TRACE_PASSES
);
void
validate_pass
(
module
&
mod
,
const
pass
&
p
,
tracer
trace
)
void
validate_pass
(
module
&
mod
,
const
pass
&
p
)
{
(
void
)
mod
;
(
void
)
p
;
(
void
)
trace
;
#ifndef NDEBUG
trace
(
"Validate
..."
)
;
std
::
cout
<<
"Validate..."
<<
std
::
endl
;
auto
invalid
=
mod
.
validate
();
if
(
invalid
!=
mod
.
end
())
{
...
...
@@ -31,14 +31,13 @@ void validate_pass(module& mod, const pass& p, tracer trace)
MIGRAPHX_THROW
(
p
.
name
()
+
" pass produces invalid program at instruction "
+
std
::
to_string
(
index
)
+
": "
+
invalid
->
name
());
}
trace
();
#endif
}
void
run_pass
(
program
&
prog
,
const
pass
&
p
,
tracer
trace
)
void
run_pass
(
program
&
prog
,
const
pass
&
p
,
tracer
&
trace
)
{
trace
(
"Pass: "
,
p
.
name
());
p
.
apply
(
prog
);
trace
(
prog
);
trace
(
p
.
name
(),
prog
);
}
struct
module_pm
:
module_pass_manager
...
...
@@ -72,11 +71,10 @@ struct module_pm : module_pass_manager
virtual
void
run_pass
(
const
pass
&
p
)
override
{
assert
(
mod
);
trace
(
"Module: "
,
mod
->
name
(),
", Pass: "
,
p
.
name
());
assert
(
mod
->
validate
()
==
mod
->
end
());
p
.
apply
(
*
this
);
trace
(
*
mod
);
validate_pass
(
*
mod
,
p
,
*
t
);
trace
(
p
.
name
(),
*
mod
);
validate_pass
(
*
mod
,
p
);
}
};
...
...
@@ -85,7 +83,7 @@ module& get_module(module_pass_manager& mpm) { return mpm.get_module(); }
void
run_passes
(
module
&
mod
,
const
std
::
vector
<
pass
>&
passes
,
tracer
trace
)
{
if
(
enabled
(
MIGRAPHX_TRACE_PASSES
{}))
trace
=
tracer
{
std
::
cout
};
trace
=
tracer
{
mod
.
name
()
+
"_passes"
};
for
(
const
auto
&
p
:
passes
)
{
module_pm
{
&
mod
,
nullptr
,
&
trace
}.
run_pass
(
p
);
...
...
@@ -94,16 +92,22 @@ void run_passes(module& mod, const std::vector<pass>& passes, tracer trace)
void
run_passes
(
program
&
prog
,
const
std
::
vector
<
pass
>&
passes
,
tracer
trace
)
{
if
(
enabled
(
MIGRAPHX_TRACE_PASSES
{}))
trace
=
tracer
{
std
::
cout
};
if
(
enabled
(
MIGRAPHX_TRACE_PASSES
{})
and
not
trace
.
enabled
())
trace
=
tracer
{
"passes"
};
auto
module_trace
=
trace
;
std
::
unordered_map
<
std
::
string
,
tracer
>
module_tracer_map
;
for
(
const
auto
&
p
:
passes
)
{
auto
mods
=
prog
.
get_modules
();
for
(
const
auto
&
mod
:
reverse
(
mods
))
{
if
(
!
module_tracer_map
.
count
(
mod
->
name
()))
{
module_tracer_map
[
mod
->
name
()]
=
module_trace
;
module_tracer_map
[
mod
->
name
()].
dump_dir
+=
"/"
+
mod
->
name
();
}
if
(
mod
->
bypass
())
continue
;
module_pm
{
mod
,
&
prog
,
&
trace
}.
run_pass
(
p
);
module_pm
{
mod
,
&
prog
,
&
module_tracer_map
[
mod
->
name
()]
}.
run_pass
(
p
);
}
run_pass
(
prog
,
p
,
trace
);
}
...
...
src/program.cpp
View file @
aff10174
...
...
@@ -138,16 +138,15 @@ instruction_ref program::validate() const
bool
program
::
is_compiled
()
const
{
return
not
this
->
impl
->
target_name
.
empty
();
}
void
program
::
compile
(
const
target
&
t
,
compile_options
options
)
void
program
::
compile
(
const
target
&
t
,
compile_options
options
,
std
::
string
ir_dump_path
)
{
assert
(
not
this
->
is_compiled
());
this
->
impl
->
target_name
=
t
.
name
();
this
->
impl
->
ctx
=
t
.
get_context
();
if
(
enabled
(
MIGRAPHX_TRACE_COMPILE
{}))
options
.
trace
=
tracer
{
std
::
cout
};
options
.
trace
=
tracer
{
t
.
name
()
+
"_"
+
ir_dump_path
};
options
.
trace
(
*
this
);
options
.
trace
();
options
.
trace
(
"input_program"
,
*
this
);
auto
&&
passes
=
t
.
get_passes
(
this
->
impl
->
ctx
,
options
);
run_passes
(
*
this
,
passes
,
options
.
trace
);
...
...
src/quantization.cpp
View file @
aff10174
...
...
@@ -90,7 +90,7 @@ void quantize_int8(program& prog,
// use the calibration data to compute the quantization scale
auto
capture_prog
=
prog
;
capture_prog
.
compile
(
t
);
capture_prog
.
compile
(
t
,
compile_options
{},
"quantization"
);
// use all calibration data to run the program to calculate the
// quantization scale and shift
...
...
src/targets/cpu/include/migraphx/cpu/lowering.hpp
View file @
aff10174
...
...
@@ -13,7 +13,7 @@ namespace cpu {
struct
lowering
{
std
::
string
name
()
const
{
return
"
cpu::
lowering"
;
}
std
::
string
name
()
const
{
return
"lowering"
;
}
void
apply
(
module
&
m
)
const
;
};
...
...
src/targets/gpu/include/migraphx/gpu/lowering.hpp
View file @
aff10174
...
...
@@ -14,7 +14,7 @@ struct lowering
{
context
*
ctx
;
bool
offload_copy
;
std
::
string
name
()
const
{
return
"
gpu::
lowering"
;
}
std
::
string
name
()
const
{
return
"lowering"
;
}
void
apply
(
module
&
m
)
const
;
};
...
...
src/targets/ref/include/migraphx/ref/lowering.hpp
View file @
aff10174
...
...
@@ -10,7 +10,7 @@ namespace ref {
struct
lowering
{
std
::
string
name
()
const
{
return
"
ref::
lowering"
;
}
std
::
string
name
()
const
{
return
"lowering"
;
}
void
apply
(
module
&
m
)
const
;
};
...
...
test/verify/run_verify.cpp
View file @
aff10174
...
...
@@ -41,7 +41,7 @@ inline void compile_check(migraphx::program& p, const migraphx::target& t, bool
std
::
stringstream
ss
;
migraphx
::
compile_options
options
;
if
(
show_trace
)
options
.
trace
=
migraphx
::
tracer
{
std
::
cout
};
options
.
trace
=
migraphx
::
tracer
{
t
.
name
()
+
"_passes"
};
p
.
compile
(
t
,
options
);
if
(
shapes
.
size
()
!=
p
.
get_output_shapes
().
size
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment