Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

thrust::find doesn't handle asymmetric equality operator #1229

Closed
@dkolsen-pgi

Description

@dkolsen-pgi

thrust::find fails to compile when the input iterator's value type is different from the type of the value being searched for and neither type is convertible to the other, even when there is an overloaded operator== that takes objects of those two different types.

Given the following CUDA program:

#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/find.h>
#include <cassert>

class Weird {
  int value;
 public:
  friend __host__ __device__ bool operator==(int x, Weird y) {
    return x == y.value;
  }
  __host__ __device__ Weird(int val, int) : value(val) { }
};

int main() {
  thrust::host_vector<int> v;
  for (int i = 0; i < 10000; ++i) {
    v.push_back(i);
  }
  thrust::device_vector<int> dv(v);
  auto result = thrust::find(dv.begin(), dv.end(), Weird(333, 0));
  assert(*result == 333);
}

When compiled with NVCC 11.0 and the latest Thrust source from the main branch, this fails with:

/proj/cuda/thrust/master/thrust/detail/functional/operators/operator_adaptors.h(108): error: function "thrust::equal_to<T>::operator() [with T=int]" cannot be ca
lled with the given argument list
            argument types are: (int, Weird)
            object type is: thrust::equal_to<int>

(followed by a typical template instantiation novel).

This is a recent regression. It broke somewhere between July 3 and July 6. I have not looked to see which commit might have caused the regression. When compiled with the Thrust in CUDA 11.0, this test case compiles successfully.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions