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
52113ea0
Commit
52113ea0
authored
Nov 03, 2022
by
charlie
Browse files
Fix eliminate_contiguous pass
parent
221503d7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
17 deletions
+123
-17
src/eliminate_contiguous.cpp
src/eliminate_contiguous.cpp
+13
-3
src/include/migraphx/op/contiguous.hpp
src/include/migraphx/op/contiguous.hpp
+22
-9
src/targets/ref/target.cpp
src/targets/ref/target.cpp
+2
-2
test/op_shape_test.cpp
test/op_shape_test.cpp
+6
-0
test/ref_ops_test.cpp
test/ref_ops_test.cpp
+80
-3
No files found.
src/eliminate_contiguous.cpp
View file @
52113ea0
...
@@ -42,6 +42,13 @@ static bool try_compute_shape(instruction_ref ins,
...
@@ -42,6 +42,13 @@ static bool try_compute_shape(instruction_ref ins,
try
try
{
{
shape
new_shape
=
ins
->
get_operator
().
compute_shape
(
inputs
,
mods
);
shape
new_shape
=
ins
->
get_operator
().
compute_shape
(
inputs
,
mods
);
// Cannot tell if a dynamic shape will need to be made contiguous
if
(
new_shape
.
dynamic
())
{
return
false
;
}
// If the output shape is a standard shape, no need to try its output
// If the output shape is a standard shape, no need to try its output
if
(
new_shape
.
standard
())
if
(
new_shape
.
standard
())
{
{
...
@@ -138,7 +145,10 @@ static void remove_contiguous(const std::string& op_name, module& m, F f)
...
@@ -138,7 +145,10 @@ static void remove_contiguous(const std::string& op_name, module& m, F f)
par_for
(
const_instructions
.
size
(),
1
,
[
&
](
const
auto
i
)
{
par_for
(
const_instructions
.
size
(),
1
,
[
&
](
const
auto
i
)
{
auto
c
=
op
::
contiguous
{};
auto
c
=
op
::
contiguous
{};
auto
prev
=
const_instructions
[
i
]
->
inputs
().
front
();
auto
prev
=
const_instructions
[
i
]
->
inputs
().
front
();
literals
[
i
]
=
c
.
compute
(
c
.
compute_shape
({
prev
->
get_shape
()}),
{
prev
->
eval
()});
std
::
vector
<
shape
>
prev_shape
=
{
prev
->
get_shape
()};
const
std
::
vector
<
argument
>&
prev_eval
=
{
prev
->
eval
()};
auto
co_shape
=
make_compute_output_shape
(
pack
(
c
,
prev_shape
,
prev_eval
));
literals
[
i
]
=
c
.
compute
(
co_shape
,
{
prev
->
eval
()});
});
});
for
(
size_t
i
=
0
;
i
<
const_instructions
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
const_instructions
.
size
();
i
++
)
...
...
src/include/migraphx/op/contiguous.hpp
View file @
52113ea0
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include <migraphx/argument.hpp>
#include <migraphx/argument.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/shape_for_each.hpp>
#include <migraphx/config.hpp>
#include <migraphx/config.hpp>
#include <migraphx/dyn_output.hpp>
namespace
migraphx
{
namespace
migraphx
{
inline
namespace
MIGRAPHX_INLINE_NS
{
inline
namespace
MIGRAPHX_INLINE_NS
{
...
@@ -42,19 +43,31 @@ namespace op {
...
@@ -42,19 +43,31 @@ namespace op {
struct
contiguous
struct
contiguous
{
{
std
::
string
name
()
const
{
return
"contiguous"
;
}
std
::
string
name
()
const
{
return
"contiguous"
;
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
check_shapes
{
inputs
,
*
this
,
true
}.
has
(
1
);
if
(
inputs
.
front
().
standard
())
auto
s0
=
inputs
.
front
();
if
(
s0
.
dynamic
())
{
return
s0
;
}
else
{
if
(
s0
.
standard
())
{
return
inputs
.
front
();
return
inputs
.
front
();
}
auto
lens
=
inputs
.
at
(
0
).
lens
();
auto
lens
=
inputs
.
at
(
0
).
lens
();
auto
t
=
inputs
.
at
(
0
).
type
();
auto
t
=
inputs
.
at
(
0
).
type
();
return
{
t
,
lens
};
return
{
t
,
lens
};
}
}
argument
compute
(
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
}
argument
compute
(
const
dyn_output
&
dyn_out
,
std
::
vector
<
argument
>
args
)
const
{
{
assert
(
out
put_shape
.
standard
());
assert
(
dyn_out
.
com
put
ed
_shape
.
standard
());
argument
result
{
out
put_shape
};
argument
result
{
dyn_out
.
com
put
ed
_shape
};
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
input
)
{
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
input
)
{
shape_for_each
(
output
.
get_shape
(),
[
&
](
const
auto
&
idx
)
{
shape_for_each
(
output
.
get_shape
(),
[
&
](
const
auto
&
idx
)
{
output
(
idx
.
begin
(),
idx
.
end
())
=
input
(
idx
.
begin
(),
idx
.
end
());
output
(
idx
.
begin
(),
idx
.
end
())
=
input
(
idx
.
begin
(),
idx
.
end
());
...
...
src/targets/ref/target.cpp
View file @
52113ea0
...
@@ -49,8 +49,8 @@ std::vector<pass> target::get_passes(migraphx::context&, const compile_options&)
...
@@ -49,8 +49,8 @@ std::vector<pass> target::get_passes(migraphx::context&, const compile_options&)
dead_code_elimination
{},
dead_code_elimination
{},
rewrite_rnn
{},
rewrite_rnn
{},
dead_code_elimination
{},
dead_code_elimination
{},
auto_contiguous
{},
//
auto_contiguous{},
dead_code_elimination
{},
//
dead_code_elimination{},
lowering
{},
lowering
{},
dead_code_elimination
{}};
dead_code_elimination
{}};
}
}
...
...
test/op_shape_test.cpp
View file @
52113ea0
...
@@ -357,6 +357,12 @@ TEST_CASE(contiguous_shape)
...
@@ -357,6 +357,12 @@ TEST_CASE(contiguous_shape)
expect_shape
(
single
,
migraphx
::
make_op
(
"contiguous"
),
single
);
expect_shape
(
single
,
migraphx
::
make_op
(
"contiguous"
),
single
);
}
}
TEST_CASE
(
contiguous_dyn_shape
)
{
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{{
1
,
4
,
0
},
{
2
,
2
,
2
}}};
expect_shape
(
s0
,
migraphx
::
make_op
(
"contiguous"
),
s0
);
}
TEST_CASE
(
contiguous_shape_scalar
)
TEST_CASE
(
contiguous_shape_scalar
)
{
{
migraphx
::
shape
output
{
migraphx
::
shape
::
float_type
};
migraphx
::
shape
output
{
migraphx
::
shape
::
float_type
};
...
...
test/ref_ops_test.cpp
View file @
52113ea0
...
@@ -918,11 +918,88 @@ TEST_CASE(contiguous_test)
...
@@ -918,11 +918,88 @@ TEST_CASE(contiguous_test)
p
.
compile
(
migraphx
::
ref
::
target
{});
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
result
=
p
.
eval
({}).
back
();
result
.
visit
([
&
](
auto
output
)
{
std
::
vector
<
size_t
>
new_strides
=
{
12
,
4
,
2
,
1
};
EXPECT
(
bool
{
output
.
get_shape
().
strides
()
==
new_strides
});
});
std
::
vector
<
float
>
results_vector
(
12
);
std
::
vector
<
float
>
results_vector
(
12
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
size_t
>
new_lens
=
{
1
,
3
,
2
,
2
};
std
::
vector
<
size_t
>
new_strides
=
{
12
,
1
,
6
,
3
};
std
::
cout
<<
"results_vector: ["
;
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
data
));
for
(
auto
r
:
results_vector
)
std
::
cout
<<
r
<<
", "
;
std
::
cout
<<
"]
\n
"
;
std
::
vector
<
float
>
gold
=
{
0
,
3
,
6
,
9
,
1
,
4
,
7
,
10
,
2
,
5
,
8
,
11
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
contiguous_param_test
)
{
migraphx
::
shape
a_shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
2
,
2
},
{
12
,
1
,
6
,
3
}};
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
auto
a
=
mm
->
add_parameter
(
"X"
,
a_shape
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
a
);
p
.
compile
(
migraphx
::
ref
::
target
{});
std
::
vector
<
float
>
data
(
12
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
migraphx
::
parameter_map
params
;
params
[
"X"
]
=
migraphx
::
argument
(
a_shape
,
data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
result
.
visit
([
&
](
auto
output
)
{
std
::
vector
<
size_t
>
new_strides
=
{
12
,
4
,
2
,
1
};
EXPECT
(
bool
{
output
.
get_shape
().
strides
()
==
new_strides
});
});
std
::
vector
<
float
>
results_vector
(
12
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
cout
<<
"results_vector: ["
;
for
(
auto
r
:
results_vector
)
std
::
cout
<<
r
<<
", "
;
std
::
cout
<<
"]
\n
"
;
std
::
vector
<
float
>
gold
=
{
0
,
3
,
6
,
9
,
1
,
4
,
7
,
10
,
2
,
5
,
8
,
11
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
TEST_CASE
(
contiguous_dyn_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
dyn_shape
{
migraphx
::
shape
::
float_type
,
{{
1
,
1
,
0
},
{
2
,
6
,
0
},
{
2
,
2
,
0
},
{
2
,
2
,
0
}}};
auto
input
=
mm
->
add_parameter
(
"X"
,
dyn_shape
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
input
);
p
.
compile
(
migraphx
::
ref
::
target
{});
migraphx
::
shape
static_shape
{
migraphx
::
shape
::
float_type
,
{
1
,
3
,
2
,
2
},
{
12
,
1
,
6
,
3
}};
std
::
vector
<
float
>
data
(
12
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0
);
migraphx
::
parameter_map
params
;
params
[
"X"
]
=
migraphx
::
argument
(
static_shape
,
data
.
data
());
auto
result
=
p
.
eval
(
params
).
back
();
result
.
visit
([
&
](
auto
output
)
{
std
::
vector
<
size_t
>
new_strides
=
{
12
,
4
,
2
,
1
};
EXPECT
(
bool
{
output
.
get_shape
().
strides
()
==
new_strides
});
});
std
::
vector
<
float
>
results_vector
(
12
);
result
.
visit
([
&
](
auto
output
)
{
results_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
cout
<<
"results_vector: ["
;
for
(
auto
r
:
results_vector
)
std
::
cout
<<
r
<<
", "
;
std
::
cout
<<
"]
\n
"
;
std
::
vector
<
float
>
gold
=
{
0
,
3
,
6
,
9
,
1
,
4
,
7
,
10
,
2
,
5
,
8
,
11
};
EXPECT
(
migraphx
::
verify_range
(
results_vector
,
gold
));
}
}
TEST_CASE
(
conv_dynamic_batch_test
)
TEST_CASE
(
conv_dynamic_batch_test
)
...
...
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