KhronosGroup / KhronosGroup/SYCL-Docs

Comparison operators for range and id don't return bool

Open
#362 20 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
158
Forks
80
Avg merge
7d 6h
Merged PRs (30d)
5

Description

The comparison operators (`<`, `>`, `<=`, `>=`) for `range` are defined in [4.9.1.1](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#range-class) as:
```c++
// OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >=
friend range operatorOP(const size_t& lhs, const range& rhs) { /* ... */
}
```

The equivalent operators for `id` are similarly defined in [4.9.1.3](https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#range-class) as:
```c++
// OP is: +, -, *, /, %, <<, >>, &, |, ^, &&, ||, <, >, <=, >=
friend id operatorOP(const id& lhs, const id& rhs) { /* ... */
}
friend id operatorOP(const id& lhs, const size_t& rhs) { /* ... */
}
```

I find this behavior confusing. I understand that imposing a strict ordering on these multi-dimensional objects doesn't make a lot of sense, which makes it impossible to return a `bool` in general. But in the 1-dimensional case we _could_ return a `bool`, and in the multi-dimensional case a developer will always have to loop through the resulting range (so it's unclear if this operator would actually make their code any simpler).

Is there a use-case for the multi-dimensional comparisons? It seems like only allowing comparisons for the one-dimensional cases would be simpler.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with SYCL specification sections 4.9.1.1 and 4.9.1.3, linked in the issue, and review the 20-comment discussion for an agreed direction. Determine whether the range and id comparison operators should be changed or clarified; done means a decided specification change or an explicit rationale for retaining the current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.