AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
RadixSort.h
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
27#ifndef RADIXSORT_H_INCLUDED
28#define RADIXSORT_H_INCLUDED
29
30#include <sphPrerequisites.h>
31#include <CalcServer.h>
32#include <CalcServer/Tool.h>
33
37#ifndef _ITEMS
38#define _ITEMS 128
39#endif
43#ifndef _GROUPS
44#define _GROUPS 32
45#endif
47#ifndef __UINTBITS__
48#define __UINTBITS__ 32
49#endif
51#ifndef _STEPBITS
52#define _STEPBITS 4
53#endif
55#define _RADIX (1 << _STEPBITS)
61#ifndef _HISTOSPLIT
62#define _HISTOSPLIT 512
63#endif
64
65/* Modify data in order to impose that local size don't be lower than
66 * minimum allowed value.
67 */
68#if _ITEMS < __CL_MIN_LOCALSIZE__
69#undef _ITEMS
70#define _ITEMS __CL_MIN_LOCALSIZE__
71#endif
72#if _HISTOSPLIT / 2 < __CL_MIN_LOCALSIZE__
73#undef _HISTOSPLIT
74#define _HISTOSPLIT 2 * __CL_MIN_LOCALSIZE__
75#endif
76#if _RADIX * _GROUPS * _ITEMS / 2 / _HISTOSPLIT < __CL_MIN_LOCALSIZE__
77#undef _GROUPS
78#define _GROUPS 2 * __CL_MIN_LOCALSIZE__* _HISTOSPLIT / (_RADIX * _ITEMS)
79#endif
80
81namespace Aqua {
82namespace CalcServer {
83
97{
98 public:
107 RadixSort(const std::string tool_name,
108 const std::string variable = "icell",
109 const std::string permutations = "id_unsorted",
110 const std::string inv_permutations = "id_sorted",
111 bool once = false);
112
115 ~RadixSort();
116
119 void setup();
120
121 protected:
126 cl_event _execute(const std::vector<cl_event> events);
127
128 private:
132 cl_event init();
133
140 cl_event histograms(cl_event keys_event, cl_event histograms_event);
141
146 cl_event scan(cl_event event);
147
153 cl_event reorder(cl_event perms_event, cl_event histograms_event);
154
158 cl_event inversePermutations();
159
162 void variables();
163
166 void setupOpenCL();
167
171 void setupDims();
172
175 void setupMems();
176
179 void setupArgs();
180
182 std::string _var_name;
183
185 std::string _perms_name;
186
188 std::string _inv_perms_name;
189
192
195
197 InputOutput::ArrayVariable* _inv_perms;
198
200 unsigned int _n;
201
203 cl_kernel _init_kernel;
205 cl_kernel _histograms_kernel;
207 cl_kernel _scan_kernel;
209 cl_kernel _paste_kernel;
211 cl_kernel _sort_kernel;
213 cl_kernel _inv_perms_kernel;
214
216 cl_mem _in_keys;
218 cl_mem _out_keys;
220 cl_mem _in_permut;
222 cl_mem _out_permut;
224 cl_mem _histograms;
226 cl_mem _global_sums;
228 cl_mem _temp_mem;
229
231 unsigned int _items;
233 unsigned int _groups;
235 unsigned int _bits;
237 unsigned int _radix;
239 unsigned int _histo_split;
240
242 unsigned int _key_bits;
244 unsigned int _n_pass;
246 unsigned int _pass;
247
249 size_t _local_work_size;
252 size_t _global_work_size;
253};
254
255}
256} // namespace
257
258#endif // RADIXSORT_H_INCLUDED
The calculation main entry point. (See Aqua::CalcServer::CalcServer for details)
Tools virtual environment to allow the user to define/manipulate the tools used to carry out the simu...
Methods to perform a radix sort using the GPU (or any device supported by OpenCL)....
Definition: RadixSort.h:97
void setup()
Definition: RadixSort.cpp:119
cl_event _execute(const std::vector< cl_event > events)
Definition: RadixSort.cpp:135
~RadixSort()
Definition: RadixSort.cpp:75
Tools base class. The way that AQUAgpusph compute each problem is set through a set of tools that are...
Definition: Tool.h:46
Definition: Variable.h:700
Main AQUAgpusph namespace.
Definition: ArgumentsManager.cpp:45
Set of definitions and macros related with the implementation.