diff --git a/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/hpvm-rt-controller.cpp b/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/hpvm-rt-controller.cpp index a754138a847cd2a696f6d717949b26c50bfd238f..f716aaf783c7d3fb9ae9885c0ee561cb679031f4 100644 --- a/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/hpvm-rt-controller.cpp +++ b/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/hpvm-rt-controller.cpp @@ -1021,18 +1021,28 @@ void RuntimeController::adjustTargetConfiguration(float goal) { DEBUG("adjustTargetConfiguration: goalVal: %f.\n\n", goal); - // Find configuration before the selected one. There is always one. + pseudo_rd += 0.1f; + // Find configuration before the selected one. + // There is always one, unless goal is 1. Then, we would pick baseline, and + // both upper and lower should be the same configuration, at index 0. + unsigned prev_conf_idx = configurationIdx > 0 ? configurationIdx - 1 + : configurationIdx; // Get the two configurations' speedup, and compute the appropriate ranges float curr_conf_speedup = (*Configurations)[configurationIdx]->speedup; - float prev_conf_speedup = (*Configurations)[configurationIdx - 1]->speedup; + float prev_conf_speedup = (*Configurations)[prev_conf_idx]->speedup; float sp_diff = curr_conf_speedup - prev_conf_speedup; float high_range = curr_conf_speedup - goal; float low_range = goal - prev_conf_speedup; // These represent how likely we are to pick the upper or lower configuration - float high_pb = low_range / sp_diff; - float low_pb = high_range / sp_diff; + float high_pb = 0.0, low_pb = 0.0; + if (configurationIdx == prev_conf_idx) { + high_pb = low_pb = 1.0; + } else { + high_pb = low_range / sp_diff; + low_pb = high_range / sp_diff; + } DEBUG( "**---- adjustTargetConfiguration: upper conf = %s with probability: " @@ -1041,17 +1051,16 @@ void RuntimeController::adjustTargetConfiguration(float goal) { DEBUG( "**---- adjustTargetConfiguration: lower conf = %s with probability: " "%f.\n\n", - ((*Configurations)[configurationIdx - 1]->name).c_str(), low_pb); + ((*Configurations)[prev_conf_idx]->name).c_str(), low_pb); // Select a random number from 0 to 1 // We assign the (0..low_pb) to the lower configuration, and the (low_pb..1) // to the upper // float rd = static_cast <float> (rand()) / static_cast <float> (RAND_MAX) ; - pseudo_rd += 0.1f; float rd = pseudo_rd; if (rd < low_pb) { // If the probability is in the low range - configurationIdx--; + configurationIdx = prev_conf_idx; } DEBUG( @@ -1260,6 +1269,37 @@ extern "C" void llvm_hpvm_invokeRtControl_ADJUST( RC->end_iteration(); } +extern "C" void llvm_hpvm_invokeRtControl_ADJUST_PR( + void *result, const char *str, int start, int end) { + + uint32_t *labels_cached = hpvm_rt_readLabelsBatch_cached(str, start, end); + hpvm_rt_computeAccuracy3(labels_cached, result); + + // Read stats for iteration that was just completed + double current_iteration_energy = RC->getCurrentIterationComputeEnergy(); + + RC->resume_profiler(); + double current_iteration_time = RC->getCurrentIterationComputeTime(); + double baseline_time = RC->getBaselineTime(); + double target_speedup = current_iteration_time / baseline_time; + RC->findTargetConfiguration(target_speedup, SPEEDUP); + RC->adjustTargetConfiguration(target_speedup); + RC->pause_profiler(); + + std::pair<double, double> pinfo = RC->get_time_energy(); + RC->reset_profiler(); + RC->addToCurrentIterationControlTime(pinfo.first); + RC->addToCurrentIterationControlEnergy(pinfo.second); + + INFO( + "current iteration time = %f, current iteration energy = %f\n", + current_iteration_time, current_iteration_energy); + INFO("target speedup = %lf\n\n", target_speedup); + + // Note the end of iteration + RC->end_iteration(); +} + extern "C" void llvm_hpvm_invokeRtControl_SLOWDOWN( void *result, const char *str, int start, int end) {