Skip to content

[BUG] CCCL.C output iterator cccl_iterator_t::value_type::size does not match JIT-compiled sizeof(iterator::value_type) #7169

Closed

Description

@bernhardmgruber

When an output iterator is created in CCCL.C with:

  iterator_t<int, random_access_iterator_state_t<int>> output_it =
    make_random_access_iterator<int>(iterator_kind::OUTPUT, "int", "out", " * 2");

and a cccl_iterator_t is obtained from output_it, it reports a value type size of 4:

((cccl_iterator_t)output_it).value_type.size == 4

This is somewhat ok.

The problem is that the source code generated for the JIT compiler defines the iterator as:

#define DIFF_T ::cuda::std::int64_t
#define OP_ALIGNMENT 8
#define OP_SIZE 8
#define VALUE_T ::cuda::std::int32_t
#define DEREF outdereference
#define ADVANCE outadvance

// Kernel Source

extern "C" __device__ void DEREF(const void *self_ptr, const void* x);
extern "C" __device__ void ADVANCE(void *self_ptr, const void* offset);
struct __align__(OP_ALIGNMENT) output_iterator_t_state_t {
  char data[OP_SIZE];
};
struct output_iterator_t_proxy_t {
  __device__ output_iterator_t_proxy_t operator=(VALUE_T x) {
    DEREF(&state, &x);
    return *this;
  }
  output_iterator_t_state_t state;
};
struct output_iterator_t {
  using iterator_category = cuda::std::random_access_iterator_tag;
  using difference_type   = DIFF_T;
  using value_type        = void; // !!!!!!!!!!!!!!!!!!!!!!!!!
  using pointer           = output_iterator_t_proxy_t*;
  using reference         = output_iterator_t_proxy_t;
  __device__ output_iterator_t_proxy_t operator*() const { return {state}; }
  __device__ output_iterator_t& operator+=(difference_type diff) {
      ADVANCE(&state, &diff);
      return *this;
  }
  __device__ output_iterator_t_proxy_t operator[](difference_type diff) const {
    output_iterator_t result = *this;
    result += diff;
    return { result.state };
  }
  __device__ output_iterator_t operator+(difference_type diff) const {
    output_iterator_t result = *this;
    result += diff;
    return result;
  }
  output_iterator_t_state_t state;
};


#undef DIFF_T
#undef OP_ALIGNMENT
#undef OP_SIZE
#undef VALUE_T
#undef DEREF
#undef ADVANCE

As we can see, it defines a using value_type = void; so when the JIT-compiled kernel asks for the value type's size, it gets a different answer than 4 (sizeof(void) is undefined, but CUB has a type function size_of<void> reporting 0).

This is a problem, because this causes cub::DeviceTransform in #6914 to generate different tuning policies on the host and the device, leading to test failures.

This can be fixed by defining using value_type = VALUE_T;, but output iterators do conventionally have a value_type of void. Trying to extend make_random_access_iterator to accept void as value type but having an iterator state of int seemed tedious.

A decision is needed to unblock #6914.

Activity

  1. gevtushenko commented on Jan 12, 2026

    @gevtushenko
    Collaborator

    Ultimately, we need void as value type for output iterators for things like discard iterator. That said, I don't think that we want all the output iterators to have void as value type. The examples in cccl.c tests are mostly transform output iterators. Thrust's transform output iterator does advertices proper value type, so I think we should do the same. I'd prefer to have a dedicated test on cccl.c end that covers discard iterator to check that void output value type is treated properly.

  2. self-assigned this
    on Jan 20, 2026
  3. griwes commented on Jan 30, 2026

    @griwes
    Contributor

    Should now be resolved by #7399.

  4. moved this from Todo to Done in CCCLon Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions