|
25 | 25 | #ifndef CUBOOL_META_HPP |
26 | 26 | #define CUBOOL_META_HPP |
27 | 27 |
|
| 28 | +#include <thrust/device_vector.h> |
| 29 | +#include <thrust/host_vector.h> |
28 | 30 | #include <cstddef> |
29 | 31 |
|
30 | 32 | namespace cubool { |
31 | 33 |
|
32 | | - template <size_t workersCount, size_t blockSize> |
33 | | - struct BinConfig { |
34 | | - static const size_t mWorkersCount = workersCount; |
35 | | - static const size_t mBlockSize = blockSize; |
36 | | - }; |
| 34 | + template <typename Config> |
| 35 | + struct StreamsWrapper { |
| 36 | + StreamsWrapper() { |
| 37 | + for (auto& s: streams) |
| 38 | + cudaStreamCreate(&s); |
| 39 | + } |
37 | 40 |
|
38 | | - template <size_t minBorder, size_t maxBorder> |
39 | | - struct BorderConfig { |
40 | | - static const size_t mMinBorder = minBorder; |
41 | | - static const size_t mMaxBorder = maxBorder; |
42 | | - }; |
| 41 | + ~StreamsWrapper() { |
| 42 | + for (auto& s: streams) |
| 43 | + cudaStreamDestroy(s); |
| 44 | + } |
43 | 45 |
|
44 | | - template <typename ... BinsConfig> |
45 | | - class ComputeConfig { |
46 | | - public: |
| 46 | + cudaStream_t streams[Config::binsCount()] = {}; |
| 47 | + }; |
47 | 48 |
|
48 | | - template<typename T, typename C> |
49 | | - void exec(C& context) { |
50 | | - ExecImpl<void, T, BinsConfig...>::exec(0, context); |
51 | | - } |
| 49 | + template<size_t BlocksSize, size_t Max, size_t Min, size_t Id> |
| 50 | + struct Bin { |
| 51 | + static constexpr size_t blockSize = BlocksSize; |
| 52 | + static constexpr size_t min = Max; |
| 53 | + static constexpr size_t max = Min; |
| 54 | + static constexpr size_t id = Id; |
| 55 | + }; |
52 | 56 |
|
53 | | - private: |
54 | 57 |
|
55 | | - template<typename D, typename T, typename C, typename ... Bins> |
56 | | - struct ExecImpl { |
57 | | - static void exec(size_t index, C& context) { } |
58 | | - }; |
| 58 | + template <typename ... Bins> |
| 59 | + struct Config { |
| 60 | + public: |
59 | 61 |
|
60 | | - template<typename D, typename T, typename C, typename Bin> |
61 | | - struct ExecImpl<D, T, C, Bin> { |
62 | | - static void exec(size_t index, C& context) { |
63 | | - using Timpl = typename T::template function<Bin>; |
| 62 | + static __host__ __device__ size_t selectBin(size_t rowSize) { |
| 63 | + static constexpr size_t mins[] = { Bins::min... }; |
| 64 | + static constexpr size_t maxs[] = { Bins::max... }; |
64 | 65 |
|
65 | | - Timpl timpl; |
66 | | - timpl(index, context); |
| 66 | + for (size_t i = 0; i < binsCount(); i++) { |
| 67 | + if (mins[i] <= rowSize && rowSize <= maxs[i]) |
| 68 | + return i; |
67 | 69 | } |
68 | | - }; |
69 | 70 |
|
70 | | - template<typename D, typename T, typename C, typename Bin, typename ... Bins> |
71 | | - struct ExecImpl<D, T, C, Bin, Bins...> { |
72 | | - static void exec(size_t index, C& context) { |
73 | | - using Timpl = typename T::template function<Bin>; |
| 71 | + return unusedBinId(); |
| 72 | + } |
74 | 73 |
|
75 | | - Timpl timpl; |
76 | | - timpl(index, context); |
| 74 | + static __host__ __device__ constexpr size_t binBlockSize(size_t id) { |
| 75 | + constexpr size_t blockSizes[] = { Bins::blockSize... }; |
| 76 | + return blockSizes[id]; |
| 77 | + } |
77 | 78 |
|
78 | | - ExecImpl<D, T, Bins...>::exec(index + 1, context); |
79 | | - } |
80 | | - }; |
| 79 | + static __host__ __device__ constexpr size_t binsCount() { |
| 80 | + return sizeof...(Bins); |
| 81 | + } |
| 82 | + |
| 83 | + static __host__ __device__ constexpr size_t unusedBinId() { |
| 84 | + return binsCount() + 1; |
| 85 | + } |
81 | 86 |
|
82 | 87 | }; |
83 | 88 |
|
|
0 commit comments