Basic Image AlgorithmS Library
2.8.0
Main Page
Related Pages
Modules
Classes
Examples
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
OpenCLFramework
Algorithm
clfRadixSort.hh
1
// C++ class for sorting integer list in OpenCL
2
// copyright Philippe Helluy, University de Strasbourg, France, 2011, helluy@math.unistra.fr
3
// licensed under the GNU Lesser General Public License see http://www.gnu.org/copyleft/lesser.html
4
// if you find this software usefull you can cite the following work in your reports or articles:
5
// Philippe HELLUY, A portable implementation of the radix sort algorithm in OpenCL, HAL 2011.
6
// The algorithm is the radix sort algorithm
7
// Marcho Zagha and Guy E. Blelloch. "Radix Sort For Vector Multiprocessor."
8
// in: Conference on High Performance Networking and Computing, pp. 712-721, 1991.
9
// each integer is made of _TOTALBITS bits. The radix is made of _BITS bits. The sort is made of
10
// several passes, each consisting in sorting against a group of bits corresponding to the radix.
11
// _TOTALBITS/_BITS passes are needed.
12
// The sorting parameters can be changed in "clfRadixSortParam.hpp"
13
// compilation for Mac:
14
//g++ clfRadixSort.cpp clfRadixSortMain.cpp -framework opencl -Wall
15
// compilation for Linux:
16
//g++ clfRadixSort.cpp clfRadixSortMain.cpp -lOpenCL -Wall
17
18
#ifndef _CLFRADIXSORT_HH_
19
#define _CLFRADIXSORT_HH_
20
21
#include <OpenCLFramework/Algorithm/clfAlgorithm.hh>
22
23
namespace
BIAS {
24
class
BIASOpenCLFramework_EXPORT
clfRadixSort
:
public
clfAlgorithm
{
25
26
public
:
27
clfRadixSort
(
clfContext
*ctx = NULL,
bool
sharedGL =
false
,
unsigned
int
device = 0);
28
29
virtual
~
clfRadixSort
();
30
31
void
SetData(
int
num,
float
*data,
int
scale = 1);
32
33
void
SetData(
int
num,
clfBuffer
*data);
34
35
// this function allows to change the size of the sorted vector
36
void
Resize(
int
nn);
37
38
// this function treats the array d_Keys on the GPU
39
// and return the sorting permutation in the array d_Permut
40
void
Sort();
41
42
void
ApplyPermutation(
clfBuffer
*in,
clfBuffer
*out,
int
elemsize,
int
numElems,
bool
hightolow =
false
);
43
44
// get the data from the GPU (for debugging)
45
void
RecupGPU(
void
);
46
47
// put the data on the host in the GPU
48
void
Host2GPU(
void
);
49
50
// check that the sort is successfull (for debugging)
51
void
Check(
void
);
52
53
// transpose the list for faster memeory access
54
// (improve coalescence)
55
void
Transpose(
int
nbrow,
int
nbcol);
56
57
// compute the histograms for one pass
58
void
Histogram(
unsigned
int
pass);
59
// scan the histograms
60
void
ScanHistogram(
void
);
61
// scan the histograms
62
void
Reorder(
unsigned
int
pass);
63
64
unsigned
int
*GetPermutation(
unsigned
int
num = 0);
65
66
67
// unsigned int h_Histograms[_RADIX * _GROUPS * _ITEMS]; // histograms on the cpu
68
unsigned
int
h_Histograms[5 * 16 * 16];
// histograms on the cpu
69
clfBuffer
*
d_Histograms
;
// histograms on the GPU
70
71
// sum of the local histograms
72
// unsigned int h_globsum[_HISTOSPLIT];
73
unsigned
int
h_globsum[512];
74
clfBuffer
*
d_globsum
;
75
clfBuffer
*
d_temp
;
// in case where the sum is not needed
76
77
// list of keys
78
unsigned
int
nkeys
;
// actual number of keys
79
unsigned
int
nkeys_rounded
;
// next multiple of _ITEMS*_GROUPS
80
unsigned
int
h_checkKeys[(1<<23)];
// a copy for check
81
unsigned
int
h_Keys[(1<<23)];
82
clfBuffer
*
d_inKeys
;
83
clfBuffer
*
d_outKeys
;
84
85
// permutation
86
unsigned
int
h_Permut[(1<<23)];
87
unsigned
int
h_initialPermut[(1<<23)];
88
clfBuffer
*
d_inPermut
;
89
clfBuffer
*
d_outPermut
;
90
91
// timers
92
float
histo_time,scan_time,reorder_time,sort_time,
transpose_time
;
93
94
};
95
}
96
97
#endif
BIAS::clfAlgorithm
Definition:
clfAlgorithm.hh:17
BIAS::clfRadixSort::d_temp
clfBuffer * d_temp
Definition:
clfRadixSort.hh:75
BIAS::clfBuffer
OpenCL Buffer wrapper.
Definition:
clfBuffer.hh:43
BIAS::clfRadixSort::d_Histograms
clfBuffer * d_Histograms
Definition:
clfRadixSort.hh:69
BIAS::clfRadixSort::d_inPermut
clfBuffer * d_inPermut
Definition:
clfRadixSort.hh:88
BIAS::clfRadixSort::d_outPermut
clfBuffer * d_outPermut
Definition:
clfRadixSort.hh:89
BIAS::clfRadixSort
Definition:
clfRadixSort.hh:24
BIAS::clfContext
OpenCL Context wrapper.
Definition:
clfContext.hh:49
BIAS::clfRadixSort::nkeys_rounded
unsigned int nkeys_rounded
Definition:
clfRadixSort.hh:79
BIAS::clfRadixSort::d_outKeys
clfBuffer * d_outKeys
Definition:
clfRadixSort.hh:83
BIAS::clfRadixSort::nkeys
unsigned int nkeys
Definition:
clfRadixSort.hh:78
BIAS::clfRadixSort::d_globsum
clfBuffer * d_globsum
Definition:
clfRadixSort.hh:74
BIAS::clfRadixSort::transpose_time
float transpose_time
Definition:
clfRadixSort.hh:92
BIAS::clfRadixSort::d_inKeys
clfBuffer * d_inKeys
Definition:
clfRadixSort.hh:82
Generated on Tue Feb 6 2018 02:01:42 for Basic Image AlgorithmS Library by
1.8.5