Assigning an item element


In the SYCL 1.2.1 spec, the SYCL item class includes the following operator definition:

size_t &operator[](int dimension);

This is described as returning the constituent id l-value. In ComputeCpp 1.1.2’s item_base.h I can only see:

size_t operator[](int dimension) const;

This means the following (say) will not compile:

#include <CL/sycl.hpp>

namespace kernels { class K; }

int main(int argc, char *argv[])
  using namespace cl::sycl;
  queue q;

  q.submit([&](handler &cgh) {
    cgh.parallel_for<kernels::K>(range<3>{4,4,4}, [=](item<3> ix) {
      ix[0] = 0;

  return 0;

Indeed it’s unlikely that such an assignment would be a good idea, but it seems to be allowed in the specification. Do you think the spec will change on this point?


Hi Paul,

So the id and range classes do allow you to modify the elements via the subscript operator if the object is non-const. However, the intention of SYCL 1.2.1 is that the id and range objects retrieved via the kernel invocation API are read-only, so the item subscript operator and get_id member function return by value.

I believe the function you mentioned above is on the id and range class but not on the item class.

The example above could be changed to:

q.submit([&](handler &cgh) {
  cgh.parallel_for<kernels::K>(range<3>{4,4,4}, [=](item<3> ix) {
    auto id = ix.get_id();
    id[0] = 0;

However this would not modify the id within the item object, just the local copy.

I hope this helps.



Isn’t the operator[] method I mentioned included on listing line 13 on page 150 as a member of item in the current (1.2.1) spec?