Skip to content

Commit

Permalink
Merge pull request #134 from alicevision/cuda/fix_thrust
Browse files Browse the repository at this point in the history
[cuda] fix CCTAG_NO_THRUST_COPY_IF code
  • Loading branch information
fabiencastan authored Oct 5, 2020
2 parents 19e3b97 + f337381 commit ebdfe26
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/cctag/cuda/frame_07d_vote_if.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <thrust/copy.h>
#include <thrust/device_ptr.h>
#ifdef CCTAG_NO_THRUST_COPY_IF
#include <thrust/host_vector.h>
#endif

#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -60,21 +63,21 @@ bool Frame::applyVoteIf( )
NumVotersIsGreaterEqual select_op( _voters.dev );

#ifdef CCTAG_NO_THRUST_COPY_IF
#
# There are reports that the Thrust::copy_if fails when you generated code with CUDA 7.0 and run it only
# a 2nd gen Maxwell card (e.g. GTX 980 and GTX 980 Ti). Also, the GTX 1080 seems to be quite similar to
# the GTX 980 and may be affected as well.
# The following code moves everything to host before copy_if, which circumvents the problem but is much
# slower. Make sure that the condition for activating it is very strict.
#
//
// There are reports that the Thrust::copy_if fails when you generated code with CUDA 7.0 and run it only
// a 2nd gen Maxwell card (e.g. GTX 980 and GTX 980 Ti). Also, the GTX 1080 seems to be quite similar to
// the GTX 980 and may be affected as well.
// The following code moves everything to host before copy_if, which circumvents the problem but is much
// slower. Make sure that the condition for activating it is very strict.
//
thrust::host_vector<int> input_host(sz);
thrust::host_vector<int> output_host(sz);
thrust::host_vector<int>::iterator output_host_end;

thrust::copy( input_begin, input_end, input_host.begin() );
output_host_end = thrust::copy_if( input_host.begin(), input_host.end(), output_host.begin(), select_op );
thrust::copy( output_host.begin(), output_host_end, output_begin );
sz = output_host_end = output_host.begin();
sz = output_host_end - output_host.begin();
output_end = output_begin + sz;
#else
output_end = thrust::copy_if( input_begin, input_end, output_begin, select_op );
Expand Down

0 comments on commit ebdfe26

Please sign in to comment.