                                      size_t N,
                                      cudaStream_t stream)
 {
-  std::vector<size_t> levels;
-  calcLevelSizes(levels, N);
-
-  std::vector<size_t> offsets;
-  offsets.push_back(0);
-  size_t alignment = 128 / sizeof(uint32_t);
-  for (size_t i = 0; i < levels.size(); i++) {
-    size_t levelSize = (levels[i] + alignment - 1) & ~alignment;
-    offsets.push_back(offsets[i] + levelSize);
-  }
-
   if (N <= std::numeric_limits<uint32_t>::max()) {
+    uint32_t n = static_cast<uint32_t>(N);
+
+    std::vector<uint32_t> levels;
+    calcLevelSizes(levels, n);
+
+    std::vector<uint32_t> offsets;
+    offsets.push_back(0);
+    size_t alignment = 128 / sizeof(uint32_t);
+    for (size_t i = 0; i < levels.size(); i++) {
+      size_t levelSize = (levels[i] + alignment - 1) & ~alignment;
+      offsets.push_back(offsets[i] + levelSize);
+    }
+
     uint32_t blockSize = SCAN_WARPS * WARPSIZE;
-    uint32_t n = static_cast<uint32_t>(N);
 
     if (levels.empty()) {
 

                                                             scratch_d + offsets[l],
                                                             levels[l]);
      }


    }

#include <limits>
#include <vector>
#include <algorithm>
#include "Scan.h"

#define WARPSIZE 32
