Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
03b1421c
Commit
03b1421c
authored
Aug 14, 2018
by
Paul
Browse files
Add tracing during compilation
parent
73e91069
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
2 deletions
+124
-2
src/CMakeLists.txt
src/CMakeLists.txt
+1
-0
src/env.cpp
src/env.cpp
+32
-0
src/include/migraph/env.hpp
src/include/migraph/env.hpp
+33
-0
src/include/migraph/ranges.hpp
src/include/migraph/ranges.hpp
+49
-2
src/program.cpp
src/program.cpp
+9
-0
No files found.
src/CMakeLists.txt
View file @
03b1421c
...
...
@@ -3,6 +3,7 @@ add_library(migraph
auto_contiguous.cpp
dead_code_elimination.cpp
eliminate_contiguous.cpp
env.cpp
generate.cpp
program.cpp
shape.cpp
...
...
src/env.cpp
0 → 100644
View file @
03b1421c
#include <migraph/env.hpp>
#include <migraph/ranges.hpp>
#include <cstdlib>
namespace
migraph
{
bool
enabled
(
const
char
*
name
)
{
auto
e
=
env
(
name
);
if
(
e
.
empty
())
return
false
;
return
contains
({
"1"
,
"enable"
,
"enabled"
,
"yes"
,
"true"
},
e
.
front
());
}
bool
disabled
(
const
char
*
name
)
{
auto
e
=
env
(
name
);
if
(
e
.
empty
())
return
false
;
return
contains
({
"0"
,
"disable"
,
"disabled"
,
"no"
,
"false"
},
e
.
front
());
}
std
::
vector
<
std
::
string
>
env
(
const
char
*
name
)
{
auto
p
=
std
::
getenv
(
name
);
if
(
p
==
nullptr
)
return
{};
else
return
{{
p
}};
}
}
// namespace migraph
src/include/migraph/env.hpp
0 → 100644
View file @
03b1421c
#ifndef MIGRAPH_GUARD_RTGLIB_ENV_HPP
#define MIGRAPH_GUARD_RTGLIB_ENV_HPP
#include <vector>
#include <string>
namespace
migraph
{
// Declare a cached environment variable
#define MIGRAPH_DECLARE_ENV_VAR(x) \
struct x { static const char* value() { return #x; } }; // NOLINT
bool
enabled
(
const
char
*
name
);
bool
disabled
(
const
char
*
name
);
std
::
vector
<
std
::
string
>
env
(
const
char
*
name
);
template
<
class
T
>
bool
enabled
(
T
)
{
static
const
bool
result
=
enabled
(
T
::
value
());
return
result
;
}
template
<
class
T
>
bool
disabled
(
T
)
{
static
const
bool
result
=
disabled
(
T
::
value
());
return
result
;
}
}
// namespace migraph
#endif
src/include/migraph/ranges.hpp
View file @
03b1421c
...
...
@@ -2,13 +2,60 @@
#define MIGRAPH_GUARD_MIGRAPHLIB_RANGES_HPP
#include <algorithm>
#include <initializer_list>
namespace
migraph
{
template
<
int
N
>
struct
rank
:
rank
<
N
-
1
>
{
};
template
<
>
struct
rank
<
0
>
{
};
namespace
detail
{
template
<
class
String
,
class
T
>
auto
generic_find_impl
(
rank
<
2
>
,
String
&&
s
,
const
T
&
x
)
->
decltype
(
s
.
begin
()
+
s
.
find
(
x
),
s
.
npos
)
{
auto
index
=
s
.
find
(
x
);
if
(
index
==
s
.
npos
)
return
s
.
end
();
else
return
s
.
begin
()
+
index
;
}
template
<
class
C
,
class
T
>
auto
generic_find_impl
(
rank
<
1
>
,
C
&&
c
,
const
T
&
x
)
->
decltype
(
c
.
find
(
x
))
{
return
c
.
find
(
x
);
}
template
<
class
C
,
class
T
>
bool
contains
(
C
&&
c
,
T
&&
x
)
auto
generic_find_impl
(
rank
<
0
>
,
C
&&
c
,
const
T
&
x
)
{
return
std
::
find
(
c
.
begin
(),
c
.
end
(),
x
);
}
}
// namespace detail
template
<
class
C
,
class
T
>
auto
generic_find
(
C
&&
c
,
const
T
&
x
)
{
return
detail
::
generic_find_impl
(
rank
<
2
>
{},
c
,
x
);
}
template
<
class
C
,
class
T
>
bool
contains
(
const
C
&
c
,
const
T
&
x
)
{
return
generic_find
(
c
,
x
)
!=
c
.
end
();
}
template
<
class
T
,
class
U
>
bool
contains
(
const
std
::
initializer_list
<
T
>&
c
,
const
U
&
x
)
{
return
c
.
find
(
x
)
!=
c
.
end
();
return
generic_
find
(
c
,
x
)
!=
c
.
end
();
}
template
<
class
Range
,
class
Iterator
>
...
...
src/program.cpp
View file @
03b1421c
#include <migraph/program.hpp>
#include <migraph/stringutils.hpp>
#include <migraph/instruction.hpp>
#include <migraph/env.hpp>
#include <iostream>
#include <sstream>
#include <algorithm>
namespace
migraph
{
MIGRAPH_DECLARE_ENV_VAR
(
MIGRAPH_TRACE_COMPILE
)
struct
program_impl
{
// A list is used to keep references to an instruction stable
...
...
@@ -183,9 +186,15 @@ void program::compile(const target& t)
{
assert
(
this
->
validate
()
==
impl
->
instructions
.
end
());
this
->
impl
->
ctx
=
t
.
get_context
();
if
(
enabled
(
MIGRAPH_TRACE_COMPILE
{}))
std
::
cout
<<
*
this
<<
std
::
endl
<<
std
::
endl
;;
for
(
auto
&&
p
:
t
.
get_passes
(
this
->
impl
->
ctx
))
{
if
(
enabled
(
MIGRAPH_TRACE_COMPILE
{}))
std
::
cout
<<
"Pass: "
<<
p
.
name
()
<<
std
::
endl
;
p
.
apply
(
*
this
);
if
(
enabled
(
MIGRAPH_TRACE_COMPILE
{}))
std
::
cout
<<
*
this
<<
std
::
endl
<<
std
::
endl
;
#ifndef NDEBUG
auto
invalid
=
this
->
validate
();
if
(
invalid
!=
impl
->
instructions
.
end
())
...
...
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