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
506a73ec
"test/git@developer.sourcefind.cn:change/sglang.git" did not exist on "5493c3343e3860e909ab528a6a23a2008013b1ae"
Commit
506a73ec
authored
Jun 25, 2019
by
Paul
Browse files
Reduce number of index calculations
parent
6bc2d0e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
5 deletions
+22
-5
src/targets/gpu/device/include/migraphx/gpu/device/shape.hpp
src/targets/gpu/device/include/migraphx/gpu/device/shape.hpp
+16
-0
src/targets/gpu/device/reduce_sum.cpp
src/targets/gpu/device/reduce_sum.cpp
+6
-5
No files found.
src/targets/gpu/device/include/migraphx/gpu/device/shape.hpp
View file @
506a73ec
...
@@ -73,6 +73,22 @@ struct hip_shape
...
@@ -73,6 +73,22 @@ struct hip_shape
}
}
return
result
;
return
result
;
}
}
MIGRAPHX_DEVICE_CONSTEXPR
hip_index
carry
(
hip_index
result
)
const
{
std
::
ptrdiff_t
rem
=
0
;
for
(
std
::
ptrdiff_t
i
=
result
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
auto
z
=
result
[
i
]
+
rem
;
rem
=
z
-
std
::
ptrdiff_t
(
lens
[
i
])
+
1
;
if
(
rem
>
0
)
z
-=
rem
;
else
rem
=
0
;
result
[
i
]
=
z
;
}
return
result
;
}
};
};
template
<
std
::
size_t
N
>
template
<
std
::
size_t
N
>
...
...
src/targets/gpu/device/reduce_sum.cpp
View file @
506a73ec
...
@@ -61,7 +61,7 @@ void reduce_sum(hipStream_t stream, const argument& result, const argument& arg)
...
@@ -61,7 +61,7 @@ void reduce_sum(hipStream_t stream, const argument& result, const argument& arg)
else
else
return
y
;
return
y
;
});
});
shape
reduce_slice
{
output_shape
.
type
(),
reduce_lens
,
input_shape
.
strides
()
};
shape
reduce_slice
{
output_shape
.
type
(),
reduce_lens
};
hip_visit_all
(
result
,
arg
,
reduce_slice
)([
&
](
auto
output
,
auto
input
,
auto
reduce_shape
)
{
hip_visit_all
(
result
,
arg
,
reduce_slice
)([
&
](
auto
output
,
auto
input
,
auto
reduce_shape
)
{
auto
nelements
=
result
.
get_shape
().
elements
();
auto
nelements
=
result
.
get_shape
().
elements
();
auto
relements
=
reduce_slice
.
elements
();
auto
relements
=
reduce_slice
.
elements
();
...
@@ -69,13 +69,14 @@ void reduce_sum(hipStream_t stream, const argument& result, const argument& arg)
...
@@ -69,13 +69,14 @@ void reduce_sum(hipStream_t stream, const argument& result, const argument& arg)
const
std
::
size_t
max_block_size
=
1024
;
const
std
::
size_t
max_block_size
=
1024
;
const
std
::
size_t
block_size
=
compute_block_size
(
relements
,
max_block_size
);
const
std
::
size_t
block_size
=
compute_block_size
(
relements
,
max_block_size
);
gs_launch
(
stream
,
nelements
*
block_size
,
block_size
)([
=
](
auto
i
,
auto
idx
)
__device__
{
gs_launch
(
stream
,
nelements
*
block_size
,
block_size
)([
=
](
auto
i
,
auto
idx
)
__device__
{
auto
base
_idx
=
output
.
get_shape
().
multi
(
i
/
block_size
)
;
const
auto
out
_idx
=
i
/
block_size
;
auto
offset
=
in
put
.
get_shape
().
index
(
base
_idx
);
auto
base_idx
=
out
put
.
get_shape
().
multi
(
out
_idx
);
auto
r
=
block_reduce
<
max_block_size
>
(
idx
,
sum
{},
0
,
relements
,
[
&
](
auto
j
)
__device__
{
auto
r
=
block_reduce
<
max_block_size
>
(
idx
,
sum
{},
0
,
relements
,
[
&
](
auto
j
)
__device__
{
return
input
.
data
()[
reduce_shape
.
index
(
j
)
+
offset
];
auto
reduce_idx
=
reduce_shape
.
multi
(
j
);
return
input
[
reduce_idx
+
base_idx
];
});
});
if
(
idx
.
local
==
0
)
if
(
idx
.
local
==
0
)
output
.
data
()[
i
/
block_size
]
=
r
;
output
.
data
()[
out_idx
]
=
r
;
});
});
});
});
}
}
...
...
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