diff options
Diffstat (limited to 'sortlib.cuh')
| -rw-r--r-- | sortlib.cuh | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/sortlib.cuh b/sortlib.cuh index fa306b0..5d32e4b 100644 --- a/sortlib.cuh +++ b/sortlib.cuh @@ -17,10 +17,12 @@ public: const int MOVE_OFFSET; const unsigned int STEP_LIMIT; - // IEEE 754 __device__ __host__ static size_t fast_log(size_t a) { - float t = a; - return (((*(int *)&t) >> 23) + 1) & 127; +#ifdef __CUDA_ARCH__ + return log2((double)a); +#else + return std::log2(a); +#endif } __device__ __host__ size_t calculate_index(size_t rank) const { @@ -38,7 +40,11 @@ public: for (size_t i = 0; i < LENGTH; i++) { auto left = calculate_index(i); auto right = calculate_rank(left - 1); - + if (i + 1 == LENGTH || i + 1 != right) { + printf("%lu %lu %lu\n", i, left, right); + printf("%lu %lu %lu\n", LENGTH, fast_log(i + 1), + (LENGTH + 1) >> fast_log(i + 1) >> 1); + } assert(i + 1 == right); } } @@ -176,6 +182,11 @@ __global__ void testCustomCalculation(size_t length) { CustomSort(length, sizeof(long) * 8).testCalculation(); } +__global__ void testCustomCalculationWithPrint(size_t length) { + CustomSort(length, sizeof(long) * 8).testCalculation(); + printf("%lu pass\n", length); +} + class FactorySort { public: |
