summaryrefslogtreecommitdiff
path: root/sortlib.cuh
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-05-17 14:08:08 +0800
committerKunoiSayami <[email protected]>2023-05-17 14:08:08 +0800
commit1ad1e0ebf58da30ee7f65a3a1f2a8f62900c47d5 (patch)
tree7d5dfa70354deee42d436328cfb6474a38dbb1ef /sortlib.cuh
parente503cc4de4f7f2e3387e55c77ab1690f709b7687 (diff)
fix: Fix fast_log
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'sortlib.cuh')
-rw-r--r--sortlib.cuh19
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: