blob: 7e3b9270357c1eb0f6c7877c2dc1487f3fef0b2e [file] [log] [blame]
Alan Green645d0e32020-04-28 14:37:41 +10001// Copyright 2020 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <iostream>
6
7#include <base/at_exit.h>
8#include <base/threading/thread_task_runner_handle.h>
Alan Greenb9d0c832020-04-30 08:29:50 +10009#include <brillo/flag_helper.h>
Alan Green645d0e32020-04-28 14:37:41 +100010#include <brillo/message_loops/base_message_loop.h>
11#include <mojo/core/embedder/embedder.h>
12#include <mojo/core/embedder/scoped_ipc_support.h>
13
Alan Greenb9d0c832020-04-30 08:29:50 +100014#include "ml/simple.h"
Alan Green645d0e32020-04-28 14:37:41 +100015
Alan Greenb9d0c832020-04-30 08:29:50 +100016// Starts environment to support Mojo
17void StartMojo() {
Alan Green645d0e32020-04-28 14:37:41 +100018 (new brillo::BaseMessageLoop())->SetAsCurrent();
Alan Green645d0e32020-04-28 14:37:41 +100019 mojo::core::Init();
20 mojo::core::ScopedIPCSupport _(
21 base::ThreadTaskRunnerHandle::Get(),
22 mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST);
Alan Greenb9d0c832020-04-30 08:29:50 +100023}
Alan Green645d0e32020-04-28 14:37:41 +100024
Alan Greenb9d0c832020-04-30 08:29:50 +100025int main(int argc, char** argv) {
26 base::AtExitManager at_exit;
27 StartMojo();
28
29 // TODO(avg): add flag to specify that NNAPI should be used
30 DEFINE_double(x, 1.0, "First operand for add");
31 DEFINE_double(y, 4.0, "Second operand for add");
Alan Green55e16542020-05-11 14:06:46 +100032 DEFINE_bool(nnapi, false, "Whether to use NNAPI");
Alan Greenb9d0c832020-04-30 08:29:50 +100033 brillo::FlagHelper::Init(argc, argv, "ML Service commandline tool");
34
35 // TODO(avg): add ability to run arbitrary models
Alan Green55e16542020-05-11 14:06:46 +100036 std::string processing = FLAGS_nnapi ? "NNAPI" : "CPU";
37 std::cout << "Adding " << FLAGS_x << " and " << FLAGS_y << " with "
38 << processing << std::endl;
39 auto result = ml::simple::Add(FLAGS_x, FLAGS_y, FLAGS_nnapi);
Alan Greenb9d0c832020-04-30 08:29:50 +100040 std::cout << "Status: " << result.status << std::endl;
41 std::cout << "Sum: " << result.sum << std::endl;
Alan Green645d0e32020-04-28 14:37:41 +100042
43 return 0;
44}