Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. $ cat t735.cu
  2. #include <thrust/device_vector.h>
  3. #include <thrust/iterator/permutation_iterator.h>
  4. #include <thrust/iterator/transform_iterator.h>
  5. #include <thrust/device_ptr.h>
  6. #include <thrust/extrema.h>
  7. #include <stdint.h>
  8.  
  9. #define DSIZE 4
  10.  
  11. // Piece 1
  12. struct MultiplyFunction : public thrust::unary_function<uint32_t, uint32_t> {
  13. uint32_t Y;
  14.  
  15. MultiplyFunction( uint32_t y ) {
  16. Y = y;
  17. }
  18. __device__ uint32_t operator()( uint32_t x ) {
  19. return x * Y;
  20. }
  21. };
  22.  
  23. // Piece 2
  24. #define my_auto( name, value ) typeof( value ) name = value
  25. int main(){
  26.  
  27. // Piece 3
  28. thrust::device_ptr<uint8_t> start;
  29. thrust::device_ptr<uint32_t> Keys1, IndirectKeys;
  30. uint32_t jump, rowsCount;
  31.  
  32. // adds
  33. thrust::device_vector<uint8_t> my_data(DSIZE,1);
  34. thrust::device_vector<uint32_t> my_keys(DSIZE, 1);
  35. thrust::device_vector<uint32_t> my_ikeys(DSIZE, 1);
  36. jump = 1;
  37. rowsCount = 1;
  38. start = my_data.data();
  39. Keys1 = my_keys.data();
  40. IndirectKeys = my_ikeys.data();
  41.  
  42. // Piece 4
  43. my_auto( begin, thrust::make_permutation_iterator(
  44. start,
  45. thrust::make_transform_iterator(
  46. thrust::make_permutation_iterator(
  47. Keys1,
  48. IndirectKeys
  49. ),
  50. MultiplyFunction( jump )
  51. )
  52. ) );
  53.  
  54. my_auto( end, begin + rowsCount );
  55. my_auto( tuple, thrust::minmax_element( begin, end ) ); // Invalid access on the CPU.
  56.  
  57. }
  58. $ nvcc -o t735 t735.cu
  59. $ cuda-memcheck ./t735
  60. ========= CUDA-MEMCHECK
  61. ========= ERROR SUMMARY: 0 errors
  62. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement