Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
c60aa9e4
There was an error fetching the commit references. Please try again later.
Commit
c60aa9e4
authored
5 years ago
by
Tomáš Oberhuber
Browse files
Options
Downloads
Patches
Plain Diff
Rewritting parallel reduciton with lambda functions.
parent
1997234c
No related branches found
No related tags found
1 merge request
!30
Reduction
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TNL/Containers/Algorithms/CudaReductionKernel.h
+17
-12
17 additions, 12 deletions
src/TNL/Containers/Algorithms/CudaReductionKernel.h
with
17 additions
and
12 deletions
src/TNL/Containers/Algorithms/CudaReductionKernel.h
+
17
−
12
View file @
c60aa9e4
...
@@ -39,14 +39,19 @@ static constexpr int Reduction_registersPerThread = 32; // empirically determi
...
@@ -39,14 +39,19 @@ static constexpr int Reduction_registersPerThread = 32; // empirically determi
static
constexpr
int
Reduction_minBlocksPerMultiprocessor
=
4
;
static
constexpr
int
Reduction_minBlocksPerMultiprocessor
=
4
;
#endif
#endif
template
<
int
blockSize
,
typename
Operation
,
typename
Index
>
template
<
int
blockSize
,
typename
Real
,
typename
FirstPhase
,
typename
SecondPhase
,
typename
Index
,
typename
ResultType
=
decltype
(
std
::
declval
<
FirstPhase
>(
0
,
0
)
)
>
__global__
void
__global__
void
__launch_bounds__
(
Reduction_maxThreadsPerBlock
,
Reduction_minBlocksPerMultiprocessor
)
__launch_bounds__
(
Reduction_maxThreadsPerBlock
,
Reduction_minBlocksPerMultiprocessor
)
CudaReductionKernel
(
Operation
operation
,
CudaReductionKernel
(
const
Real
&
initialValue
,
FirstReduction
&
firstReduction
,
SecondReduction
&
secondReduction
,
const
Index
size
,
const
Index
size
,
const
typename
Operation
::
DataType1
*
input1
,
ResultType
*
output
)
const
typename
Operation
::
DataType2
*
input2
,
typename
Operation
::
ResultType
*
output
)
{
{
typedef
Index
IndexType
;
typedef
Index
IndexType
;
typedef
typename
Operation
::
ResultType
ResultType
;
typedef
typename
Operation
::
ResultType
ResultType
;
...
@@ -62,23 +67,23 @@ CudaReductionKernel( Operation operation,
...
@@ -62,23 +67,23 @@ CudaReductionKernel( Operation operation,
IndexType
gid
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
IndexType
gid
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
const
IndexType
gridSize
=
blockDim
.
x
*
gridDim
.
x
;
const
IndexType
gridSize
=
blockDim
.
x
*
gridDim
.
x
;
sdata
[
tid
]
=
operation
.
initialValue
()
;
sdata
[
tid
]
=
initialValue
;
/***
/***
* Read data into the shared memory. We start with the
* Read data into the shared memory. We start with the
* sequential reduction.
* sequential reduction.
*/
*/
while
(
gid
+
4
*
gridSize
<
size
)
while
(
gid
+
4
*
gridSize
<
size
)
{
{
operation
.
firstReduction
(
sdata
[
tid
],
gid
,
input1
,
input2
);
sdata
[
tid
]
=
firstReduction
(
sdata
[
tid
],
gid
);
operation
.
firstReduction
(
sdata
[
tid
],
gid
+
gridSize
,
input1
,
input2
);
sdata
[
tid
]
=
firstReduction
(
sdata
[
tid
],
gid
+
gridSize
);
operation
.
firstReduction
(
sdata
[
tid
],
gid
+
2
*
gridSize
,
input1
,
input2
);
sdata
[
tid
]
=
firstReduction
(
sdata
[
tid
],
gid
+
2
*
gridSize
);
operation
.
firstReduction
(
sdata
[
tid
],
gid
+
3
*
gridSize
,
input1
,
input2
);
sdata
[
tid
]
=
firstReduction
(
sdata
[
tid
],
gid
+
3
*
gridSize
);
gid
+=
4
*
gridSize
;
gid
+=
4
*
gridSize
;
}
}
while
(
gid
+
2
*
gridSize
<
size
)
while
(
gid
+
2
*
gridSize
<
size
)
{
{
operation
.
firstReduction
(
sdata
[
tid
],
gid
,
input1
,
input2
);
firstReduction
(
sdata
[
tid
],
gid
,
input1
,
input2
);
operation
.
firstReduction
(
sdata
[
tid
],
gid
+
gridSize
,
input1
,
input2
);
firstReduction
(
sdata
[
tid
],
gid
+
gridSize
,
input1
,
input2
);
gid
+=
2
*
gridSize
;
gid
+=
2
*
gridSize
;
}
}
while
(
gid
<
size
)
while
(
gid
<
size
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment