| 1569 | namespace { |
| 1570 | template <typename F> |
| 1571 | void each_card(std::vector<CardW>& cards, F f) { |
| 1572 | std::vector<std::thread> th; |
| 1573 | std::vector<std::string> errs(NCARD); |
| 1574 | for (int c = 0; c < NCARD; ++c) |
| 1575 | th.emplace_back([&, c] { |
| 1576 | try { |
| 1577 | ck(cudaSetDevice(cards[c].dev), "cudaSetDevice"); |
| 1578 | f(cards[c]); |
| 1579 | } catch (const std::exception& e) { errs[c] = e.what(); } |
| 1580 | }); |
| 1581 | for (auto& t : th) t.join(); |
| 1582 | for (int c = 0; c < NCARD; ++c) |
| 1583 | if (!errs[c].empty()) throw std::runtime_error("card " + std::to_string(c) + ": " + errs[c]); |
| 1584 | } |
| 1585 | } // namespace |
| 1586 | |
| 1587 | void Model::place_experts() { |