torchsparse icon indicating copy to clipboard operation
torchsparse copied to clipboard

[BUG] some code mistakes on hash_kernel

Open zjp-shadow opened this issue 3 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

When we test the functions of hash, we meet the error when offset equals to $0$ , and find out the results when using sphashquery is not $[0, 1, \dots, n-1]$. Then we find the bugs in hash_kernel.

void cpu_kernel_hash_wrapper(int N, int K, const int *data,
                             const int *kernel_offset, int64_t *out) {
  for (int k = 0; k < K; k++) {
#pragma omp parallel for
    for (int i = 0; i < N; i++) {
      int cur_coord[4];
      for (int j = 0; j < 3; j++) {
        cur_coord[j] = data[i * 4 + j] + kernel_offset[k * 3 + j];
      }
      cur_coord[3] = data[3];
      uint64_t hash = 14695981039346656037UL;
      for (int j = 0; j < 4; j++) {
        hash ^= (unsigned int)cur_coord[j];
        hash *= 1099511628211UL;
      }
      hash = (hash >> 60) ^ (hash & 0xFFFFFFFFFFFFFFF);
      out[k * N + i] = hash;
    }
  }
}

I think for the same points in query, the batch_id should be the same too.

It can be corrected as

cur_coord[3] = data[i * 4 + 3];

Expected Behavior

No response

Environment

No response

Anything else?

No response

zjp-shadow avatar Jul 26 '22 04:07 zjp-shadow