Commit c2d2edae authored by Andrew Moylan's avatar Andrew Moylan Committed by Commit Bot

Update ML Service mojoms to match latest API in Chrome OS

This syncs Chrome's version of the ML Service Mojo interface with
Chrome OS's version in src/platform2/ml/mojom.

The incorporated mojom changes introduce error/status responses from
most of the mojom methods.

No clients depend on this yet so the only required C++ change is an
update to the LoadModel helper in the client library.

Bug: 836095
Change-Id: I15a7ba831792290c7b68db889332efd356163d28
Reviewed-on: https://chromium-review.googlesource.com/1226650
Commit-Queue: Andrew Moylan <amoylan@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarMichael Martis <martis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591274}
parent f05b8f9d
...@@ -21,11 +21,14 @@ ServiceConnection* ServiceConnection::GetInstance() { ...@@ -21,11 +21,14 @@ ServiceConnection* ServiceConnection::GetInstance() {
return service_connection.get(); return service_connection.get();
} }
void ServiceConnection::LoadModel(mojom::ModelSpecPtr spec, void ServiceConnection::LoadModel(
mojom::ModelRequest request) { mojom::ModelSpecPtr spec,
mojom::ModelRequest request,
mojom::MachineLearningService::LoadModelCallback result_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
BindMachineLearningServiceIfNeeded(); BindMachineLearningServiceIfNeeded();
machine_learning_service_->LoadModel(std::move(spec), std::move(request)); machine_learning_service_->LoadModel(std::move(spec), std::move(request),
std::move(result_callback));
} }
void ServiceConnection::BindMachineLearningServiceIfNeeded() { void ServiceConnection::BindMachineLearningServiceIfNeeded() {
......
...@@ -17,10 +17,11 @@ namespace machine_learning { ...@@ -17,10 +17,11 @@ namespace machine_learning {
// interface. // interface.
// Usage: // Usage:
// chromeos::machine_learning::mojom::ModelPtr model; // chromeos::machine_learning::mojom::ModelPtr model;
// chromeos::machine_learning::mojom::ModelSpec spec; // chromeos::machine_learning::mojom::ModelSpec spec = ...;
// chromeos::machine_learning::ServiceConnection::GetInstance() // chromeos::machine_learning::ServiceConnection::GetInstance()
// ->LoadModel(spec, mojom::MakeRequest(&model)); // ->LoadModel(spec, mojom::MakeRequest(&model),
// // Use model ... // base::BindOnce(&MyCallBack));
// // Use |model| or wait for |MyCallBack|.
// Sequencing: Must be used on a single sequence (may be created on another). // Sequencing: Must be used on a single sequence (may be created on another).
class ServiceConnection { class ServiceConnection {
public: public:
...@@ -29,7 +30,10 @@ class ServiceConnection { ...@@ -29,7 +30,10 @@ class ServiceConnection {
// Instruct ML daemon to load the model specified in |spec|, binding a Model // Instruct ML daemon to load the model specified in |spec|, binding a Model
// implementation to |request|. // implementation to |request|.
// Bootstraps the initial Mojo connection to the daemon if necessary. // Bootstraps the initial Mojo connection to the daemon if necessary.
void LoadModel(mojom::ModelSpecPtr spec, mojom::ModelRequest request); void LoadModel(
mojom::ModelSpecPtr spec,
mojom::ModelRequest request,
mojom::MachineLearningService::LoadModelCallback result_callback);
private: private:
friend class base::NoDestructor<ServiceConnection>; friend class base::NoDestructor<ServiceConnection>;
......
...@@ -43,9 +43,10 @@ class ServiceConnectionTest : public testing::Test { ...@@ -43,9 +43,10 @@ class ServiceConnectionTest : public testing::Test {
// Tests that BindModelProvider runs OK (no crash) in a basic Mojo environment. // Tests that BindModelProvider runs OK (no crash) in a basic Mojo environment.
TEST_F(ServiceConnectionTest, BindModelProvider) { TEST_F(ServiceConnectionTest, BindModelProvider) {
mojom::ModelPtr model; mojom::ModelPtr model;
mojom::ModelSpecPtr spec = mojom::ModelSpec::New(mojom::ModelId::UNKNOWN); mojom::ModelSpecPtr spec = mojom::ModelSpec::New(mojom::ModelId::TEST_MODEL);
ServiceConnection::GetInstance()->LoadModel(std::move(spec), ServiceConnection::GetInstance()->LoadModel(
mojo::MakeRequest(&model)); std::move(spec), mojo::MakeRequest(&model),
base::BindOnce([](mojom::LoadModelResult result) {}));
} }
} // namespace } // namespace
......
...@@ -11,6 +11,19 @@ module chromeos.machine_learning.mojom; ...@@ -11,6 +11,19 @@ module chromeos.machine_learning.mojom;
import "chromeos/services/machine_learning/public/mojom/tensor.mojom"; import "chromeos/services/machine_learning/public/mojom/tensor.mojom";
enum ExecuteResult {
OK = 0,
INPUT_MISSING_ERROR,
UNKNOWN_INPUT_ERROR,
INPUT_TYPE_ERROR,
INPUT_SHAPE_ERROR,
INPUT_FORMAT_ERROR,
OUTPUT_MISSING_ERROR,
UNKNOWN_OUTPUT_ERROR,
DUPLICATE_OUTPUT_ERROR,
EXECUTION_ERROR,
};
// API for performing inference on a TensorFlow graph. A given graph can be // API for performing inference on a TensorFlow graph. A given graph can be
// executed multiple times with a single instance of GraphExecutor. // executed multiple times with a single instance of GraphExecutor.
interface GraphExecutor { interface GraphExecutor {
...@@ -18,5 +31,5 @@ interface GraphExecutor { ...@@ -18,5 +31,5 @@ interface GraphExecutor {
// graph. The returned |outputs| are the values for the nodes specified in // graph. The returned |outputs| are the values for the nodes specified in
// |output_names|. // |output_names|.
Execute(map<string, Tensor> inputs, array<string> output_names) Execute(map<string, Tensor> inputs, array<string> output_names)
=> (array<Tensor> outputs); => (ExecuteResult result, array<Tensor>? outputs);
}; };
...@@ -13,8 +13,14 @@ module chromeos.machine_learning.mojom; ...@@ -13,8 +13,14 @@ module chromeos.machine_learning.mojom;
import "chromeos/services/machine_learning/public/mojom/model.mojom"; import "chromeos/services/machine_learning/public/mojom/model.mojom";
enum LoadModelResult {
OK = 0,
MODEL_SPEC_ERROR,
LOAD_MODEL_ERROR,
};
// Top-level interface between Chromium and the ML Service daemon. // Top-level interface between Chromium and the ML Service daemon.
interface MachineLearningService { interface MachineLearningService {
// The ModelId inside ModelSpec is used to specify the model to be loaded. // The ModelId inside ModelSpec is used to specify the model to be loaded.
LoadModel(ModelSpec spec, Model& request); LoadModel(ModelSpec spec, Model& request) => (LoadModelResult result);
}; };
...@@ -15,8 +15,13 @@ import "chromeos/services/machine_learning/public/mojom/graph_executor.mojom"; ...@@ -15,8 +15,13 @@ import "chromeos/services/machine_learning/public/mojom/graph_executor.mojom";
enum ModelId { enum ModelId {
UNKNOWN, UNKNOWN,
TAB_DISCARDER, TEST_MODEL, // Only available in tests.
POWER_MANAGER };
enum CreateGraphExecutorResult {
OK = 0,
MODEL_INTERPRETATION_ERROR,
MEMORY_ALLOCATION_ERROR,
}; };
struct ModelSpec { struct ModelSpec {
...@@ -27,5 +32,6 @@ struct ModelSpec { ...@@ -27,5 +32,6 @@ struct ModelSpec {
// interface pipe. The Model interface pipe can be used to acquire multiple // interface pipe. The Model interface pipe can be used to acquire multiple
// separate GraphExecutor instances. // separate GraphExecutor instances.
interface Model { interface Model {
CreateGraphExecutor(GraphExecutor& request); CreateGraphExecutor(GraphExecutor& request) =>
(CreateGraphExecutorResult result);
}; };
...@@ -13,22 +13,29 @@ ...@@ -13,22 +13,29 @@
module chromeos.machine_learning.mojom; module chromeos.machine_learning.mojom;
// Corresponds to tensorflow.BytesList protobuf:
struct StringList { struct StringList {
array<string> value; array<string> value;
}; };
// Corresponds to tensorflow.FloatList protobuf:
struct FloatList { struct FloatList {
array<double> value; array<double> value;
}; };
// Corresponds to tensorflow.Int64List protobuf:
struct Int64List { struct Int64List {
array<int64> value; array<int64> value;
}; };
// Corresponds to tensorflow.Feature protobuf: // The union of all supported tensor types. Supporting a new type comprises the
// following:
// - Adding a new struct above (e.g. BoolList),
// - Adding this new struct to the union below,
// - Adding template specializations for the new type to
// platform2/ml/tensor_view.{h,cc}.
// - Updating platform2/ml/graph_executor_impl.cc to use a TensorView of the
// new type.
//
// TODO(chromium:836098): add new types (e.g. uint8, bool) as they become
// useful.
union ValueList { union ValueList {
StringList string_list; StringList string_list;
FloatList float_list; FloatList float_list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment