driver_api.h 3.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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.
 */

/*!
21 22
 * \file tvm/driver/driver_api.h
 * \brief Compiler driver APIs to drive the compilation.
23 24 25 26 27 28
 *
 * This module provides end-to-end utils to drive the compilation process.
 * We adopt the term "compiler driver" in common compiler infrastructures.
 * Note that a compiler driver is different from "runtime drivers".
 * Most of runtime related code are defined in the runtime folder instead.
 */
29 30
#ifndef TVM_DRIVER_DRIVER_API_H_
#define TVM_DRIVER_DRIVER_API_H_
31 32 33 34

#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>
#include <tvm/support/with.h>
35
#include <tvm/ir/module.h>
36
#include <tvm/te/schedule_pass.h>
37 38 39 40 41 42 43 44 45

#include <string>
#include <vector>
#include <utility>
#include <unordered_map>
#include <unordered_set>

namespace tvm {
/*!
46
* \brief Build an IRModule given a schedule, args and binds
47 48 49 50 51
* \param sch The schedule to lower.
* \param args The arguments to the function.
* \param name The name of the lowered function.
* \param binds Buffer assignments.
* \param config The build configuration.
52
* \return The result module.
53
*/
54
TVM_DLL IRModule lower(
55 56
    te::Schedule sch,
    const Array<te::Tensor>& args,
57
    const std::string& name,
58
    const std::unordered_map<te::Tensor, tir::Buffer>& binds,
59 60 61
    const BuildConfig& config);

/*!
62
* \brief Build a device and host module for a specific target from an IRModule.
63 64 65 66 67 68
* \param funcs The functions to be built.
* \param target The target device to build for.
* \param target_host The target for building host code. To use the default, pass Target()
* \param config The build configuration.
* \return The built module.
*/
69
TVM_DLL runtime::Module build(const IRModule& funcs,
70 71 72 73 74 75
                              const Target& target,
                              const Target& target_host,
                              const BuildConfig& config);

/*!
 * \brief Build a device and host module for a specific target from a map
76
 * contains target to IRModule. This function is used
77
 * for heterogeneous build.
78
 * \param input The map contains target to an IRModule.
79 80 81 82 83
 * \param target_host The target for building host code. To use the default,
 *        pass Target().
 * \param config The build configuration.
 * \return The built module that contains code for different processors.
 */
84
TVM_DLL runtime::Module build(const Map<Target, IRModule>& input,
85 86 87 88 89
                              const Target& target_host,
                              const BuildConfig& config);

/*!
 * \brief Build a device and host module for a specific target from a map
90
 * contains target to IRModule. This function is used
91
 * for heterogeneous build.
92
 * \param input The map contains target string to an  IRModule.
93 94 95 96 97
 * \param target_host The target for building host code. To use the default,
 *        pass Target().
 * \param config The build configuration.
 * \return The built module that contains code for different processors.
 */
98
TVM_DLL runtime::Module build(const Map<std::string, IRModule>& input,
99 100 101 102
                              const Target& target_host,
                              const BuildConfig& config);
}  // namespace tvm

103
#endif  // TVM_DRIVER_DRIVER_API_H_