Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat t1008.cu
- #include <thrust/device_vector.h>
- #include <thrust/transform.h>
- #include <thrust/merge.h>
- #include <thrust/iterator/zip_iterator.h>
- struct multiply_transformation : public thrust::binary_function<thrust::tuple<int, int>, thrust::tuple<int, int>, thrust::tuple<int, int> >
- {
- __host__ __device__
- thrust::tuple<int, int> operator()(thrust::tuple<int, int> d_left, thrust::tuple<int, int> d_right)
- {
- if (thrust::get<0>(d_left) == thrust::get<1>(d_right)) {
- return thrust::make_tuple(thrust::get<0>(d_left), thrust::get<1>(d_left) * thrust::get<1>(d_right));
- }
- return thrust::make_tuple(-1, -1);
- }
- };
- int main(){
- int h_leftCount = 1;
- int h_rightCount = 1;
- thrust::device_vector<int> d_leftCountKeys(h_leftCount);
- thrust::device_vector<int> d_rightCountKeys(h_rightCount);
- thrust::device_vector<int> d_leftCounts(h_leftCount);
- thrust::device_vector<int> d_rightCounts(h_rightCount);
- thrust::device_vector<int> d_mergedKeys(h_leftCount + h_rightCount);
- thrust::device_vector<int> d_mergedValues(h_leftCount + h_rightCount);
- thrust::merge_by_key(d_leftCountKeys.begin(), d_leftCountKeys.begin() + h_leftCount,
- d_rightCountKeys.begin(), d_rightCountKeys.begin() + h_rightCount,
- d_leftCounts.begin(), d_rightCounts.begin(), d_mergedKeys.begin(), d_mergedValues.begin());
- typedef thrust::tuple<thrust::device_vector<int>::iterator, thrust::device_vector<int>::iterator > ZipTuple;
- thrust::zip_iterator<ZipTuple> d_zippedCounts(thrust::make_tuple(d_mergedKeys.begin(), d_mergedValues.begin()));
- thrust::zip_iterator<ZipTuple> d_zippedCountsOffset(d_zippedCounts + 1);
- multiply_transformation transformOperator;
- typedef thrust::tuple<int, int> IntTuple;
- thrust::device_vector<IntTuple> d_transformedResult(h_leftCount + h_rightCount);
- thrust::transform(d_zippedCounts, d_zippedCounts + h_leftCount + h_rightCount - 1, d_zippedCountsOffset, d_transformedResult.begin(), transformOperator);
- }
- $ nvcc -o t1008 t1008.cu
- $ ./t1008
- $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement