           uint8*            flags)
 {
     const uint32 blockdim = 128;
-    const uint32 n_blocks = (n + blockdim-1) / blockdim;
+    const uint32 n_blocks = util::divide_ri( n, blockdim );
 
     build_head_flags_kernel<<<n_blocks,blockdim>>>(
         n,

          uint8*            flags)
{
    const uint32 blockdim = 128;
    const uint32 n_blocks = ((n+3)/4 + blockdim-1) / blockdim;

    build_head_flags_kernel<<<n_blocks,blockdim>>>(
        n,

          uint32*           comp_flags)
{
    const uint32 blockdim = 128;
    const uint32 n_words  = util::divide_ri( n, 32u );
    const uint32 n_blocks = util::divide_ri( n_words, blockdim );

    pack_flags_kernel<<<n_blocks,blockdim>>>(
        n,
