Skip to content

[Runtime] Change ResultCode to an enum class #2278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/glow/Runtime/RuntimeTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using RunIdentifierTy = size_t;

/// Enum to communicate results when communicating with device at initialization
/// and runtime.
enum ResultCode { Ready, Executed, Failed, Cancelled };
enum class ResultCode { Ready, Executed, Failed, Cancelled };

/// Data structure that contains device constraint information for each device.
/// Used to communicate memory constraints and later costs to the Partitioner.
Expand Down
10 changes: 5 additions & 5 deletions lib/Backends/CPU/CPUDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void CPUDeviceManager::addNetworkImpl(const Module *module,
if (modIt != modules_.end()) {
// Already have a module with this ID.
// TODO: should we replace it?
readyCB(module, Failed);
readyCB(module, ResultCode::Failed);
return;
}

Expand All @@ -46,7 +46,7 @@ void CPUDeviceManager::addNetworkImpl(const Module *module,
size_t moduleSize = 200 * 1024 * 1024;

if (usedMemoryBytes + moduleSize > maxMemoryBytes) {
readyCB(module, Failed);
readyCB(module, ResultCode::Failed);
return;
}

Expand All @@ -60,7 +60,7 @@ void CPUDeviceManager::addNetworkImpl(const Module *module,
usedMemoryBytes += moduleSize;

// Fire the ready CB.
readyCB(module, Ready);
readyCB(module, ResultCode::Ready);
}

void CPUDeviceManager::evictNetworkImpl(const Module *module) {
Expand All @@ -85,7 +85,7 @@ void CPUDeviceManager::runFunctionImpl(RunIdentifierTy id, std::string function,
ResultCBTy resultCB) {
auto funcIt = functions_.find(function);
if (funcIt == functions_.end()) {
resultCB(id, Failed, std::move(ctx));
resultCB(id, ResultCode::Failed, std::move(ctx));
return;
}

Expand All @@ -99,5 +99,5 @@ void CPUDeviceManager::runFunctionImpl(RunIdentifierTy id, std::string function,
func->tearDownRuns();

// Fire the resultCB.
resultCB(id, Executed, std::move(ctx));
resultCB(id, ResultCode::Executed, std::move(ctx));
}
59 changes: 32 additions & 27 deletions tests/unittests/CPUDeviceManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ TEST(CPUDeviceManagerTest, Basic) {

cpuCoreDevice.addNetwork(module.get(), std::move(functions),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
callbackHelper(promise, module, result,
ResultCode::Ready);
});

future.wait_for(2s);
Expand All @@ -134,7 +135,7 @@ TEST(CPUDeviceManagerTest, Basic) {
[&runPromise](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runPromise, std::move(ctx_),
result, Executed);
result, ResultCode::Executed);
});

runFuture.wait_for(2s);
Expand All @@ -155,7 +156,8 @@ TEST(CPUDeviceManagerTest, MultiRun) {
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module.get(), std::move(functions),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
callbackHelper(promise, module, result,
ResultCode::Ready);
});
future.wait_for(2s);
EXPECT_EQ(future.get(), module.get());
Expand Down Expand Up @@ -185,14 +187,14 @@ TEST(CPUDeviceManagerTest, MultiRun) {
[&runP1](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP1, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

cpuCoreDevice.runFunction("main", std::move(ctx2),
[&runP2](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP2, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

ctx1 = runF1.get();
Expand Down Expand Up @@ -225,7 +227,8 @@ TEST(CPUDeviceManagerTest, MultiFunction) {
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module.get(), std::move(functions),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
callbackHelper(promise, module, result,
ResultCode::Ready);
});
future.wait_for(2s);
EXPECT_EQ(future.get(), module.get());
Expand All @@ -245,14 +248,14 @@ TEST(CPUDeviceManagerTest, MultiFunction) {
[&runP1](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP1, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

cpuCoreDevice.runFunction("func2", std::move(ctx2),
[&runP2](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP2, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

ctx1 = runF1.get();
Expand All @@ -276,15 +279,17 @@ TEST(CPUDeviceManagerTest, MultiModule) {
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module1.get(), std::move(functions1),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
callbackHelper(promise, module, result,
ResultCode::Ready);
});
future.wait_for(2s);
EXPECT_EQ(future.get(), module1.get());

std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module2.get(), std::move(functions2),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
callbackHelper(promise, module, result,
ResultCode::Ready);
});
future.wait_for(2s);
EXPECT_EQ(future.get(), module2.get());
Expand All @@ -309,14 +314,14 @@ TEST(CPUDeviceManagerTest, MultiModule) {
[&runP1](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP1, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

cpuCoreDevice.runFunction("func2", std::move(ctx2),
[&runP2](RunIdentifierTy, ResultCode result,
std::unique_ptr<Context> ctx_) {
callbackHelper(runP2, std::move(ctx_), result,
Executed);
ResultCode::Executed);
});

ctx1 = runF1.get();
Expand All @@ -340,11 +345,11 @@ TEST(CPUDeviceManagerTest, AvailableMemory) {

auto module = makeBasicModule();
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module.get(),
compileFunctions(module.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
});
cpuCoreDevice.addNetwork(
module.get(), compileFunctions(module.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, ResultCode::Ready);
});

future.wait_for(2s);
EXPECT_EQ(future.get(), module.get());
Expand All @@ -357,11 +362,11 @@ TEST(CPUDeviceManagerTest, AvailableMemory) {
// Let's try again.
auto module2 = makeBasicModule();
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module2.get(),
compileFunctions(module2.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
});
cpuCoreDevice.addNetwork(
module2.get(), compileFunctions(module2.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, ResultCode::Ready);
});

future.wait_for(2s);
auto *resultModule = future.get();
Expand All @@ -377,11 +382,11 @@ TEST(CPUDeviceManagerTest, AvailableMemory) {

// And try again, this time with available space.
std::tie(promise, future) = getFutureHelper<const Module *>();
cpuCoreDevice.addNetwork(module2.get(),
compileFunctions(module2.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, Ready);
});
cpuCoreDevice.addNetwork(
module2.get(), compileFunctions(module2.get(), backing),
[&promise](const Module *module, ResultCode result) {
callbackHelper(promise, module, result, ResultCode::Ready);
});

future.wait_for(2s);
EXPECT_EQ(future.get(), module2.get());
Expand Down