MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / main

Function main

compute/example/host_sort.cpp:28–56  ·  view source on GitHub ↗

this example demonstrates how to sort a std::vector of ints on the GPU

Source from the content-addressed store, hash-verified

26
27// this example demonstrates how to sort a std::vector of ints on the GPU
28int main()
29{
30 // get default device and setup context
31 compute::device gpu = compute::system::default_device();
32 compute::context context(gpu);
33 compute::command_queue queue(context, gpu);
34 std::cout << "device: " << gpu.name() << std::endl;
35
36 // create vector of random values on the host
37 std::vector<int> vector(8);
38 std::generate(vector.begin(), vector.end(), rand_int);
39
40 // print input vector
41 std::cout << "input: [ "
42 << karma::format(karma::int_ % ", ", vector)
43 << " ]"
44 << std::endl;
45
46 // sort vector
47 compute::sort(vector.begin(), vector.end(), queue);
48
49 // print sorted vector
50 std::cout << "output: [ "
51 << karma::format(karma::int_ % ", ", vector)
52 << " ]"
53 << std::endl;
54
55 return 0;
56}

Callers

nothing calls this directly

Calls 5

sortFunction · 0.85
generateFunction · 0.50
nameMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected