| 106 | } |
| 107 | |
| 108 | int main(int argc, char *argv[]) |
| 109 | { |
| 110 | // setup command line arguments |
| 111 | po::options_description options("options"); |
| 112 | options.add_options() |
| 113 | ("help", "show usage instructions") |
| 114 | ("size", po::value<size_t>()->default_value(8192), "input size") |
| 115 | ("trials", po::value<size_t>()->default_value(3), "number of trials to run") |
| 116 | ("tune", "run tuning procedure") |
| 117 | ("alpha", po::value<double>()->default_value(2.5), "saxpy alpha value") |
| 118 | ; |
| 119 | po::positional_options_description positional_options; |
| 120 | positional_options.add("size", 1); |
| 121 | |
| 122 | // parse command line |
| 123 | po::variables_map vm; |
| 124 | po::store( |
| 125 | po::command_line_parser(argc, argv) |
| 126 | .options(options).positional(positional_options).run(), |
| 127 | vm |
| 128 | ); |
| 129 | po::notify(vm); |
| 130 | |
| 131 | const size_t size = vm["size"].as<size_t>(); |
| 132 | const size_t trials = vm["trials"].as<size_t>(); |
| 133 | const float alpha = vm["alpha"].as<double>(); |
| 134 | std::cout << "size: " << size << std::endl; |
| 135 | |
| 136 | // setup context and queue for the default device |
| 137 | compute::device device = boost::compute::system::default_device(); |
| 138 | compute::context context(device); |
| 139 | compute::command_queue queue(context, device); |
| 140 | std::cout << "device: " << device.name() << std::endl; |
| 141 | |
| 142 | // create vector of random numbers on the host |
| 143 | std::vector<float> host_x(size); |
| 144 | std::vector<float> host_y(size); |
| 145 | std::generate(host_x.begin(), host_x.end(), rand_float); |
| 146 | std::generate(host_y.begin(), host_y.end(), rand_float); |
| 147 | |
| 148 | // create vector on the device and copy the data |
| 149 | compute::vector<float> x(host_x.begin(), host_x.end(), queue); |
| 150 | compute::vector<float> y(host_y.begin(), host_y.end(), queue); |
| 151 | |
| 152 | // run tuning proceure (if requested) |
| 153 | if(vm.count("tune")){ |
| 154 | tune_saxpy(x, y, alpha, trials, queue); |
| 155 | } |
| 156 | |
| 157 | // run benchmark |
| 158 | double t = perf_saxpy(x, y, alpha, trials, queue); |
| 159 | std::cout << "time: " << t / 1e6 << " ms" << std::endl; |
| 160 | |
| 161 | return 0; |
| 162 | } |
nothing calls this directly
no test coverage detected