/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #ifndef TVM_S_TIR_META_SCHEDULE_TUNE_CONTEXT_H_ #define TVM_S_TIR_META_SCHEDULE_TUNE_CONTEXT_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace tvm { namespace s_tir { namespace meta_schedule { class TaskSchedulerNode; class MeasureCallback; class TuneContext; /*! \brief The auto tuning context. */ class TuneContextNode : public ffi::Object { public: using TRandState = LinearCongruentialEngine::TRandState; /*! \brief The workload to be tuned. */ ffi::Optional mod; /*! \brief The target to be tuned for. */ ffi::Optional target; /*! \brief The design space generator. */ ffi::Optional space_generator; /*! \brief The search strategy. */ ffi::Optional search_strategy; /*! \brief The name of the tuning task. */ ffi::Optional task_name; /*! \brief The number of threads to be used. */ int num_threads; /*! \brief The random state. */ TRandState rand_state; /*! \brief The tuning task's logging function. t*/ ffi::Function logger; static void RegisterReflection() { namespace refl = tvm::ffi::reflection; refl::ObjectDef() .def_ro("mod", &TuneContextNode::mod) .def_ro("target", &TuneContextNode::target) .def_ro("space_generator", &TuneContextNode::space_generator) .def_ro("search_strategy", &TuneContextNode::search_strategy) .def_ro("task_name", &TuneContextNode::task_name) .def_ro("num_threads", &TuneContextNode::num_threads) .def_ro("rand_state", &TuneContextNode::rand_state); // `logger` is not registered } /*! * \brief Initialize members that needs initialization with tune context. */ void Initialize(); /*! * \brief Clone the tune context. * \return The cloned tune context. */ TuneContext Clone() const; static constexpr const bool _type_mutable = true; TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.TuneContext", TuneContextNode, ffi::Object); }; /*! * \brief Managed reference to TuneContextNode. * \sa TuneContextNode */ class TuneContext : public ffi::ObjectRef { public: using TRandState = LinearCongruentialEngine::TRandState; /*! * \brief Constructor from ffi::ObjectPtr. * \param data The object pointer. */ explicit TuneContext(ffi::ObjectPtr data) : ffi::ObjectRef(data) { TVM_FFI_ICHECK(data != nullptr); } /*! * \brief Constructor. * \param mod The workload to be tuned. * \param target The target to be tuned for. * \param space_generator The design space generator. * \param search_strategy The search strategy. * \param task_name The name of the tuning task. * \param num_threads The number of threads to be used. * \param rand_state The random state. * \param logger The tuning task's logging function. */ TVM_DLL explicit TuneContext(ffi::Optional mod, ffi::Optional target, ffi::Optional space_generator, ffi::Optional search_strategy, ffi::Optional task_name, int num_threads, TRandState rand_state, ffi::Function logger); TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TuneContext, ffi::ObjectRef, TuneContextNode); }; } // namespace meta_schedule } // namespace s_tir } // namespace tvm #endif // TVM_S_TIR_META_SCHEDULE_TUNE_CONTEXT_H_