Advertisement
Guest User

OpenCL/Sorting/Boost.Compute

a guest
Aug 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #define BOOST_COMPUTE_CL_VERSION_1_2
  2. #include <boost/compute.hpp>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7. namespace compute = boost::compute;
  8.  
  9. int main() {
  10.         // for
  11.         auto gpus = compute::system::devices();
  12.         const size_t size=33;
  13.         for(auto &gpu: gpus) {
  14.                 srand(1);
  15.                 // if( gpu.name() == "Intel(R) HD Graphics 4000" ) continue;
  16.                 cout << size << ":" << gpu.name() << ":" << gpu.version() << endl;
  17.                 auto ctx = compute::context(gpu);
  18.                 auto queue = compute::command_queue(ctx, gpu);
  19.  
  20.                 vector<int> host(size);
  21.                 generate(host.begin(), host.end(), []() {
  22.                         return rand()%100-50;
  23.                 });
  24.  
  25.                 cout << "\nBefore:\n ";
  26.                 for(auto &i: host) { cout << i << " "; } cout << endl;
  27.  
  28.                 compute::vector<int> data(size, ctx);
  29.                 compute::copy( host.begin(), host.end(), data.begin(), queue);
  30.                 compute::sort(data.begin(), data.end(), queue);
  31.                 compute::copy(data.begin(), data.end(), host.begin(), queue);
  32.  
  33.                 cout << "\nAfter :\n ";
  34.                 for(auto &i: host) { cout << i << " "; } cout << endl;
  35.         }
  36.         return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement