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
bc78c8c8
There was an error fetching the commit references. Please try again later.
Commit
bc78c8c8
authored
7 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Fixed prefix sum in CUDA
parent
909fef43
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TNL/Containers/Algorithms/cuda-prefix-sum_impl.h
+13
-15
13 additions, 15 deletions
src/TNL/Containers/Algorithms/cuda-prefix-sum_impl.h
with
13 additions
and
15 deletions
src/TNL/Containers/Algorithms/cuda-prefix-sum_impl.h
+
13
−
15
View file @
bc78c8c8
...
...
@@ -36,12 +36,11 @@ cudaFirstPhaseBlockPrefixSum( const PrefixSumType prefixSumType,
DataType
*
auxArray
)
{
DataType
*
sharedData
=
TNL
::
Devices
::
Cuda
::
getSharedMemory
<
DataType
>
();
DataType
*
auxData
=
&
sharedData
[
elementsInBlock
+
elementsInBlock
/
Devices
::
Cuda
::
getNumberOfSharedMemoryBanks
()
+
2
];
DataType
*
warpSums
=
&
auxData
[
blockDim
.
x
];
volatile
DataType
*
auxData
=
&
sharedData
[
elementsInBlock
+
elementsInBlock
/
Devices
::
Cuda
::
getNumberOfSharedMemoryBanks
()
+
2
];
volatile
DataType
*
warpSums
=
&
auxData
[
blockDim
.
x
];
const
Index
lastElementIdx
=
size
-
blockIdx
.
x
*
elementsInBlock
;
Index
lastElementInBlock
=
(
lastElementIdx
<
elementsInBlock
?
lastElementIdx
:
elementsInBlock
);
const
Index
lastElementInBlock
=
TNL
::
min
(
lastElementIdx
,
elementsInBlock
);
/***
* Load data into the shared memory.
...
...
@@ -109,7 +108,7 @@ cudaFirstPhaseBlockPrefixSum( const PrefixSumType prefixSumType,
if
(
warpIdx
==
0
)
for
(
int
stride
=
1
;
stride
<
Devices
::
Cuda
::
getWarpSize
();
stride
*=
2
)
if
(
threadInWarpIdx
>=
stride
)
operation
.
commonReduction
(
warpSums
[
threadI
nWarpId
x
],
warpSums
[
threadI
nWarpId
x
-
stride
]
);
operation
.
commonReduction
(
warpSums
[
threadI
dx
.
x
],
warpSums
[
threadI
dx
.
x
-
stride
]
);
__syncthreads
();
/****
...
...
@@ -159,20 +158,19 @@ __global__ void
cudaSecondPhaseBlockPrefixSum
(
Operation
operation
,
const
Index
size
,
const
Index
elementsInBlock
,
const
Index
gridShift
,
DataType
gridShift
,
const
DataType
*
auxArray
,
DataType
*
data
)
{
if
(
blockIdx
.
x
>
0
)
{
DataType
shift
(
gridShift
);
operation
.
commonReduction
(
shift
,
auxArray
[
blockIdx
.
x
-
1
]
);
operation
.
commonReduction
(
gridShift
,
auxArray
[
blockIdx
.
x
-
1
]
);
const
Index
readOffset
=
blockIdx
.
x
*
elementsInBlock
;
Index
readIdx
=
threadIdx
.
x
;
while
(
readIdx
<
elementsInBlock
&&
readOffset
+
readIdx
<
size
)
{
operation
.
commonReduction
(
data
[
readIdx
+
readOffset
],
s
hift
);
operation
.
commonReduction
(
data
[
readIdx
+
readOffset
],
gridS
hift
);
readIdx
+=
blockDim
.
x
;
}
}
...
...
@@ -188,7 +186,7 @@ cudaRecursivePrefixSum( const PrefixSumType prefixSumType,
const
Index
size
,
const
Index
blockSize
,
const
Index
elementsInBlock
,
const
Index
gridShift
,
const
DataType
gridShift
,
const
DataType
*
input
,
DataType
*
output
)
{
...
...
@@ -233,7 +231,7 @@ cudaRecursivePrefixSum( const PrefixSumType prefixSumType,
numberOfBlocks
,
blockSize
,
elementsInBlock
,
(
Index
)
0
,
operation
.
initialValue
()
,
auxArray1
.
getData
(),
auxArray2
.
getData
()
);
...
...
@@ -260,7 +258,7 @@ cudaGridPrefixSum( PrefixSumType prefixSumType,
const
Index
elementsInBlock
,
const
DataType
*
deviceInput
,
DataType
*
deviceOutput
,
Index
&
gridShift
)
DataType
&
gridShift
)
{
cudaRecursivePrefixSum
(
prefixSumType
,
operation
,
...
...
@@ -300,16 +298,16 @@ cudaPrefixSum( const Index size,
/****
* Loop over all grids.
*/
Index
gridShift
=
0
;
DataType
gridShift
=
operation
.
initialValue
()
;
for
(
Index
gridIdx
=
0
;
gridIdx
<
numberOfGrids
;
gridIdx
++
)
{
/****
* Compute current grid size and size of data to be scanned
*/
Index
currentSize
=
size
-
gridIdx
*
maxGridSize
*
elementsInBlock
;
const
Index
gridOffset
=
gridIdx
*
maxGridSize
*
elementsInBlock
;
Index
currentSize
=
size
-
gridOffset
;
if
(
currentSize
/
elementsInBlock
>
maxGridSize
)
currentSize
=
maxGridSize
*
elementsInBlock
;
const
Index
gridOffset
=
gridIdx
*
maxGridSize
*
elementsInBlock
;
cudaGridPrefixSum
(
prefixSumType
,
operation
,
...
...
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