// Copyright 2021 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef COMPONENTS_OPTIMIZATION_GUIDE_CORE_MODEL_EXECUTOR_H_ #define COMPONENTS_OPTIMIZATION_GUIDE_CORE_MODEL_EXECUTOR_H_ #include <optional> #include "base/files/file_path.h" #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/memory/weak_ptr.h" #include "base/task/sequenced_task_runner.h" #include "base/time/time.h" #include "base/types/optional_ref.h" #include "components/optimization_guide/proto/models.pb.h" namespace optimization_guide { // This class handles the execution, loading, unloading, and associated metrics // of machine learning models in Optimization Guide on a specified thread. This // class is meant to be used and owned by an instance of |ModelHandler|. A // ModelExecutor must be passed to a ModelHandler's constructor, this design // allows the implementer of a ModelExecutor to define how the model is built // and executed. See also tflite_model_executor.h, base_model_executor.h, and // base_model_executor_helpers.h in this directory for helpful derived classes. // // Lifetime: This class can be constructed on any thread but cannot do anything // useful until |InitializeAndMoveToExecutionThread| is called. After that // method is called, all subsequent calls to this class must be made through the // |execution_task_runner| that was passed to initialize. Furthermore, all // WeakPointers of this class must only be dereferenced on the // |execution_task_runner| thread as well. This in turn means that this class // must be destroyed on the |execution_task_runner| thread as well. template <class OutputType, class InputType> class ModelExecutor { … }; } // namespace optimization_guide #endif // COMPONENTS_OPTIMIZATION_GUIDE_CORE_MODEL_EXECUTOR_H_