lion03 / thrust

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

bug in any_of #323

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please post a short, self-contained code sample which reproduces the
problem:

#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/logical.h>
#include <thrust/functional.h>
#include <fstream>
#include <iostream>

struct hasPositiveComponent : thrust::unary_function<float2, bool> {
    __host__ __device__
        bool operator()(float2 x) {
            return ((fabs(x.x) > 0.0001f) || (fabs(x.y) > 0.0001f));
        }
};

int main(void) {
    std::ifstream ifs("breaksAnyOf.txt");
    thrust::host_vector<float2> foo;
    float2 tmp;
    ifs >> tmp.x >> tmp.y;
    while(!ifs.eof()) {
        foo.push_back(tmp);
        ifs >> tmp.x >> tmp.y;
    }
    ifs.close();

    thrust::device_vector<float2> dFoo = foo;
    thrust::device_vector<bool> dBar(foo.size());

    thrust::transform(dFoo.begin(), dFoo.end(), dBar.begin(), hasPositiveComponent());

    bool result1 = thrust::any_of(dFoo.begin(), dFoo.end(), hasPositiveComponent()); //breaks

    bool result2 = thrust::any_of(dBar.begin(), dBar.end(), thrust::identity<bool>()); //works

    bool result3 = thrust::any_of(thrust::make_transform_iterator(dFoo.begin(), hasPositiveComponent()),
                                  thrust::make_transform_iterator(dFoo.end(), hasPositiveComponent()),
                                  thrust::identity<bool>()); //breaks

    std::cout << "All numbers should match...\n";
    std::cout << result1 << " " << result2 << " " << result3 << std::endl;

    return 0;
}

What is the expected output? What do you see instead?

All of the three calls to any_of should produce identical ouput - true, there 
are many positive components in the input data file (attached).  But the 
versions which use a transform_iterator and the functor don't work.

What version of Thrust are you using? Which version of nvcc?  Which host
compiler?  On what operating system?

Appears in both 1.3 and 1.4.  nvcc 3.2, gcc 4.3.2, suse 11.1

Please provide any additional information below.

This bug only appears when compiling with sm_20, sm_13 and below all produce 
the correct output.

Original issue reported on code.google.com by ekel...@gmail.com on 10 Mar 2011 at 7:58

Attachments:

GoogleCodeExporter commented 8 years ago
I can't reproduce the broken behavior with nvcc 4.0 RC and GTX 480.

Erich, can you try again with nvcc 4.0?

Original comment by jaredhoberock on 10 Mar 2011 at 8:16

GoogleCodeExporter commented 8 years ago
Yes, it appears to be fixed in 4.0RC.

Original comment by ekel...@gmail.com on 10 Mar 2011 at 11:07

GoogleCodeExporter commented 8 years ago

Original comment by jaredhoberock on 10 Mar 2011 at 11:07