Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 1 | // 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 Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 9 | #include <brillo/flag_helper.h> |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 10 | #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 Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 14 | #include "ml/simple.h" |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 15 | |
Alan Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 16 | // Starts environment to support Mojo |
| 17 | void StartMojo() { |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 18 | (new brillo::BaseMessageLoop())->SetAsCurrent(); |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 19 | mojo::core::Init(); |
| 20 | mojo::core::ScopedIPCSupport _( |
| 21 | base::ThreadTaskRunnerHandle::Get(), |
| 22 | mojo::core::ScopedIPCSupport::ShutdownPolicy::FAST); |
Alan Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 23 | } |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 24 | |
Alan Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 25 | int 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 Green | 55e1654 | 2020-05-11 14:06:46 +1000 | [diff] [blame] | 32 | DEFINE_bool(nnapi, false, "Whether to use NNAPI"); |
Alan Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 33 | brillo::FlagHelper::Init(argc, argv, "ML Service commandline tool"); |
| 34 | |
| 35 | // TODO(avg): add ability to run arbitrary models |
Alan Green | 55e1654 | 2020-05-11 14:06:46 +1000 | [diff] [blame] | 36 | 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 Green | b9d0c83 | 2020-04-30 08:29:50 +1000 | [diff] [blame] | 40 | std::cout << "Status: " << result.status << std::endl; |
| 41 | std::cout << "Sum: " << result.sum << std::endl; |
Alan Green | 645d0e3 | 2020-04-28 14:37:41 +1000 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |