You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by ar...@apache.org on 2022/06/10 00:59:30 UTC
[tvm] branch main updated: [CRT runtime] Added functions TVMPlatformBeforeMeasurement and TVMPlatformAfterMeasurement (#11244)
This is an automated email from the ASF dual-hosted git repository.
areusch pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 832856d109 [CRT runtime] Added functions TVMPlatformBeforeMeasurement and TVMPlatformAfterMeasurement (#11244)
832856d109 is described below
commit 832856d1090de195a5fa7b2962d7cdd4f470d6ff
Author: fPecc <pe...@frba.utn.edu.ar>
AuthorDate: Fri Jun 10 02:59:24 2022 +0200
[CRT runtime] Added functions TVMPlatformBeforeMeasurement and TVMPlatformAfterMeasurement (#11244)
* Added functions with weak links before and after TVMFuncCall in the TimeEvaluator
* Fixed lint
* Clang changes
* Added clang proposal
* clang-format proposed changes
Co-authored-by: Federico Peccia <pe...@fzi.de>
---
include/tvm/runtime/crt/platform.h | 19 +++++++++++++++++++
src/runtime/crt/common/crt_runtime_api.c | 16 ++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/include/tvm/runtime/crt/platform.h b/include/tvm/runtime/crt/platform.h
index c774aaeaa0..bb916afacd 100644
--- a/include/tvm/runtime/crt/platform.h
+++ b/include/tvm/runtime/crt/platform.h
@@ -97,6 +97,25 @@ tvm_crt_error_t TVMPlatformTimerStart();
*/
tvm_crt_error_t TVMPlatformTimerStop(double* elapsed_time_seconds);
+/*! \brief Platform-specific before measurement call.
+ *
+ * A function which is called before calling TVMFuncCall in the TimeEvaluator.
+ * Can be used, for example, to initialize reset global state which may affect the results of
+ * measurement.
+ *
+ * \return kTvmErrorNoError if successful; a descriptive error code otherwise.
+ */
+tvm_crt_error_t TVMPlatformBeforeMeasurement();
+
+/*! \brief Platform-specific after measurement call.
+ *
+ * A function which is called after calling TVMFuncCall in the TimeEvaluator.
+ * It is the counterpart of the TVMPlatformBeforeMeasurement function.
+ *
+ * \return kTvmErrorNoError if successful; a descriptive error code otherwise.
+ */
+tvm_crt_error_t TVMPlatformAfterMeasurement();
+
/*! \brief Fill a buffer with random data.
*
* Cryptographically-secure random data is NOT required. This function is intended for use
diff --git a/src/runtime/crt/common/crt_runtime_api.c b/src/runtime/crt/common/crt_runtime_api.c
index 49a699c3ce..31ab3e9a69 100644
--- a/src/runtime/crt/common/crt_runtime_api.c
+++ b/src/runtime/crt/common/crt_runtime_api.c
@@ -526,6 +526,11 @@ tvm_crt_error_t RunTimeEvaluator(tvm_function_index_t function_index, TVMValue*
int exec_count = 0;
// do-while structure ensures we run even when `min_repeat_ms` isn't set (i.e., is 0).
do {
+ err = TVMPlatformBeforeMeasurement();
+ if (err != kTvmErrorNoError) {
+ goto release_and_return;
+ }
+
err = TVMPlatformTimerStart();
if (err != kTvmErrorNoError) {
goto release_and_return;
@@ -546,6 +551,11 @@ tvm_crt_error_t RunTimeEvaluator(tvm_function_index_t function_index, TVMValue*
goto release_and_return;
}
repeat_res_seconds += curr_res_seconds;
+
+ err = TVMPlatformAfterMeasurement();
+ if (err != kTvmErrorNoError) {
+ goto release_and_return;
+ }
} while (repeat_res_seconds < min_repeat_seconds);
double mean_exec_seconds = repeat_res_seconds / exec_count;
*iter = mean_exec_seconds;
@@ -575,6 +585,12 @@ __attribute__((weak)) tvm_crt_error_t TVMPlatformGenerateRandom(uint8_t* buffer,
return kTvmErrorFunctionCallNotImplemented;
}
+// Default implementation, overridden by the platform runtime.
+__attribute__((weak)) tvm_crt_error_t TVMPlatformBeforeMeasurement() { return kTvmErrorNoError; }
+
+// Default implementation, overridden by the platform runtime.
+__attribute__((weak)) tvm_crt_error_t TVMPlatformAfterMeasurement() { return kTvmErrorNoError; }
+
// Fill the tensor in args[0] with random data using TVMPlatformGenerateRandom.
// Named to correspond with the analogous function in the C++ runtime.
int TVMContribRandomFill(TVMValue* args, int* type_codes, int num_args, TVMValue* ret_val,