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

Function test_copy_if_odd

compute/perf/perf_copy_if.cpp:23–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace compute = boost::compute;
22
23void test_copy_if_odd(compute::command_queue &queue)
24{
25 // create input and output vectors on the device
26 const compute::context &context = queue.get_context();
27 compute::vector<int> input(PERF_N, context);
28 compute::vector<int> output(PERF_N, context);
29
30 // generate random numbers between 1 and 10
31 compute::default_random_engine rng(queue);
32 compute::uniform_int_distribution<int> d(1, 10);
33 d.generate(input.begin(), input.end(), rng, queue);
34
35 BOOST_COMPUTE_FUNCTION(bool, is_odd, (int x),
36 {
37 return x & 1;
38 });
39
40 perf_timer t;
41 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
42 t.start();
43 compute::vector<int>::iterator i = compute::copy_if(
44 input.begin(), input.end(), output.begin(), is_odd, queue
45 );
46 queue.finish();
47 t.stop();
48
49 float ratio = float(std::distance(output.begin(), i)) / PERF_N;
50 if(PERF_N > 1000 && (ratio < 0.45f || ratio > 0.55f)){
51 std::cerr << "error: ratio is " << ratio << std::endl;
52 std::cerr << "error: ratio should be around 45-55%" << std::endl;
53 }
54 }
55 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
56}
57
58void test_copy_if_in_sphere(compute::command_queue &queue)
59{

Callers 1

mainFunction · 0.85

Calls 9

copy_ifFunction · 0.85
startMethod · 0.80
stopMethod · 0.80
min_timeMethod · 0.80
get_contextMethod · 0.45
generateMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected