MCPcopy Create free account
hub / github.com/boostorg/compute / main

Function main

example/matrix_transpose.cpp:219–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217#endif
218
219int main(int argc, char *argv[])
220{
221 // setup command line arguments
222 po::options_description options("options");
223 options.add_options()
224 ("help", "show usage instructions")
225 ("rows", po::value<uint_>()->default_value(4096), "number of matrix rows")
226 ("cols", po::value<uint_>()->default_value(4096), "number of matrix columns")
227 ;
228
229 // parse command line
230 po::variables_map vm;
231 po::store(po::parse_command_line(argc, argv, options), vm);
232 po::notify(vm);
233
234 // check command line arguments
235 if(vm.count("help")){
236 std::cout << options << std::endl;
237 return 0;
238 }
239
240 // get number rows and columns for the matrix
241 const uint_ rows = vm["rows"].as<uint_>();
242 const uint_ cols = vm["cols"].as<uint_>();
243
244 // get the default device
245 compute::device device = compute::system::default_device();
246
247 // print out device name and matrix information
248 std::cout << "Device: " << device.name() << std::endl;
249 std::cout << "Matrix Size: " << rows << "x" << cols << std::endl;
250 std::cout << "Grid Size: " << rows/TILE_DIM << "x" << cols/TILE_DIM << " blocks" << std::endl;
251 std::cout << "Local Size: " << TILE_DIM << "x" << BLOCK_ROWS << " threads" << std::endl;
252 std::cout << std::endl;
253
254 // On OSX this example does not work on CPU devices
255 #if defined(__APPLE__)
256 if(device.type() & compute::device::cpu) {
257 std::cout << "On OSX this example does not work on CPU devices" << std::endl;
258 return 0;
259 }
260 #endif
261
262 const size_t global_work_size[2] = {rows, cols*BLOCK_ROWS/TILE_DIM};
263 const size_t local_work_size[2] = {TILE_DIM, BLOCK_ROWS};
264
265 // setup input data on the host
266 const uint_ size = rows * cols;
267 std::vector<float> h_input(size);
268 std::vector<float> h_output(size);
269 std::vector<float> expectedResult(size);
270 generate_matrix(h_input, expectedResult, rows, cols);
271
272 // create a context for the device
273 compute::context context(device);
274
275 // device vectors
276 compute::vector<float> d_input(size, context);

Callers

nothing calls this directly

Calls 15

generate_matrixFunction · 0.85
copyFunction · 0.85
make_copy_kernelFunction · 0.85
check_transpositionFunction · 0.85
countMethod · 0.45
nameMethod · 0.45
typeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected