[neurun] Fix linear interpolation in ExecTime::getOperationExecTime (#5614)
authorДилшоджон Умронхонович Пошшоев/AI Tools Lab /SRR/Engineer/삼성전자 <d.poshshoev@samsung.com>
Tue, 16 Jul 2019 10:13:44 +0000 (19:13 +0900)
committer이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Tue, 16 Jul 2019 10:13:44 +0000 (19:13 +0900)
In some cases ops with smaller inputs is executed slower than the one
with larger inputs, more likely because of a backend's load difference.
In such cases result of lin-interpolation is negative, which is wrong

Signed-off-by: Dilshodzhon Poshshoev <d.poshshoev@samsung.com>
runtimes/neurun/core/src/backend/ExecTime.cc

index b58885c..9cb1ff1 100644 (file)
@@ -80,6 +80,15 @@ int64_t ExecTime::getOperationExecTime(const Backend *backend, const std::string
 
   int64_t interpolated_value = y0 + (x - x0) * (y1 - y0) / (x1 - x0);
 
+  // In some cases ops with smaller inputs is executed slower than the one
+  // with larger inputs, more likely because of a backend's load difference
+  if (interpolated_value < 0 && x > x1)
+  {
+    return y0;
+  }
+  // It must be non-positive ONLY if it's lesser than both of them
+  assert(interpolated_value > 0 || x < x0);
+
   // execution time must be non-negative
   return std::max<int64_t>(interpolated_value, 1);
 }