comaniac commented on a change in pull request #6348:
URL: https://github.com/apache/incubator-tvm/pull/6348#discussion_r478604334
##########
File path: src/auto_scheduler/search_policy/sketch_policy.cc
##########
@@ -322,32 +323,40 @@ Array<State> SketchPolicyNode::GenerateSketches() {
}
Array<State> SketchPolicyNode::SampleInitPopulation(const Array<State>&
sketches, int out_size) {
- int fail_ct = 0;
+ std::atomic<int> fail_ct(0);
+ std::mutex m;
Array<State> out_states;
auto tic_begin = std::chrono::high_resolution_clock::now();
- // TODO(jcf94, merrymercy): Use parallel_for to run this loop in parallel
- while (static_cast<int>(out_states.size()) < out_size && fail_ct <
static_cast<int>(out_size)) {
- // Random choose a starting sketch
- // TODO(jcf94, merrymercy): Maybe choose sketches in different possibility
for they may have
- // different potential on generating state with better performance
- State tmp_s = sketches[(rand_gen)() % sketches.size()];
-
- // Derivation rule based enumeration
- bool valid = true;
- for (const auto& rule : init_rules) {
- if (rule->Apply(this, &tmp_s) ==
InitPopulationRule::ResultKind::kInvalid) {
- valid = false;
- break;
- }
- }
+ support::parallel_for(
+ 0, out_size, [this, &out_size, &sketches, &out_states, &fail_ct, &m](int
i) {
+ if (fail_ct >= out_size) {
+ return;
+ }
- if (valid) {
- out_states.push_back(std::move(tmp_s));
- } else {
- fail_ct++;
- }
- }
+ // Random choose a starting sketch
+ // TODO(jcf94, merrymercy): Maybe choose sketches in different
possibility for they may have
+ // different potential on generating state with better performance
+ State tmp_s = sketches[(rand_gen)() % sketches.size()];
+ // Derivation rule based enumeration
+ bool valid = true;
+ for (const auto& rule : init_rules) {
+ // Some rules use the random generator of SketchPolicyNode, so this
part has to be
+ // protected
Review comment:
With this limitation, how beneficial is the `parallel_for` for this
operation?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]