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

Function tune_saxpy

compute/perf/perf_saxpy.cpp:65–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64template<class T>
65void tune_saxpy(const compute::vector<T>& x,
66 const compute::vector<T>& y,
67 const T alpha,
68 const size_t trials,
69 compute::command_queue& queue)
70{
71 boost::shared_ptr<compute::detail::parameter_cache>
72 params = compute::detail::parameter_cache::get_global_cache(queue.get_device());
73
74 const std::string cache_key =
75 std::string("__boost_copy_kernel_") + boost::lexical_cast<std::string>(sizeof(T));
76
77 const compute::uint_ tpbs[] = { 4, 8, 16, 32, 64, 128, 256, 512, 1024 };
78 const compute::uint_ vpts[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
79
80 double min_time = (std::numeric_limits<double>::max)();
81 compute::uint_ best_tpb = 0;
82 compute::uint_ best_vpt = 0;
83
84 for(size_t i = 0; i < sizeof(tpbs) / sizeof(*tpbs); i++){
85 params->set(cache_key, "tpb", tpbs[i]);
86 for(size_t j = 0; j < sizeof(vpts) / sizeof(*vpts); j++){
87 params->set(cache_key, "vpt", vpts[j]);
88
89 try {
90 const double t = perf_saxpy(x, y, alpha, trials, queue);
91 if(t < min_time){
92 best_tpb = tpbs[i];
93 best_vpt = vpts[j];
94 min_time = t;
95 }
96 }
97 catch(compute::opencl_error&){
98 // invalid parameters for this device, skip
99 }
100 }
101 }
102
103 // store optimal parameters
104 params->set(cache_key, "tpb", best_tpb);
105 params->set(cache_key, "vpt", best_vpt);
106}
107
108int main(int argc, char *argv[])
109{

Callers 1

mainFunction · 0.85

Calls 3

perf_saxpyFunction · 0.85
get_deviceMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected