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
34bb4112
"model.properties" did not exist on "97993ad37dba9cf0d6da57d39422900d821e60c3"
Commit
34bb4112
authored
Dec 08, 2023
by
Brian Pickrell
Browse files
work in progress, builds and runs
parent
538dbd75
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
30 deletions
+83
-30
src/include/migraphx/op/resize.hpp
src/include/migraphx/op/resize.hpp
+79
-28
test/ref/resize.cpp
test/ref/resize.cpp
+4
-2
No files found.
src/include/migraphx/op/resize.hpp
View file @
34bb4112
...
...
@@ -103,8 +103,6 @@ struct resize
f
(
self
.
coordinate_transformation_mode
,
"coordinate_transformation_mode"
));
}
shape
compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
// check_shapes{{inputs[0]}, *this, true}.has(2);
...
...
@@ -150,53 +148,106 @@ struct resize
argument
compute
(
const
dyn_output
&
dyn_out
,
std
::
vector
<
argument
>
args
)
const
{
// See scatter.hpp or gather.hpp for how to do a similar iteration with reduction
// iterate through items in shape
argument
result
{
dyn_out
.
computed_shape
};
shape
output_shape
;
auto
in_lens
=
args
[
0
].
get_shape
().
to_static
(
1
).
lens
();
std
::
vector
<
size_t
>
out_lens
(
in_lens
.
size
());
// Scales are either given, or calculated from output shape
std
::
vector
<
double
>
vec_scale
(
in_lens
.
size
());
if
(
dyn_out
.
computed_shape
.
dynamic
())
{
// calculate output shape from scales or sizes
if
(
not
sizes
.
empty
())
{
// read sizes from args[1]
// out_lens = args[1].get_shape().to_static(1).lens(); // <===
// Compute the scales from the given output dimensions
// Copy the output size
args
[
1
].
visit
([
&
](
auto
size_input
)
{
for
(
auto
aa
:
size_input
)
std
::
cout
<<
aa
<<
" sizes
\n
"
;
std
::
transform
(
size_input
.
begin
(),
size_input
.
end
(),
out_lens
.
begin
(),
[](
auto
size_i
)
{
std
::
cout
<<
size_i
<<
" transform
\n
"
;
return
size_i
;
});
std
::
cout
<<
"***
\n
"
;
for
(
auto
aa
:
out_lens
)
std
::
cout
<<
aa
<<
" out_lens
\n
"
;
std
::
cout
<<
"***
\n
"
;
// Deduce the scales for each axis
std
::
transform
(
size_input
.
begin
(),
size_input
.
end
(),
in_lens
.
begin
(),
vec_scale
.
begin
(),
[](
auto
sz
,
size_t
in_len
)
{
return
static_cast
<
double
>
(
sz
)
/
in_len
;
});
});
for
(
auto
aa
:
vec_scale
)
std
::
cout
<<
aa
<<
" vec_scale
\n
"
;
}
else
{
args
[
1
].
visit
([
&
](
auto
scale_input
)
{
for
(
auto
aa
:
scale_input
)
std
::
cout
<<
aa
<<
" scale_input
\n
"
;
// read the scale from args[1]-- vec_scale = scale_input;
//
std
::
transform
(
scale_input
.
begin
(),
scale_input
.
end
(),
vec_scale
.
begin
(),
[](
auto
scale_i
)
{
return
scale_i
;
});
// compute the output dimensions from the given scale
std
::
transform
(
scale_input
.
begin
(),
scale_input
.
end
(),
in_lens
.
begin
(),
out_lens
.
begin
(),
[](
auto
scale_i
,
size_t
in_len
)
{
return
static_cast
<
size_t
>
(
scale_i
*
in_len
);
});
});
}
output_shape
=
{
args
[
0
].
get_shape
().
type
(),
out_lens
};
}
argument
result
{
output_shape
};
auto
nearest_op
=
get_nearest_op
(
nearest_mode
);
auto
idx_op
=
get_original_idx_op
(
coordinate_transformation_mode
);
auto
in_lens
=
args
[
0
].
get_shape
().
lens
();
auto
out_lens
=
dyn_out
.
computed_shape
.
lens
();
// temp. This is a placeholder for reading the desired dimensions or scale
std
::
vector
<
double
>
vec_scale
=
{
1.
,
1.
,
5.
/
3.
,
8.
/
3.
};
// max dimension in axis
visit_all
(
result
,
args
[
0
])([
&
](
auto
output
,
auto
data
)
{
// the size input
args
[
1
].
visit
([
&
](
auto
indices
)
{
for
(
auto
aa
:
indices
)
std
::
cout
<<
aa
<<
" indices
\n
"
;
if
(
dyn_out
.
computed_shape
.
scalar
())
{
std
::
cout
<<
" scalar output
\n
"
;
}
else
{
//
args[1].visit([&](auto indices) {
//
for(auto aa : indices ) std::cout << aa << " indices \n";
//
if(dyn_out.computed_shape.scalar())
//
{
//
std::cout << " scalar output\n";
//
}
//
else
//
{
// for each element in output, calculate index in input
for
(
auto
bb
:
data
)
std
::
cout
<<
bb
<<
" zzz data
\n
"
;
migraphx
::
shape
out_comp_shape
{
data
.
get_shape
().
type
(),
indice
s
};
migraphx
::
shape
out_comp_shape
{
data
.
get_shape
().
type
(),
out_len
s
};
shape_for_each
(
out_comp_shape
,
[
&
](
const
auto
&
out_idx_v
,
size_t
out_idx
)
{
// Show the output indices. Last index iterates fastest
for
(
auto
vv
:
out_idx_v
)
std
::
cout
<<
vv
<<
" "
;
std
::
cout
<<
out_idx
<<
" out_index
\n
"
;
std
::
cout
<<
nearest_mode
<<
"
\n
"
;
// populate output at this index
// output[out_idx] = data(data_idx.begin(), data_idx.end());
std
::
vector
<
size_t
>
in_idx
(
out_idx_v
.
size
());
for
(
auto
ii
=
0
;
ii
<
out_idx_v
.
size
();
++
ii
)
{
auto
idx_val
=
idx_op
(
in_lens
[
ii
],
out_lens
[
ii
],
out_idx_v
[
ii
],
vec_scale
[
ii
]);
std
::
cout
<<
in_lens
[
ii
]
<<
" "
<<
out_lens
[
ii
]
<<
" "
<<
out_idx_v
[
ii
]
<<
" "
<<
vec_scale
[
ii
]
<<
"==> "
<<
idx_val
<<
"
\n
"
;
in_idx
[
ii
]
=
nearest_op
(
in_lens
[
ii
],
idx_val
);
}
// output[out_idx] = data.at(in_idx);
});
}
std
::
cout
<<
"
\n
"
;
std
::
cout
<<
out_idx
<<
" out_index
\n
"
;
auto
zap
=
data
(
in_idx
.
begin
(),
in_idx
.
end
());
for
(
auto
gg
:
output
)
std
::
cout
<<
gg
<<
" "
;
std
::
cout
<<
"ggg
\n
"
;
// use index function instead?
output
[
out_idx
]
=
data
(
in_idx
.
begin
(),
in_idx
.
end
());
std
::
cout
<<
zap
<<
"
\n
"
;
});
// }
// });
});
std
::
cout
<<
" finish resize
\n
"
;
return
result
;
...
...
test/ref/resize.cpp
View file @
34bb4112
...
...
@@ -40,18 +40,20 @@ TEST_CASE(resize_test_1)
std
::
vector
<
float
>
data
(
3
*
3
);
std
::
iota
(
data
.
begin
(),
data
.
end
(),
0.5
);
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
1
,
1
,
3
,
3
}};
// to do: non-literal
auto
a0
=
mm
->
add_literal
(
migraphx
::
literal
{
s
,
data
});
migraphx
::
shape
size_input
{
migraphx
::
shape
::
int32_type
,
{
4
}};
std
::
vector
<
int
>
size_values
=
{
1
,
1
,
5
,
8
};
auto
a1
=
mm
->
add_literal
(
migraphx
::
literal
{
size_input
,
size_values
});
// a0 = input data
// a1 = sizes of output
mm
->
add_instruction
(
migraphx
::
make_op
(
"resize"
,
{{
"sizes"
,
{
1
}},
{
"scales"
,
{}},
{
"nearest_mode"
,
"floor"
}
,
{
"coordinate_transformation_mode"
,
"half_pixel"
}}),
a0
,
a1
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
auto
result
=
p
.
eval
({}).
back
();
std
::
vector
<
float
>
res_data
(
4
*
5
);
std
::
vector
<
float
>
res_data
(
1
*
1
*
5
*
8
);
std
::
vector
<
float
>
golden
=
{
0.5
f
,
1.5
f
,
2.5
f
,
6.5
f
,
7.5
f
,
8.5
f
};
result
.
visit
([
&
](
auto
output
)
{
res_data
.
assign
(
output
.
begin
(),
output
.
end
());
});
for
(
auto
aa
:
res_data
)
std
::
cout
<<
aa
<<
", "
;
std
::
cout
<<
" result
\n
"
;
...
...
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