MCPcopy Create free account
hub / github.com/Samsung/ONE / profileDataInParallel

Method profileDataInParallel

compiler/record-minmax/src/RecordMinMax.cpp:495–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495void RecordMinMax::profileDataInParallel(const std::string &input_data_path)
496{
497 LOGGER(l);
498
499 assert(_interpreters.size() == _threads_size);
500 assert(_observers.size() == _threads_size);
501
502 const long h5_file_size = getH5FileSize(input_data_path);
503
504 if (h5_file_size > h5_max_size_bytes)
505 throw std::runtime_error("H5 file size is too large for parallel recording");
506
507 WholeOutput whole_output;
508 try
509 {
510 whole_output = importH5Data(input_data_path);
511 }
512 catch (const std::bad_alloc &e)
513 {
514 throw std::runtime_error("Out of memory during h5 data load.");
515 }
516
517 const auto num_records = whole_output.size();
518 const auto input_nodes = loco::input_nodes(_module->graph());
519
520 // Start parallel part
521 INFO(l) << _threads_size << " concurrent threads are supported." << std::endl;
522
523 const auto run_threads = num_records < _threads_size ? num_records : _threads_size;
524
525 const auto records_batch = static_cast<uint32_t>(num_records / run_threads);
526
527 auto interpret_batch = [&whole_output, &input_nodes](int first_record, int last_record,
528 luci_interpreter::Interpreter *interpreter) {
529 for (int record_index = first_record; record_index < last_record; ++record_index)
530 {
531 for (uint32_t input_idx = 0; input_idx < input_nodes.size(); input_idx++)
532 {
533 const auto *input_node = loco::must_cast<const luci::CircleInput *>(input_nodes[input_idx]);
534
535 const auto &cur_input_data = whole_output[record_index][input_idx];
536 interpreter->writeInputTensor(input_node, cur_input_data.data(), cur_input_data.size());
537 }
538 interpreter->interpret();
539 }
540 };
541
542 std::vector<std::thread> threads;
543 for (uint32_t t = 0; t < run_threads; ++t)
544 {
545 if (t < run_threads - 1)
546 {
547 threads.emplace_back(interpret_batch, records_batch * t, records_batch * (t + 1),
548 _interpreters[t].get());
549 }
550 else
551 {
552 threads.emplace_back(interpret_batch, records_batch * t, num_records, _interpreters[t].get());

Callers 1

entryFunction · 0.80

Calls 15

getH5FileSizeFunction · 0.85
input_nodesFunction · 0.85
writeInputTensorMethod · 0.80
joinMethod · 0.80
getMapMethod · 0.80
minMaxDataMethod · 0.80
appendMinMaxVectorMethod · 0.80
update_qparamMethod · 0.80
sizeMethod · 0.45
graphMethod · 0.45
dataMethod · 0.45
interpretMethod · 0.45

Tested by

no test coverage detected