Skip to content

Commit

Permalink
Limit parallelism for constant propagation when parallel STL is not e…
Browse files Browse the repository at this point in the history
…nabled (#2987)
  • Loading branch information
ahsan-ca authored and Chris Austen committed Apr 23, 2024
1 parent 11d19e3 commit fad9b78
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/propagate_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <migraphx/functional.hpp>
#include <migraphx/simple_par_for.hpp>
#include <migraphx/env.hpp>
#include <thread>
#include <unordered_set>

namespace migraphx {
Expand Down Expand Up @@ -83,7 +84,12 @@ void propagate_constant::apply(module& m) const
// Compute literals in parallel
std::vector<instruction_ref> const_instrs_vec{const_instrs.begin(), const_instrs.end()};
std::vector<argument> literals(const_instrs_vec.size());
simple_par_for(const_instrs_vec.size(), 1, [&](const auto i) {
std::size_t n = 1;
#if !MIGRAPHX_HAS_EXECUTORS
n = std::max<std::size_t>(
std::ceil(static_cast<double>(1024) / std::thread::hardware_concurrency()), 1);
#endif
simple_par_for(const_instrs_vec.size(), n, [&](const auto i) {
literals[i] = const_instrs_vec[i]->eval();
});

Expand Down

0 comments on commit fad9b78

Please sign in to comment.