Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 44 additions & 40 deletions include/tvm/build_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "lowered_func.h"

namespace tvm {
using namespace tvm::runtime;

/*!
* \brief Container for target device information.
Expand All @@ -40,7 +39,7 @@ class TargetNode : public Node {
Array<Expr> libs_array;

/*! \return the full device string to pass to codegen::Build */
EXPORT std::string str() const;
TVM_DLL const std::string& str() const;

void VisitAttrs(AttrVisitor* v) final {
v->Visit("target_name", &target_name);
Expand All @@ -54,16 +53,20 @@ class TargetNode : public Node {
}

/*! \brief Get the keys for this target as a vector of string */
EXPORT std::vector<std::string> keys() const;
TVM_DLL std::vector<std::string> keys() const;

/*! \brief Get the options for this target as a vector of string */
EXPORT std::vector<std::string> options() const;
TVM_DLL std::vector<std::string> options() const;

/*! \brief Get the keys for this target as an unordered_set of string */
EXPORT std::unordered_set<std::string> libs() const;
TVM_DLL std::unordered_set<std::string> libs() const;

static constexpr const char* _type_key = "Target";
TVM_DECLARE_NODE_TYPE_INFO(TargetNode, Node);

private:
/*! \brief Internal string repr. */
mutable std::string str_repr_;
};

class Target : public NodeRef {
Expand All @@ -75,20 +78,20 @@ class Target : public NodeRef {
* \brief Create a Target given a string
* \param target_str the string to parse
*/
EXPORT static Target create(const std::string& target_str);
TVM_DLL static Target create(const std::string& target_str);

/*!
* \brief Push a new target context onto the thread local stack. The Target on top of
* the stack is used to determine which specialization to use when invoking a GenericFunc.
* \param target The target to set as the current context.
*/
EXPORT static void EnterTargetScope(const tvm::Target& target);
TVM_DLL static void EnterTargetScope(const tvm::Target& target);

/*!
* \brief Pop a target off the thread local context stack, restoring the previous target
* as the current context.
*/
EXPORT static void ExitTargetScope();
TVM_DLL static void ExitTargetScope();

/*!
* \brief Get the current target context from thread local storage.
Expand All @@ -98,7 +101,7 @@ class Target : public NodeRef {
* \return The target that is the current context. The target may not be defined if
* allow_not_defined is true.
*/
EXPORT static tvm::Target current_target(bool allow_not_defined = true);
TVM_DLL static tvm::Target current_target(bool allow_not_defined = true);

inline const TargetNode* operator->() const {
return static_cast<const TargetNode*>(node_.get());
Expand Down Expand Up @@ -130,39 +133,39 @@ struct TargetContext {
/*! \brief This namespace provides functions to construct Target instances */
namespace target {
/*! \return A target for LLVM */
EXPORT Target llvm(const std::vector<std::string>& options =
TVM_DLL Target llvm(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for CUDA */
EXPORT Target cuda(const std::vector<std::string>& options =
TVM_DLL Target cuda(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for ROCm */
EXPORT Target rocm(const std::vector<std::string>& options =
TVM_DLL Target rocm(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for OpenCL */
EXPORT Target opencl(const std::vector<std::string>& options =
TVM_DLL Target opencl(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for Metal */
EXPORT Target metal(const std::vector<std::string>& options =
TVM_DLL Target metal(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for rasp */
EXPORT Target rasp(const std::vector<std::string>& options =
TVM_DLL Target rasp(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for Mali */
EXPORT Target mali(const std::vector<std::string>& options =
TVM_DLL Target mali(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for Intel Graphics */
EXPORT Target intel_graphics(const std::vector<std::string>& options =
TVM_DLL Target intel_graphics(const std::vector<std::string>& options =
std::vector<std::string>());

/*! \return A target for stackvm */
EXPORT Target stackvm(const std::vector<std::string>& options =
TVM_DLL Target stackvm(const std::vector<std::string>& options =
std::vector<std::string>());

} // namespace target
Expand Down Expand Up @@ -212,7 +215,7 @@ class BuildConfigNode : public Node {
bool partition_const_loop = false;

/*! \brief Whether to dump the IR of each pass (only when building from python) */
std::vector< std::pair<int, PackedFunc> > add_lower_pass;
std::vector< std::pair<int, runtime::PackedFunc> > add_lower_pass;

/*! \brief Whether to dump the IR of each pass (only when building from python) */
bool dump_pass_ir = false;
Expand Down Expand Up @@ -255,20 +258,20 @@ class BuildConfig : public ::tvm::NodeRef {
* \brief Push a new BuildConfig context onto the thread local stack.
* \param build_config The configuration to set as the current context.
*/
EXPORT static void EnterBuildConfigScope(const tvm::BuildConfig& build_config);
TVM_DLL static void EnterBuildConfigScope(const tvm::BuildConfig& build_config);

/*!
* \brief Pop a build config off the thread local context stack, restoring the previous
* configuration as the current context.
*/
EXPORT static void ExitBuildConfigScope();
TVM_DLL static void ExitBuildConfigScope();

/*!
* \brief Get the current BuildConfig context from thread local storage, or a default
* configuration if a BuildConfig scope has not been entered.
* \return The configuration that is the current context.
*/
EXPORT static tvm::BuildConfig Current();
TVM_DLL static tvm::BuildConfig Current();

using ContainerType = BuildConfigNode;
};
Expand Down Expand Up @@ -297,7 +300,7 @@ struct BuildConfigContext {
* \brief Construct a BuildConfig containing a new BuildConfigNode
* \return The new BuildConfig
*/
EXPORT BuildConfig build_config();
TVM_DLL BuildConfig build_config();

/*!
* \brief Build a LoweredFunc given a schedule, args and binds
Expand All @@ -308,11 +311,11 @@ EXPORT BuildConfig build_config();
* \param config The build configuration.
* \return The lowered function.
*/
EXPORT Array<LoweredFunc> lower(Schedule sch,
const Array<Tensor>& args,
const std::string& name,
const std::unordered_map<Tensor, Buffer>& binds,
const BuildConfig& config);
TVM_DLL Array<LoweredFunc> lower(Schedule sch,
const Array<Tensor>& args,
const std::string& name,
const std::unordered_map<Tensor, Buffer>& binds,
const BuildConfig& config);

/*!
* \brief Build a device and host module for a specific target from an array of lowered functions.
Expand All @@ -322,10 +325,10 @@ EXPORT Array<LoweredFunc> lower(Schedule sch,
* \param config The build configuration.
* \return The built module.
*/
EXPORT runtime::Module build(const Array<LoweredFunc>& funcs,
const Target& target,
const Target& target_host,
const BuildConfig& config);
TVM_DLL runtime::Module build(const Array<LoweredFunc>& funcs,
const Target& target,
const Target& target_host,
const BuildConfig& config);

class GenericFuncNode;

Expand All @@ -344,7 +347,7 @@ class GenericFunc : public NodeRef {
* false, an error will be logged if the call would override a previously registered function.
* \return reference to self.
*/
TVM_DLL GenericFunc& set_default(const PackedFunc value,
TVM_DLL GenericFunc& set_default(const runtime::PackedFunc value,
bool allow_override = false);
/*!
* \brief Register a specialized function
Expand All @@ -355,7 +358,7 @@ class GenericFunc : public NodeRef {
* \return reference to self.
*/
TVM_DLL GenericFunc& register_func(const std::vector<std::string>& tags,
const PackedFunc value,
const runtime::PackedFunc value,
bool allow_override = false);
/*!
* \brief Call generic function by directly passing in unpacked format.
Expand All @@ -372,14 +375,15 @@ class GenericFunc : public NodeRef {
* \endcode
*/
template<typename... Args>
inline TVMRetValue operator()(Args&& ...args) const;
inline runtime::TVMRetValue operator()(Args&& ...args) const;
/*!
* \brief Invoke the relevant function for the current target context, set by set_target_context.
* Arguments are passed in packed format.
* \param args The arguments to pass to the function.
* \param ret The return value
*/
TVM_DLL void CallPacked(TVMArgs args, TVMRetValue* ret) const;
TVM_DLL void CallPacked(runtime::TVMArgs args,
runtime::TVMRetValue* ret) const;

/*!
* \brief Find or register the GenericFunc instance corresponding to the give name
Expand Down Expand Up @@ -412,14 +416,14 @@ class GenericFunc : public NodeRef {
};

template<typename... Args>
inline TVMRetValue GenericFunc::operator()(Args&& ...args) const {
inline runtime::TVMRetValue GenericFunc::operator()(Args&& ...args) const {
const int kNumArgs = sizeof...(Args);
const int kArraySize = kNumArgs > 0 ? kNumArgs : 1;
TVMValue values[kArraySize];
int type_codes[kArraySize];
runtime::detail::for_each(TVMArgsSetter(values, type_codes),
std::forward<Args>(args)...);
TVMRetValue rv;
runtime::TVMRetValue rv;
CallPacked(TVMArgs(values, type_codes, kNumArgs), &rv);
return rv;
}
Expand All @@ -432,9 +436,9 @@ class GenericFuncNode : public Node {
/*! \brief name of the function */
std::string name_;
/* \brief the generic builder */
PackedFunc generic_func_;
runtime::PackedFunc generic_func_;
/* \brief map from keys to registered functions */
std::unordered_map<std::string, PackedFunc> dispatch_dict_;
std::unordered_map<std::string, runtime::PackedFunc> dispatch_dict_;

static constexpr const char* _type_key = "GenericFunc";
TVM_DECLARE_NODE_TYPE_INFO(GenericFuncNode, Node);
Expand Down
76 changes: 0 additions & 76 deletions include/tvm/relay/build_module.h

This file was deleted.

16 changes: 11 additions & 5 deletions include/tvm/relay/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef TVM_RELAY_INTERPRETER_H_
#define TVM_RELAY_INTERPRETER_H_

#include <tvm/build_module.h>
#include <tvm/relay/module.h>
#include <tvm/relay/expr.h>

Expand All @@ -27,7 +28,9 @@ namespace relay {
*/
class Value;

/*! \brief Evaluate an expression using the interpreter producing a value.
/*!
*\brief Create a Interpreter function that can
* evaluate an expression and produce a value.
*
* The resulting value can be passed to Python, making it easy to use
* for testing and debugging.
Expand All @@ -38,8 +41,14 @@ class Value;
*
* Our intent is that this will never be the most efficient implementation of
* Relay's semantics, but a readable and clear one.
*
* \param mod The function module.
* \param context The primary context that the interepreter runs on.
* \param target Compiler target flag to compile the functions on the context.
* \return A function that takes in an expression and returns a value.
*/
Value Evaluate(Module mod, Expr e);
runtime::TypedPackedFunc<Value(Expr)>
CreateInterpreter(Module mod, DLContext context, Target target);

/*! \brief The base container type of Relay values. */
class ValueNode : public RelayNode {
Expand Down Expand Up @@ -125,9 +134,6 @@ struct TensorValueNode : ValueNode {
/*! \brief Build a value from an NDArray. */
TVM_DLL static TensorValue make(runtime::NDArray data);

/*! \brief Construct an empty tensor value from t. */
TVM_DLL static TensorValue FromType(const Type& t);

static constexpr const char* _type_key = "relay.TensorValue";
TVM_DECLARE_NODE_TYPE_INFO(TensorValueNode, ValueNode);
};
Expand Down
Loading