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
7c63b13b
Commit
7c63b13b
authored
May 06, 2022
by
charlie
Browse files
Dynamic shape tests
parent
dfa26315
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
src/shape.cpp
src/shape.cpp
+2
-0
test/shape_test.cpp
test/shape_test.cpp
+55
-0
No files found.
src/shape.cpp
View file @
7c63b13b
...
@@ -220,6 +220,7 @@ std::size_t shape::index(std::initializer_list<std::size_t> l) const
...
@@ -220,6 +220,7 @@ std::size_t shape::index(std::initializer_list<std::size_t> l) const
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
return
std
::
inner_product
(
l
.
begin
(),
l
.
end
(),
this
->
strides
().
begin
(),
std
::
size_t
{
0
});
return
std
::
inner_product
(
l
.
begin
(),
l
.
end
(),
this
->
strides
().
begin
(),
std
::
size_t
{
0
});
}
}
std
::
size_t
shape
::
index
(
const
std
::
vector
<
std
::
size_t
>&
l
)
const
std
::
size_t
shape
::
index
(
const
std
::
vector
<
std
::
size_t
>&
l
)
const
{
{
if
(
this
->
dynamic
())
if
(
this
->
dynamic
())
...
@@ -230,6 +231,7 @@ std::size_t shape::index(const std::vector<std::size_t>& l) const
...
@@ -230,6 +231,7 @@ std::size_t shape::index(const std::vector<std::size_t>& l) const
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
assert
(
this
->
lens
().
size
()
==
this
->
strides
().
size
());
return
std
::
inner_product
(
l
.
begin
(),
l
.
end
(),
this
->
strides
().
begin
(),
std
::
size_t
{
0
});
return
std
::
inner_product
(
l
.
begin
(),
l
.
end
(),
this
->
strides
().
begin
(),
std
::
size_t
{
0
});
}
}
std
::
size_t
shape
::
index
(
std
::
size_t
i
)
const
std
::
size_t
shape
::
index
(
std
::
size_t
i
)
const
{
{
if
(
this
->
dynamic
())
if
(
this
->
dynamic
())
...
...
test/shape_test.cpp
View file @
7c63b13b
...
@@ -75,6 +75,61 @@ TEST_CASE(test_shape_dynamic_not_fixed)
...
@@ -75,6 +75,61 @@ TEST_CASE(test_shape_dynamic_not_fixed)
EXPECT
(
s
.
dyn_dims
().
at
(
0
).
has_optimal
());
EXPECT
(
s
.
dyn_dims
().
at
(
0
).
has_optimal
());
}
}
TEST_CASE
(
test_shape_dynamic_compares
)
{
auto
a
=
migraphx
::
shape
::
dynamic_dimension
{
2
,
5
,
2
};
auto
b
=
a
;
auto
c
=
migraphx
::
shape
::
dynamic_dimension
{
2
,
5
,
2
};
auto
d
=
migraphx
::
shape
::
dynamic_dimension
{
3
,
8
,
4
};
EXPECT
(
a
==
b
);
EXPECT
(
a
==
c
);
EXPECT
(
a
!=
d
);
migraphx
::
shape
s0
{
migraphx
::
shape
::
float_type
,
{
a
,
d
}};
migraphx
::
shape
s1
=
s0
;
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
a
,
d
}};
migraphx
::
shape
s3
{
migraphx
::
shape
::
int32_type
,
{
a
}};
EXPECT
(
s0
==
s1
);
EXPECT
(
s0
==
s2
);
EXPECT
(
s0
!=
s3
);
}
TEST_CASE
(
test_shape_dynamic_errors
)
{
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dims
=
{};
dims
.
emplace_back
(
migraphx
::
shape
::
dynamic_dimension
{
2
,
5
,
2
});
dims
.
emplace_back
(
migraphx
::
shape
::
dynamic_dimension
{
2
,
8
,
0
});
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
dims
};
EXPECT
(
test
::
throws
([
&
]
{
s
.
element_space
();
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
elements
();
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
bytes
();
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
index
({
0
,
1
});
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
index
(
1
);
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
with_lens
({
3
,
5
});
}));
EXPECT
(
test
::
throws
([
&
]
{
s
.
with_lens
(
migraphx
::
shape
::
float_type
,
{
3
,
5
});
}));
}
TEST_CASE
(
test_shape_dynamic_serialize
)
{
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dims1
=
{};
dims1
.
emplace_back
(
migraphx
::
shape
::
dynamic_dimension
{
2
,
5
,
2
});
dims1
.
emplace_back
(
migraphx
::
shape
::
dynamic_dimension
{
2
,
8
,
0
});
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
dims1
};
auto
v1
=
migraphx
::
to_value
(
s1
);
std
::
vector
<
migraphx
::
shape
::
dynamic_dimension
>
dims2
=
{};
dims2
.
emplace_back
(
migraphx
::
shape
::
dynamic_dimension
{
2
,
5
,
2
});
migraphx
::
shape
s2
{
migraphx
::
shape
::
uint64_type
,
dims2
};
auto
v2
=
migraphx
::
to_value
(
s2
);
EXPECT
(
v1
!=
v2
);
auto
s3
=
migraphx
::
from_value
<
migraphx
::
shape
>
(
v1
);
EXPECT
(
s3
==
s1
);
auto
s4
=
migraphx
::
from_value
<
migraphx
::
shape
>
(
v2
);
EXPECT
(
s4
==
s2
);
EXPECT
(
s3
!=
s4
);
}
TEST_CASE
(
test_shape_packed
)
TEST_CASE
(
test_shape_packed
)
{
{
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
2
},
{
2
,
1
}};
migraphx
::
shape
s
{
migraphx
::
shape
::
float_type
,
{
2
,
2
},
{
2
,
1
}};
...
...
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