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
c37b1636
Commit
c37b1636
authored
Jun 28, 2022
by
Paul
Browse files
Query to perfdb
parent
00d94d76
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
6 deletions
+136
-6
src/include/migraphx/stringutils.hpp
src/include/migraphx/stringutils.hpp
+6
-6
src/targets/gpu/CMakeLists.txt
src/targets/gpu/CMakeLists.txt
+1
-0
src/targets/gpu/include/migraphx/gpu/perfdb.hpp
src/targets/gpu/include/migraphx/gpu/perfdb.hpp
+26
-0
src/targets/gpu/mlir.cpp
src/targets/gpu/mlir.cpp
+9
-0
src/targets/gpu/perfdb.cpp
src/targets/gpu/perfdb.cpp
+94
-0
No files found.
src/include/migraphx/stringutils.hpp
View file @
c37b1636
...
@@ -168,27 +168,27 @@ inline std::string interpolate_string(const std::string& input,
...
@@ -168,27 +168,27 @@ inline std::string interpolate_string(const std::string& input,
}
}
template
<
class
Iterator
>
template
<
class
Iterator
>
inline
std
::
string
to_string_range
(
Iterator
start
,
Iterator
last
)
inline
std
::
string
to_string_range
(
Iterator
start
,
Iterator
last
,
const
char
*
delim
=
", "
)
{
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
if
(
start
!=
last
)
if
(
start
!=
last
)
{
{
ss
<<
*
start
;
ss
<<
*
start
;
std
::
for_each
(
std
::
next
(
start
),
last
,
[
&
](
auto
&&
x
)
{
ss
<<
", "
<<
x
;
});
std
::
for_each
(
std
::
next
(
start
),
last
,
[
&
](
auto
&&
x
)
{
ss
<<
delim
<<
x
;
});
}
}
return
ss
.
str
();
return
ss
.
str
();
}
}
template
<
class
Range
>
template
<
class
Range
>
inline
std
::
string
to_string_range
(
const
Range
&
r
)
inline
std
::
string
to_string_range
(
const
Range
&
r
,
const
char
*
delim
=
", "
)
{
{
return
to_string_range
(
r
.
begin
(),
r
.
end
());
return
to_string_range
(
r
.
begin
(),
r
.
end
()
,
delim
);
}
}
template
<
class
T
>
template
<
class
T
>
inline
std
::
string
to_string_range
(
const
std
::
initializer_list
<
T
>&
r
)
inline
std
::
string
to_string_range
(
const
std
::
initializer_list
<
T
>&
r
,
const
char
*
delim
=
", "
)
{
{
return
to_string_range
(
r
.
begin
(),
r
.
end
());
return
to_string_range
(
r
.
begin
(),
r
.
end
()
,
delim
);
}
}
template
<
class
T
>
template
<
class
T
>
...
...
src/targets/gpu/CMakeLists.txt
View file @
c37b1636
...
@@ -184,6 +184,7 @@ add_library(migraphx_gpu
...
@@ -184,6 +184,7 @@ add_library(migraphx_gpu
pack_int8_args.cpp
pack_int8_args.cpp
prefuse_ops.cpp
prefuse_ops.cpp
pad.cpp
pad.cpp
perfdb.cpp
pooling.cpp
pooling.cpp
quant_convolution.cpp
quant_convolution.cpp
reverse.cpp
reverse.cpp
...
...
src/targets/gpu/include/migraphx/gpu/perfdb.hpp
0 → 100644
View file @
c37b1636
#ifndef MIGRAPHX_GUARD_GPU_PERFDB_HPP
#define MIGRAPHX_GUARD_GPU_PERFDB_HPP
#include <migraphx/config.hpp>
#include <migraphx/shape.hpp>
#include <migraphx/operation.hpp>
#include <string>
#include <vector>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
struct
problem_params
{
operation
op
;
std
::
vector
<
shape
>
inputs
;
shape
output
;
};
std
::
string
get_mlir_perf_for_conv
(
const
problem_params
&
pp
);
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
#endif // MIGRAPHX_GUARD_GPU_PERFDB_HPP
src/targets/gpu/mlir.cpp
View file @
c37b1636
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/device_name.hpp>
#include <migraphx/gpu/device_name.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/iterator_for.hpp>
#include <migraphx/gpu/perfdb.hpp>
#include <deque>
#include <deque>
#include <variant>
#include <variant>
...
@@ -464,6 +465,8 @@ struct mlir_program
...
@@ -464,6 +465,8 @@ struct mlir_program
ops
.
add_attribute_value
(
get_operator_value
(
ins
->
get_operator
()));
ops
.
add_attribute_value
(
get_operator_value
(
ins
->
get_operator
()));
if
(
ins
->
name
()
!=
"@return"
)
if
(
ins
->
name
()
!=
"@return"
)
ops
.
add_results
({
get_shape
(
ins
)});
ops
.
add_results
({
get_shape
(
ins
)});
if
(
ins
->
name
())
pp
=
{
ins
->
get_operator
(),
ins
->
inputs
(),
ins
->
get_shape
()};
std
::
vector
<
MlirValue
>
inputs
;
std
::
vector
<
MlirValue
>
inputs
;
transform
(
transform
(
...
@@ -522,9 +525,15 @@ struct mlir_program
...
@@ -522,9 +525,15 @@ struct mlir_program
MIGRAPHX_THROW
(
"Failed to compile mlir program"
);
MIGRAPHX_THROW
(
"Failed to compile mlir program"
);
}
}
std
::
string
get_tune_params
()
{
return
get_mlir_perf_for_conv
(
pp
);
}
mlir_context
ctx
;
mlir_context
ctx
;
MlirLocation
location
;
MlirLocation
location
;
mlir_module
mmodule
;
mlir_module
mmodule
;
problem_params
pp
;
std
::
deque
<
std
::
string
>
strings
{};
std
::
deque
<
std
::
string
>
strings
{};
};
};
...
...
src/targets/gpu/perfdb.cpp
0 → 100644
View file @
c37b1636
#include <migraphx/gpu/perfdb.hpp>
#include <migraphx/value.hpp>
#include <migraphx/sqlite.hpp>
#include <migraphx/stringutils.hpp>
#include <migraphx/permutation.hpp>
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
namespace
gpu
{
namespace
{
// C-HxW-XxY-K-OHxOW-N-padhxpadw-stride-dilation-0-xlayout-wlayout-ylayout-type-F
// case miopenFloat: return "FP32";
// case miopenHalf: return "FP16";
// case miopenInt8: return "INT8";
// case miopenInt8x4: return "INT8x4";
// case miopenInt32: return "INT32";
// case miopenBFloat16: return "BF16";
// case miopenDouble: return "FP64";
std
::
string
get_layout
(
const
shape
&
s
,
std
::
string
labels
)
{
auto
result
=
labels
;
auto
p
=
find_permutation
(
s
);
std
::
transform
(
p
.
begin
(),
p
.
end
(),
result
.
begin
(),
[
&
](
auto
i
)
{
return
labels
[
i
];
});
return
result
;
}
std
::
string
get_type
(
const
shape
&
s
)
{
static
const
std
::
unordered_map
<
shape
::
type_t
,
std
::
string
>
m
=
{
{
shape
::
float_type
,
"FP32"
},
{
shape
::
half_type
,
"FP16"
},
{
shape
::
double_type
,
"FP64"
},
{
shape
::
int8_type
,
"INT8"
},
{
shape
::
int32_type
,
"INT32"
},
};
auto
it
=
m
.
find
(
s
.
type
());
if
(
it
==
m
.
end
())
return
"UNKNOWN"
;
return
it
->
second
;
}
std
::
string
generate_miopen_config
(
const
problem_params
&
pp
)
{
value
v
=
pp
.
op
.
to_value
();
auto
input
=
pp
.
inputs
[
0
].
lens
();
auto
weights
=
pp
.
inputs
[
1
].
lens
();
auto
output
=
pp
.
output
.
lens
();
auto
padding
=
v
[
"padding"
].
to_vector
<
std
::
size_t
>
();
auto
stride
=
v
[
"stride"
].
to_vector
<
std
::
size_t
>
();
auto
dilation
=
v
[
"dilation"
].
to_vector
<
std
::
size_t
>
();
if
(
padding
.
size
()
!=
stride
.
size
())
padding
.
erase
(
padding
.
begin
()
+
padding
.
size
()
/
2
,
padding
.
end
());
return
to_string_range
({
to_string
(
input
[
1
]),
to_string_range
(
input
.
begin
()
+
2
,
input
.
end
(),
"x"
),
to_string_range
(
weights
.
begin
()
+
2
,
weights
.
end
(),
"x"
),
to_string
(
weights
[
0
]),
to_string_range
(
output
.
begin
()
+
2
,
output
.
end
(),
"x"
),
to_string
(
input
[
0
]),
to_string_range
(
padding
.
begin
()
+
2
,
padding
.
end
(),
"x"
),
to_string_range
(
stride
.
begin
()
+
2
,
stride
.
end
(),
"x"
),
to_string_range
(
dilation
.
begin
()
+
2
,
dilation
.
end
(),
"x"
),
std
::
string
{
"0"
},
get_layout
(
pp
.
inputs
[
0
],
"NCHW"
),
get_layout
(
pp
.
inputs
[
1
],
"NCHW"
),
get_layout
(
pp
.
output
,
"NCHW"
),
get_type
(
pp
.
inputs
[
0
]),
std
::
string
{
"F"
}
},
"-"
);
}
}
std
::
string
get_mlir_perf_for_conv
(
const
problem_params
&
pp
)
{
const
auto
dbpath
=
fs
::
path
{
"opt"
}
/
"rocm"
/
"share"
/
"miopen"
/
"db"
/
"miopen.db"
;
auto
db
=
sqlite
::
read
(
dbpath
);
std
::
string
query
=
"select * from perf_db where config=${config}"
;
auto
results
=
db
.
execute
(
interpolate_string
(
query
,
{{
"config"
,
generate_miopen_config
(
pp
)}}));
if
(
results
.
empty
())
return
""
;
return
results
.
front
().
at
(
"params"
);
}
}
// namespace gpu
}
// namespace MIGRAPHX_INLINE_NS
}
// namespace migraphx
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