AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
RadixSort.hpp
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
26
27#ifndef RADIXSORT_H_INCLUDED
28#define RADIXSORT_H_INCLUDED
29
31#include "CalcServer.hpp"
32#include "Tool.hpp"
33#include "Kernel.hpp"
34
38#ifndef _ITEMS
39#define _ITEMS 64U
40#endif
44#ifndef _GROUPS
45#define _GROUPS 16U
46#endif
48#ifndef _STEPBITS
49#define _STEPBITS 4U
50#endif
52#define _RADIX (1 << _STEPBITS)
58#ifndef _HISTOSPLIT
59#define _HISTOSPLIT 512U
60#endif
61
62/* Modify data in order to impose that local size don't be lower than
63 * minimum allowed value.
64 */
65#if _ITEMS < __CL_MIN_LOCALSIZE__
66#undef _ITEMS
67#define _ITEMS __CL_MIN_LOCALSIZE__
68#endif
69#if _HISTOSPLIT / 2 < __CL_MIN_LOCALSIZE__
70#undef _HISTOSPLIT
71#define _HISTOSPLIT 2 * __CL_MIN_LOCALSIZE__
72#endif
73#if _RADIX * _GROUPS * _ITEMS / 2 / _HISTOSPLIT < __CL_MIN_LOCALSIZE__
74#undef _GROUPS
75#define _GROUPS 2 * __CL_MIN_LOCALSIZE__* _HISTOSPLIT / (_RADIX * _ITEMS)
76#endif
77
78namespace Aqua {
79namespace CalcServer {
80
94{
95 public:
104 RadixSort(const std::string tool_name,
105 const std::string variable = "icell",
106 const std::string permutations = "id_unsorted",
107 const std::string inv_permutations = "id_sorted",
108 bool once = false);
109
112 ~RadixSort();
113
116 void setup();
117
118 protected:
123 cl_event _execute(const std::vector<cl_event> events);
124
125 private:
129 cl_event init();
130
137 cl_event histograms(cl_event keys_event, cl_event histograms_event);
138
143 cl_event scan(cl_event event);
144
150 cl_event reorder(cl_event perms_event, cl_event histograms_event);
151
155 cl_event inversePermutations();
156
159 void variables();
160
163 void setupOpenCL();
164
168 void setupDims();
169
172 void setupMems();
173
177 template<typename T>
178 void setupTypedArgs();
179
180 void setupArgs();
182
183
185 std::string _var_name;
186
188 std::string _perms_name;
189
191 std::string _inv_perms_name;
192
195
198
200 InputOutput::ArrayVariable* _inv_perms;
201
203 size_t _n;
204
206 size_t _n_padded;
207
209 cl_kernel _init_kernel;
211 cl_kernel _histograms_kernel;
213 cl_kernel _scan_kernel;
215 cl_kernel _paste_kernel;
217 cl_kernel _sort_kernel;
219 cl_kernel _inv_perms_kernel;
220
222 cl_mem _in_vals;
224 cl_mem _out_vals;
226 cl_mem _in_permut;
228 cl_mem _out_permut;
230 cl_mem _histograms;
232 cl_mem _global_sums;
234 cl_mem _temp_mem;
235
237 size_t _items;
239 size_t _groups;
241 size_t _bits;
243 size_t _radix;
245 size_t _histo_split;
246
248 size_t _key_bits;
250 uicl _n_pass;
252 uicl _pass;
253
255 size_t _local_work_size;
258 size_t _global_work_size;
259};
260
261}
262} // namespace
263
264#endif // RADIXSORT_H_INCLUDED
The calculation main entry point. (See Aqua::CalcServer::CalcServer for details)
OpenCL kernel kernel based tool. (see Aqua::CalcServer::Kernel for details)
Tools virtual environment to allow the user to define/manipulate the tools used to carry out the simu...
RadixSort(const std::string tool_name, const std::string variable="icell", const std::string permutations="id_unsorted", const std::string inv_permutations="id_sorted", bool once=false)
Definition RadixSort.cpp:43
void setup()
Definition RadixSort.cpp:114
cl_event _execute(const std::vector< cl_event > events)
Definition RadixSort.cpp:130
~RadixSort()
Definition RadixSort.cpp:83
Tools base class.
Definition Tool.hpp:176
An array variable.
Definition Variable.hpp:894
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
Set of definitions and macros related with the implementation.
#define uicl
Unsigned integer number.
Definition sphPrerequisites.hpp:85