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

Function test_copy_if_in_sphere

compute/perf/perf_copy_if.cpp:58–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58void test_copy_if_in_sphere(compute::command_queue &queue)
59{
60 using boost::compute::float4_;
61
62 // create input and output vectors on the device
63 const compute::context &context = queue.get_context();
64 compute::vector<float4_> input_points(PERF_N, context);
65 compute::vector<float4_> output_points(PERF_N, context);
66
67 // generate random numbers in a cube
68 float radius = 5.0f;
69 compute::default_random_engine rng(queue);
70 compute::uniform_real_distribution<float> d(-radius, +radius);
71 d.generate(
72 compute::make_buffer_iterator<float>(input_points.get_buffer(), 0),
73 compute::make_buffer_iterator<float>(input_points.get_buffer(), PERF_N * 4),
74 rng,
75 queue
76 );
77
78 // predicate which returns true if the point lies within the sphere
79 BOOST_COMPUTE_CLOSURE(bool, is_in_sphere, (float4_ point), (radius),
80 {
81 // ignore fourth component
82 point.w = 0;
83
84 return length(point) < radius;
85 });
86
87 perf_timer t;
88 for(size_t trial = 0; trial < PERF_TRIALS; trial++){
89 t.start();
90 compute::vector<float4_>::iterator i = compute::copy_if(
91 input_points.begin(),
92 input_points.end(),
93 output_points.begin(),
94 is_in_sphere,
95 queue
96 );
97 queue.finish();
98 t.stop();
99
100 float ratio = float(std::distance(output_points.begin(), i)) / PERF_N;
101 if(PERF_N > 1000 && (ratio < 0.5f || ratio > 0.6f)){
102 std::cerr << "error: ratio is " << ratio << std::endl;
103 std::cerr << "error: ratio should be around 50-60%" << std::endl;
104 }
105 }
106 std::cout << "time: " << t.min_time() / 1e6 << " ms" << std::endl;
107}
108
109int main(int argc, char *argv[])
110{

Callers

nothing calls this directly

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