23
23
*/
24
24
#include < tvm/runtime/container.h>
25
25
#include < tvm/runtime/device_api.h>
26
+ #include < tvm/runtime/profiling.h>
26
27
#include < tvm/runtime/registry.h>
27
28
28
29
#include < cstring>
@@ -364,8 +365,6 @@ PackedFunc WrapTimeEvaluator(PackedFunc pf, TVMContext ctx, int number, int repe
364
365
if (f_preproc != nullptr ) {
365
366
f_preproc.CallPacked (args, &temp);
366
367
}
367
- std::chrono::time_point<std::chrono::high_resolution_clock, std::chrono::nanoseconds> tbegin,
368
- tend;
369
368
double duration_ms = 0.0 ;
370
369
371
370
do {
@@ -374,20 +373,17 @@ PackedFunc WrapTimeEvaluator(PackedFunc pf, TVMContext ctx, int number, int repe
374
373
number * 1.618 )); // 1.618 is chosen by random
375
374
}
376
375
377
- tbegin = std::chrono::high_resolution_clock::now ( );
376
+ Timer t = Timer::Start (ctx );
378
377
// start timing
379
378
for (int i = 0 ; i < number; ++i) {
380
379
pf.CallPacked (args, &temp);
381
380
}
382
- DeviceAPI::Get (ctx)->StreamSync (ctx, nullptr );
383
- tend = std::chrono::high_resolution_clock::now ();
384
-
385
- duration_ms =
386
- std::chrono::duration_cast<std::chrono::duration<double >>(tend - tbegin).count () * 1000 ;
381
+ t->Stop ();
382
+ int64_t t_nanos = t->SyncAndGetElapsedNanos ();
383
+ duration_ms = t_nanos / 1e6 ;
387
384
} while (duration_ms < min_repeat_ms);
388
385
389
- double speed =
390
- std::chrono::duration_cast<std::chrono::duration<double >>(tend - tbegin).count () / number;
386
+ double speed = duration_ms / 1e3 / number;
391
387
os.write (reinterpret_cast <char *>(&speed), sizeof (speed));
392
388
}
393
389
0 commit comments