Skip to content

Commit d942a98

Browse files
tkonoligetrevor-m
authored andcommitted
[RUNTIME] Switch time evaluator to use device specific timing. (apache#7631)
1 parent 9ef7fc8 commit d942a98

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/runtime/rpc/rpc_module.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
#include <tvm/runtime/container.h>
2525
#include <tvm/runtime/device_api.h>
26+
#include <tvm/runtime/profiling.h>
2627
#include <tvm/runtime/registry.h>
2728

2829
#include <cstring>
@@ -364,8 +365,6 @@ PackedFunc WrapTimeEvaluator(PackedFunc pf, TVMContext ctx, int number, int repe
364365
if (f_preproc != nullptr) {
365366
f_preproc.CallPacked(args, &temp);
366367
}
367-
std::chrono::time_point<std::chrono::high_resolution_clock, std::chrono::nanoseconds> tbegin,
368-
tend;
369368
double duration_ms = 0.0;
370369

371370
do {
@@ -374,20 +373,17 @@ PackedFunc WrapTimeEvaluator(PackedFunc pf, TVMContext ctx, int number, int repe
374373
number * 1.618)); // 1.618 is chosen by random
375374
}
376375

377-
tbegin = std::chrono::high_resolution_clock::now();
376+
Timer t = Timer::Start(ctx);
378377
// start timing
379378
for (int i = 0; i < number; ++i) {
380379
pf.CallPacked(args, &temp);
381380
}
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;
387384
} while (duration_ms < min_repeat_ms);
388385

389-
double speed =
390-
std::chrono::duration_cast<std::chrono::duration<double>>(tend - tbegin).count() / number;
386+
double speed = duration_ms / 1e3 / number;
391387
os.write(reinterpret_cast<char*>(&speed), sizeof(speed));
392388
}
393389

0 commit comments

Comments
 (0)