2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
#ifndef B3_RADIXSORT32_H
|
|
|
|
#define B3_RADIXSORT32_H
|
|
|
|
|
|
|
|
#include "b3OpenCLArray.h"
|
|
|
|
|
|
|
|
struct b3SortData
|
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
union {
|
2017-08-01 14:30:58 +02:00
|
|
|
unsigned int m_key;
|
|
|
|
unsigned int x;
|
|
|
|
};
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
union {
|
2017-08-01 14:30:58 +02:00
|
|
|
unsigned int m_value;
|
|
|
|
unsigned int y;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#include "b3BufferInfoCL.h"
|
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
class b3RadixSort32CL
|
2017-08-01 14:30:58 +02:00
|
|
|
{
|
2019-01-03 14:26:51 +01:00
|
|
|
b3OpenCLArray<unsigned int>* m_workBuffer1;
|
|
|
|
b3OpenCLArray<unsigned int>* m_workBuffer2;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
b3OpenCLArray<b3SortData>* m_workBuffer3;
|
|
|
|
b3OpenCLArray<b3SortData>* m_workBuffer4;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
b3OpenCLArray<unsigned int>* m_workBuffer3a;
|
|
|
|
b3OpenCLArray<unsigned int>* m_workBuffer4a;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cl_command_queue m_commandQueue;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cl_kernel m_streamCountSortDataKernel;
|
|
|
|
cl_kernel m_streamCountKernel;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
cl_kernel m_prefixScanKernel;
|
|
|
|
cl_kernel m_sortAndScatterSortDataKernel;
|
|
|
|
cl_kernel m_sortAndScatterKernel;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
bool m_deviceCPU;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
class b3PrefixScanCL* m_scan;
|
|
|
|
class b3FillCL* m_fill;
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct b3ConstData
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
int m_n;
|
|
|
|
int m_nWGs;
|
|
|
|
int m_startBit;
|
|
|
|
int m_nBlocksPerWG;
|
|
|
|
};
|
2017-08-01 14:30:58 +02:00
|
|
|
enum
|
2019-01-03 14:26:51 +01:00
|
|
|
{
|
|
|
|
DATA_ALIGNMENT = 256,
|
|
|
|
WG_SIZE = 64,
|
|
|
|
BLOCK_SIZE = 256,
|
|
|
|
ELEMENTS_PER_WORK_ITEM = (BLOCK_SIZE / WG_SIZE),
|
|
|
|
BITS_PER_PASS = 4,
|
|
|
|
NUM_BUCKET = (1 << BITS_PER_PASS),
|
|
|
|
// if you change this, change nPerWI in kernel as well
|
|
|
|
NUM_WGS = 20 * 6, // cypress
|
|
|
|
// NUM_WGS = 24*6, // cayman
|
|
|
|
// NUM_WGS = 32*4, // nv
|
|
|
|
};
|
2017-08-01 14:30:58 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
public:
|
2019-01-03 14:26:51 +01:00
|
|
|
b3RadixSort32CL(cl_context ctx, cl_device_id device, cl_command_queue queue, int initialCapacity = 0);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
virtual ~b3RadixSort32CL();
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void execute(b3OpenCLArray<unsigned int>& keysIn, b3OpenCLArray<unsigned int>& keysOut, b3OpenCLArray<unsigned int>& valuesIn,
|
|
|
|
b3OpenCLArray<unsigned int>& valuesOut, int n, int sortBits = 32);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
///keys only
|
|
|
|
void execute(b3OpenCLArray<unsigned int>& keysInOut, int sortBits = 32);
|
2017-08-01 14:30:58 +02:00
|
|
|
|
2019-01-03 14:26:51 +01:00
|
|
|
void execute(b3OpenCLArray<b3SortData>& keyValuesInOut, int sortBits = 32);
|
|
|
|
void executeHost(b3OpenCLArray<b3SortData>& keyValuesInOut, int sortBits = 32);
|
|
|
|
void executeHost(b3AlignedObjectArray<b3SortData>& keyValuesInOut, int sortBits = 32);
|
2017-08-01 14:30:58 +02:00
|
|
|
};
|
2019-01-03 14:26:51 +01:00
|
|
|
#endif //B3_RADIXSORT32_H
|