asherliu / thrust

Automatically exported from code.google.com/p/thrust
Apache License 2.0
0 stars 0 forks source link

_1 <= 0 (lambda expression) gives compiler error #342

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/partition.h>
#include <thrust/functional.h>
#include <iostream>

struct less_zero {
  typedef bool result_type;

  __device__
  bool operator()(int x) {
    return x<=0;
  }
};
int main()
{
  int x[7] = {1, 2, 4, 8, -1, 0, 4};
  thrust::device_vector<int> d(x, x+7);

  using namespace thrust::placeholders;

  // Does not work
  thrust::partition(d.begin(), d.end(), _1 <= 0);
  // Works
  //thrust::partition(d.begin(), d.end(), less_zero());

  thrust::copy(d.begin(), d.end(),
               std::ostream_iterator<int>(std::cout, "\n"));
  return 0;
}

Original issue reported on code.google.com by keveman@gmail.com on 11 Jun 2011 at 8:03

GoogleCodeExporter commented 8 years ago

Original comment by jaredhoberock on 11 Jun 2011 at 8:40

GoogleCodeExporter commented 8 years ago

Original comment by jaredhoberock on 11 Jun 2011 at 8:40

GoogleCodeExporter commented 8 years ago
What is the error message?  It seems to work on my platform:

yucky:thrust-tot jared$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Thu_Sep__9_16:01:02_PDT_2010
Cuda compilation tools, release 3.2, V0.2.1221

Original comment by jaredhoberock on 11 Jun 2011 at 8:44

GoogleCodeExporter commented 8 years ago
Works with nvcc 4.0 as well.

Are you sure you have Thrust TOT?  The placeholders were almost completely 
broken before this revision:

http://code.google.com/p/thrust/source/detail?r=6428b3d5579ce071a717ebcf0819ff37
af326de8

Original comment by jaredhoberock on 11 Jun 2011 at 9:00

GoogleCodeExporter commented 8 years ago
Sorry, my bad. Looks like my copy of Thrust was just before this revision. It 
works for me.

Original comment by keveman@gmail.com on 11 Jun 2011 at 10:42

GoogleCodeExporter commented 8 years ago

Original comment by jaredhoberock on 12 Jun 2011 at 12:09