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
composable_kernel
Commits
fb05bd38
Commit
fb05bd38
authored
Sep 14, 2022
by
Po-Yen, Chen
Browse files
Use function return value directly to eliminate variables
parent
097506c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
17 deletions
+10
-17
example/37_permute/common.hpp
example/37_permute/common.hpp
+6
-9
example/37_permute/run_permute_bundle_example.inc
example/37_permute/run_permute_bundle_example.inc
+3
-6
example/37_permute/run_permute_element_example.inc
example/37_permute/run_permute_element_example.inc
+1
-2
No files found.
example/37_permute/common.hpp
View file @
fb05bd38
...
...
@@ -289,23 +289,20 @@ is_valid_indices(const Shape& shape, const Indices& indices)
return
true
;
}
template
<
typename
Shape
,
typename
Axes
,
typename
OutputIterator
>
inline
std
::
enable_if_t
<
detail
::
is_random_access_range_v
<
Shape
>
&&
detail
::
is_sized_range_v
<
Shape
>
&&
detail
::
is_sized_range_v
<
Axes
>
&&
detail
::
is_output_iterator_v
<
OutputIterator
>
,
OutputIterator
>
transpose_shape
(
const
Shape
&
shape
,
const
Axes
&
axes
,
OutputIterator
iter
)
template
<
std
::
size_t
Size
>
std
::
array
<
std
::
size_t
,
Size
>
transpose
(
const
std
::
array
<
std
::
size_t
,
Size
>&
shape
,
const
std
::
array
<
std
::
size_t
,
Size
>&
axes
)
{
using
std
::
size
;
assert
(
size
(
shape
)
==
size
(
axes
));
assert
(
is_valid_shape
(
shape
)
&&
is_valid_axes
(
axes
));
std
::
array
<
std
::
size_t
,
Size
>
transposed
;
auto
iter
=
std
::
begin
(
transposed
);
for
(
const
auto
axis
:
axes
)
{
*
iter
++
=
shape
[
axis
];
}
return
iter
;
return
transposed
;
}
auto
extend_shape
(
const
Problem
::
Shape
&
shape
,
std
::
size_t
new_dim
)
...
...
example/37_permute/run_permute_bundle_example.inc
View file @
fb05bd38
...
...
@@ -12,8 +12,7 @@ bool run_permute_bundle(const Problem& problem)
const
auto
&
input_bundle_shape
=
problem
.
shape
;
const
auto
&
input_bundle_axes
=
problem
.
axes
;
ck
::
remove_cvref_t
<
decltype
(
input_bundle_shape
)
>
output_bundle_shape
;
transpose_shape
(
input_bundle_shape
,
input_bundle_axes
,
begin
(
output_bundle_shape
));
const
auto
output_bundle_shape
=
transpose
(
input_bundle_shape
,
input_bundle_axes
);
Tensor
<
BundleType
>
input_bundle_tensor
(
input_bundle_shape
);
Tensor
<
BundleType
>
output_bundle_tensor
(
output_bundle_shape
);
...
...
@@ -66,18 +65,16 @@ bool run_permute_bundle(const Problem& problem)
output_device_buf
.
FromDevice
(
data
(
output_bundle_tensor
));
// extend tensor shape from [N, H, W] to [N, H, W, NumElemsInBundle]
// axes from [0, 2, 1] to [0, 2, 1, 3]
const
auto
input_shape
=
extend_shape
(
input_bundle_shape
,
NumElemsInBundle
);
const
auto
input_axes
=
extend_axes
(
input_bundle_axes
);
ck
::
remove_cvref_t
<
decltype
(
input_shape
)
>
output_shape
;
transpose_shape
(
input_shape
,
input_axes
,
begin
(
output_shape
));
Tensor
<
DataType
>
input_tensor
(
input_shape
);
std
::
memcpy
(
data
(
input_tensor
),
data
(
input_bundle_tensor
),
input_bundle_tensor
.
GetElementSpaceSizeInBytes
());
Tensor
<
DataType
>
output_tensor
(
output_shape
);
Tensor
<
DataType
>
output_tensor
(
transpose
(
input_shape
,
input_axes
)
);
if
(
!
host_permute
(
input_tensor
,
input_axes
,
PassThrough
{},
output_tensor
))
{
return
false
;
...
...
example/37_permute/run_permute_element_example.inc
View file @
fb05bd38
...
...
@@ -10,8 +10,7 @@ bool run_permute_element(const Problem& problem)
const
auto
&
input_shape
=
problem
.
shape
;
const
auto
&
input_axes
=
problem
.
axes
;
ck
::
remove_cvref_t
<
decltype
(
input_shape
)
>
output_shape
;
transpose_shape
(
input_shape
,
input_axes
,
begin
(
output_shape
));
const
auto
output_shape
=
transpose
(
input_shape
,
input_axes
);
Tensor
<
InDataType
>
input_tensor
(
input_shape
);
Tensor
<
OutDataType
>
output_tensor
(
output_shape
);
...
...
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