Skip to content

Commit b622eef

Browse files
author
Andrew Reusch
committed
try many different things to please the gods
1 parent d922b8c commit b622eef

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/runtime/micro/micro_session.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct TVMMicroSessionThreadLocalEntry {
4242

4343
typedef dmlc::ThreadLocalStore<TVMMicroSessionThreadLocalEntry> TVMMicroSessionThreadLocalStore;
4444

45-
ObjectPtr<MicroSession>& MicroSession::Current() {
45+
ObjectPtr<MicroSession>& MicroSession::Current(void) {
4646
TVMMicroSessionThreadLocalEntry *entry = TVMMicroSessionThreadLocalStore::Get();
4747
CHECK_GT(entry->session_stack.size(), 0) << "No current session";
4848
return entry->session_stack.top();

src/runtime/rpc/rpc_session.cc

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,26 +1247,28 @@ void RPCSession::EventHandler::HandlePackedCall() {
12471247
CHECK_EQ(state_, kRecvCode);
12481248
}
12491249

1250-
PackedFunc MicroTimeEvaluator(
1251-
PackedFunc pf,
1252-
TVMContext ctx,
1253-
size_t number,
1254-
int repeat,
1255-
int min_repeat_ms) {
1256-
auto ftimer = [pf, ctx, number, repeat](TVMArgs args, TVMRetValue *rv) mutable {
1250+
1251+
class MicroTimeEvaluatorFunctor {
1252+
public:
1253+
PackedFunc pf_;
1254+
TVMContext ctx_;
1255+
size_t number_;
1256+
int repeat_;
1257+
1258+
void operator()(TVMArgs args, TVMRetValue* rv) {
12571259
TVMRetValue temp;
12581260
std::ostringstream os;
12591261

1260-
for (int i = 0; i < repeat; ++i) {
1262+
for (int i = 0; i < repeat_; ++i) {
12611263
// start timing
1262-
CHECK(number < MicroSession::kTaskQueueCapacity)
1263-
<< "`number` must be less than uTVM task queue capacity";
1264-
for (unsigned int j = 0; j < number; ++j) {
1265-
pf.CallPacked(args, &temp);
1264+
CHECK(number_ < MicroSession::kTaskQueueCapacity)
1265+
<< "`number_` must be less than uTVM task queue capacity";
1266+
for (unsigned int j = 0; j < number_; ++j) {
1267+
pf_.CallPacked(args, &temp);
12661268
}
12671269
ObjectPtr<MicroSession> session = MicroSession::Current();
1268-
DeviceAPI::Get(ctx)->StreamSync(ctx, nullptr);
1269-
double time_per_batch = session->GetLastBatchTime() / number;
1270+
DeviceAPI::Get(ctx_)->StreamSync(ctx_, nullptr);
1271+
double time_per_batch = session->GetLastBatchTime() / number_;
12701272
os.write(reinterpret_cast<char*>(&time_per_batch), sizeof(time_per_batch));
12711273
}
12721274
std::string blob = os.str();
@@ -1275,6 +1277,18 @@ PackedFunc MicroTimeEvaluator(
12751277
arr.data = blob.data();
12761278
// return the time.
12771279
*rv = arr;
1280+
}
1281+
};
1282+
1283+
PackedFunc MicroTimeEvaluator(
1284+
PackedFunc pf,
1285+
TVMContext ctx,
1286+
size_t number,
1287+
int repeat,
1288+
int min_repeat_ms) {
1289+
MicroTimeEvaluatorFunctor func{pf, ctx, number, repeat};
1290+
auto ftimer = [func](TVMArgs args, TVMRetValue *rv) mutable {
1291+
func(args, rv);
12781292
};
12791293
return PackedFunc(ftimer);
12801294
}

0 commit comments

Comments
 (0)