cccl icon indicating copy to clipboard operation
cccl copied to clipboard

[BUG]: `reduce_by_key` fails with zip_iterator to const pointers

Open upsj opened this issue 1 year ago • 5 comments

Is this a duplicate?

  • [X] I confirmed there appear to be no duplicate issues for this bug and that I agree to the Code of Conduct

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

The following code fails to compile with CUDA 12.4 (tracked by upstream issue https://github.com/ginkgo-project/ginkgo/issues/1564)

#include <thrust/execution_policy.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/reduce.h>
#include <thrust/tuple.h>

void sum_duplicates(int size) {
  const int *rows{};
  const int *cols{};
  const float *in_vals{};
  int *out_rows{};
  int *out_cols{};
  float *out_vals{};
  auto in_locs = thrust::make_zip_iterator(thrust::make_tuple(rows, cols));
  auto out_locs =
      thrust::make_zip_iterator(thrust::make_tuple(out_rows, out_cols));
  thrust::reduce_by_key(thrust::device, in_locs, in_locs + size, in_vals,
                        out_locs, out_vals);
}

Noteworthy: The issue goes away when the pointers are int* instead of const int*

How to Reproduce

  • call nvcc file.cu

Expected behavior

The code compiles (as it did with CUDA <= 12.3)

Reproduction link

No response

Operating System

Ubuntu 22.04

nvidia-smi output

No response

NVCC version

nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2024 NVIDIA Corporation Built on Tue_Feb_27_16:19:38_PST_2024 Cuda compilation tools, release 12.4, V12.4.99 Build cuda_12.4.r12.4/compiler.33961263_0

upsj avatar Mar 09 '24 13:03 upsj

A possible workaround here is to const_cast the inputs, but I would like to hear if there is a less "unsafe" workaround we can apply.

upsj avatar Mar 09 '24 14:03 upsj

Are you building against current main or a specific branch?

miscco avatar Mar 10 '24 09:03 miscco

I just checked, the issue is still present in main

upsj avatar Mar 10 '24 12:03 upsj

@upsj Thanks a lot for the bug report. I opened a PR with a fix and added your reproducer to out test suite

miscco avatar Mar 11 '24 08:03 miscco

That was quick, thank you very much!

upsj avatar Mar 11 '24 12:03 upsj