Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GPUSort
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
TNL
GPUSort
Commits
45bf0dae
There was an error fetching the commit references. Please try again later.
Commit
45bf0dae
authored
3 years ago
by
Xuan Thang Nguyen
Browse files
Options
Downloads
Patches
Plain Diff
roll back 1st step
parent
cbe260c1
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
GPUSort/src/bitonicSort/bitonicSort.h
+41
-7
41 additions, 7 deletions
GPUSort/src/bitonicSort/bitonicSort.h
with
41 additions
and
7 deletions
GPUSort/src/bitonicSort/bitonicSort.h
+
41
−
7
View file @
45bf0dae
...
...
@@ -108,15 +108,49 @@ template <typename Value, typename CMP>
__global__
void
bitoniSort1stStepSharedMemory
(
TNL
::
Containers
::
ArrayView
<
Value
,
TNL
::
Devices
::
Cuda
>
arr
,
CMP
Cmp
)
{
extern
__shared__
int
externMem
[];
int
sharedMemLen
=
2
*
blockDim
.
x
;
Value
*
sharedMem
=
(
Value
*
)
externMem
;
int
sharedMemLen
=
2
*
blockDim
.
x
;
int
myBlockStart
=
blockIdx
.
x
*
sharedMemLen
;
int
myBlockEnd
=
TNL
::
min
(
arr
.
getSize
(),
myBlockStart
+
sharedMemLen
);
int
myBlockEnd
=
TNL
::
min
(
arr
.
getSize
(),
myBlockStart
+
sharedMemLen
);
if
(
blockIdx
.
x
%
2
||
blockIdx
.
x
+
1
==
gridDim
.
x
)
bitonicSort_Block
(
arr
.
getView
(
myBlockStart
,
myBlockEnd
),
arr
.
getView
(
myBlockStart
,
myBlockEnd
),
(
Value
*
)
externMem
,
Cmp
);
else
bitonicSort_Block
(
arr
.
getView
(
myBlockStart
,
myBlockEnd
),
arr
.
getView
(
myBlockStart
,
myBlockEnd
),
(
Value
*
)
externMem
,
[
&
]
__cuda_callable__
(
const
Value
&
a
,
const
Value
&
b
)
{
return
Cmp
(
b
,
a
);
});
//copy from globalMem into sharedMem
for
(
int
i
=
threadIdx
.
x
;
myBlockStart
+
i
<
myBlockEnd
;
i
+=
blockDim
.
x
)
sharedMem
[
i
]
=
arr
[
myBlockStart
+
i
];
__syncthreads
();
//------------------------------------------
//bitonic activity
{
int
i
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
int
paddedSize
=
closestPow2
(
myBlockEnd
-
myBlockStart
);
for
(
int
monotonicSeqLen
=
2
;
monotonicSeqLen
<=
paddedSize
;
monotonicSeqLen
*=
2
)
{
//calculate the direction of swapping
int
monotonicSeqIdx
=
i
/
(
monotonicSeqLen
/
2
);
bool
ascending
=
(
monotonicSeqIdx
&
1
)
!=
0
;
if
((
monotonicSeqIdx
+
1
)
*
monotonicSeqLen
>=
arr
.
getSize
())
//special case for parts with no "partner"
ascending
=
true
;
for
(
int
len
=
monotonicSeqLen
;
len
>
1
;
len
/=
2
)
{
//calculates which 2 indexes will be compared and swap
int
part
=
threadIdx
.
x
/
(
len
/
2
);
int
s
=
part
*
len
+
(
threadIdx
.
x
&
((
len
/
2
)
-
1
));
int
e
=
s
+
len
/
2
;
if
(
e
<
myBlockEnd
-
myBlockStart
)
//touching virtual padding
cmpSwap
(
sharedMem
[
s
],
sharedMem
[
e
],
ascending
,
Cmp
);
__syncthreads
();
}
}
}
//writeback to global memory
for
(
int
i
=
threadIdx
.
x
;
myBlockStart
+
i
<
myBlockEnd
;
i
+=
blockDim
.
x
)
arr
[
myBlockStart
+
i
]
=
sharedMem
[
i
];
}
//---------------------------------------------
...
...
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