Skip to content

Commit

Permalink
Optimize Linux shared library modules (*.so files) (apache#2445)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony-Mai authored and merrymercy committed Feb 17, 2019
1 parent 704fceb commit db5e100
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 135 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/HalideIR
2 changes: 1 addition & 1 deletion 3rdparty/dlpack
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ else(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_compile_options(-O0 -Wall -fPIC -std=c++11)
add_compile_options(-O0 -Wall -fPIC -fvisibility=hidden -std=c++11)
else()
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11 ${CMAKE_CXX_FLAGS}")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = DMLC_USE_CXX11
PREDEFINED = DMLC_USE_CXX11 TVM_DLL= NNVM_DLL= __attribute__(x)=

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
20 changes: 0 additions & 20 deletions include/tvm/ir_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,6 @@ TVM_DLL Expr max(Expr a, Expr b);
* index types(int32, int64) when possible.
*/
TVM_DLL Expr min(Expr a, Expr b);
/*!
* \brief right shift
*
* \param a left operand
* \param b right operand
* \return The result expression.
* \note this function does eager constant folding for
* index types(int32, int64) when possible.
*/
TVM_DLL Expr operator>>(Expr a, Expr b);
/*!
* \brief left shift
*
* \param a left operand
* \param b right operand
* \return The result expression.
* \note this function does eager constant folding for
* index types(int32, int64) when possible.
*/
TVM_DLL Expr operator<<(Expr a, Expr b);
/*!
* \brief take bitwise and of two values
*
Expand Down
12 changes: 6 additions & 6 deletions include/tvm/ir_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ir {
* \param vrange The range information about the variable.
* \return Canonicalized statement.
*/
EXPORT Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());
TVM_DLL Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());

/*!
* \brief Simplify the statement.
Expand All @@ -52,7 +52,7 @@ Stmt CanonicalSimplify(Stmt stmt,
* \param vrange The range information about the variable.
* \return Canonicalized expression.
*/
EXPORT Expr CanonicalSimplify(Expr expr,
TVM_DLL Expr CanonicalSimplify(Expr expr,
Map<Var, Range> vrange = Map<Var, Range>());

/*!
Expand All @@ -61,7 +61,7 @@ EXPORT Expr CanonicalSimplify(Expr expr,
* \param rhs The right operand
* \return The comparison result.
*/
EXPORT bool Equal(const Expr& lhs, const Expr& rhs);
TVM_DLL bool Equal(const Expr& lhs, const Expr& rhs);

/*!
* \brief Deep compare lhs and rhs
Expand Down Expand Up @@ -92,13 +92,13 @@ int Compare(const Expr& lhs, const Expr& rhs);
* \return Whether IR is in SSA form.
* \note All the passes in this file uses SSA form and outputs SSA form.
*/
bool VerifySSA(const Stmt& ir);
TVM_DLL bool VerifySSA(const Stmt& ir);

/*!
* \brief Whether the expression have side effect.
* \return whether expression have side effect
*/
bool HasSideEffect(const Expr& e);
TVM_DLL bool HasSideEffect(const Expr& e);

/*!
* \brief Whether e expression used var.
Expand All @@ -121,7 +121,7 @@ bool ExprUseVar(const Expr& e, const std::unordered_set<const Variable*>& vset);
* \param stmt The source statement to be converted.
* \return The converted form.
*/
Stmt ConvertSSA(Stmt stmt);
TVM_DLL Stmt ConvertSSA(Stmt stmt);

/*!
* \brief Substitute the var specified in key->var to be value.
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir_visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TVM_DLL IRVisitor {
* \param node The ir to be visited.
* \param fvisit The visitor function to be applied.
*/
void PostOrderVisit(const NodeRef& node, std::function<void(const NodeRef&)> fvisit);
TVM_DLL void PostOrderVisit(const NodeRef& node, std::function<void(const NodeRef&)> fvisit);

} // namespace ir
} // namespace tvm
Expand Down
46 changes: 23 additions & 23 deletions include/tvm/relay/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace relay {
*
* \return A type checked expression with its checked_type field populated.
*/
Expr InferType(const Expr& expr, const Module& mod);
TVM_DLL Expr InferType(const Expr& expr, const Module& mod);

/*!
* \brief Infer the type of a function as if it is mapped to var in the mod.
Expand All @@ -39,8 +39,8 @@ Expr InferType(const Expr& expr, const Module& mod);
* \return A type checked Function with its checked_type field populated.
* \note this function mutates mod and is not thread-safe.
*/
Function InferType(const Function& f, const Module& mod,
const GlobalVar& var);
TVM_DLL Function InferType(const Function& f, const Module& mod,
const GlobalVar& var);

/*!
* \brief Check that types are well kinded by applying "kinding rules".
Expand All @@ -58,7 +58,7 @@ Function InferType(const Function& f, const Module& mod,
*
* \return true if the rules are satisified otherwise false
*/
bool KindCheck(const Type& t, const Module& mod);
TVM_DLL bool KindCheck(const Type& t, const Module& mod);

/*! \brief Compare two expressions for structural equivalence.
*
Expand All @@ -75,7 +75,7 @@ bool KindCheck(const Type& t, const Module& mod);
*
* \return true if equal, otherwise false
*/
bool AlphaEqual(const Expr& e1, const Expr& e2);
TVM_DLL bool AlphaEqual(const Expr& e1, const Expr& e2);

/*! \brief Compare two types for structural equivalence.
*
Expand All @@ -93,7 +93,7 @@ bool AlphaEqual(const Expr& e1, const Expr& e2);
*
* \return true if equal, otherwise false
*/
bool AlphaEqual(const Type& t1, const Type& t2);
TVM_DLL bool AlphaEqual(const Type& t1, const Type& t2);

/*! \brief Check that each Var is only bound once.
*
Expand All @@ -106,7 +106,7 @@ bool AlphaEqual(const Type& t1, const Type& t2);
*
* \return true iff all Var in expr is bound at most once.
*/
bool WellFormed(const Expr& expr);
TVM_DLL bool WellFormed(const Expr& expr);

/*! \brief Get all bound variables from expression expr.
*
Expand All @@ -117,7 +117,7 @@ bool WellFormed(const Expr& expr);
*
* \return List of bound vars, in the PostDFS order in the expression.
*/
tvm::Array<Var> BoundVars(const Expr& expr);
TVM_DLL tvm::Array<Var> BoundVars(const Expr& expr);

/*! \brief Get free type parameters from expression expr.
*
Expand All @@ -128,15 +128,15 @@ tvm::Array<Var> BoundVars(const Expr& expr);
*
* \return List of free vars, in the PostDFS order in the expression.
*/
tvm::Array<Var> FreeVars(const Expr& expr);
TVM_DLL tvm::Array<Var> FreeVars(const Expr& expr);

/*! \brief Get all variables from expression expr.
*
* \param expr the expression.
*
* \return List of all vars, in the PostDFS order in the expression.
*/
tvm::Array<Var> AllVars(const Expr& expr);
TVM_DLL tvm::Array<Var> AllVars(const Expr& expr);

/*! \brief Get free TypeVars from expression expr.
*
Expand All @@ -147,7 +147,7 @@ tvm::Array<Var> AllVars(const Expr& expr);
*
* \return List of free vars, in the PostDFS order visited by expr.
*/
tvm::Array<TypeVar> FreeTypeVars(const Expr& expr);
TVM_DLL tvm::Array<TypeVar> FreeTypeVars(const Expr& expr);

/*! \brief Get free TypeVars from type t.
*
Expand All @@ -158,7 +158,7 @@ tvm::Array<TypeVar> FreeTypeVars(const Expr& expr);
*
* \return List of free type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> FreeTypeVars(const Type& t);
TVM_DLL tvm::Array<TypeVar> FreeTypeVars(const Type& t);

/*! \brief Get all bound type variables from expression expr.
*
Expand All @@ -169,7 +169,7 @@ tvm::Array<TypeVar> FreeTypeVars(const Type& t);
*
* \return List of bound type vars, in the PostDFS order in the expression.
*/
tvm::Array<TypeVar> BoundTypeVars(const Expr& expr);
TVM_DLL tvm::Array<TypeVar> BoundTypeVars(const Expr& expr);

/*! \brief Get all bound type variables from type t.
*
Expand All @@ -180,23 +180,23 @@ tvm::Array<TypeVar> BoundTypeVars(const Expr& expr);
*
* \return List of bound type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> BoundTypeVars(const Type& t);
TVM_DLL tvm::Array<TypeVar> BoundTypeVars(const Type& t);

/*! \brief Get all type variables in expression expr.
*
* \param expr the expression.
*
* \return List of type vars, in the PostDFS order in the expression.
*/
tvm::Array<TypeVar> AllTypeVars(const Expr& expr);
TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Expr& expr);

/*! \brief Get all type variables in type t.
*
* \param t the type.
*
* \return List of type vars, in the PostDFS order visited by type.
*/
tvm::Array<TypeVar> AllTypeVars(const Type& t);
TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Type& t);

/*! \brief Remove expressions which does not effect the program result.
*
Expand All @@ -211,22 +211,22 @@ tvm::Array<TypeVar> AllTypeVars(const Type& t);
*
* \return the optimized expression.
*/
Expr DeadCodeElimination(const Expr& e);
TVM_DLL Expr DeadCodeElimination(const Expr& e);

/*!
* \brief Fold constant expressions.
* \param expr the expression to be optimized.
* \return The optimized expression.
*/
Expr FoldConstant(const Expr& expr);
TVM_DLL Expr FoldConstant(const Expr& expr);

/*!
* \brief Fuse operations into expr into seperate functions.
* \param expr The expression.
* \param fuse_opt_level Optimization level.
* \return The optimized expression.
*/
Expr FuseOps(const Expr& expr, int fuse_opt_level);
TVM_DLL Expr FuseOps(const Expr& expr, int fuse_opt_level);

/*!
* \brief Apply rewrite rules to rewrite the expr in post DFS order.
Expand All @@ -238,7 +238,7 @@ Expr FuseOps(const Expr& expr, int fuse_opt_level);
* an Expr consumed by multiple callers.
* \return The rewritten expression.
*/
Expr ForwardRewrite(const Expr& expr,
TVM_DLL Expr ForwardRewrite(const Expr& expr,
const std::string& rewrite_map_attr_name,
std::function<NodeRef(const Call&)> fcontext = nullptr,
std::function<Expr(const Expr&)> fmulti_ref_trigger = nullptr);
Expand All @@ -252,7 +252,7 @@ Expr ForwardRewrite(const Expr& expr,
* an Expr consumed by multiple callers.
* \return The rewritten expression.
*/
Expr ForwardRewrite(const Expr& expr,
TVM_DLL Expr ForwardRewrite(const Expr& expr,
const FForwardRewrite& rewrite_func,
std::function<NodeRef(const Call&)> fcontext = nullptr,
std::function<Expr(const Expr&)> fmulti_ref_trigger = nullptr);
Expand All @@ -264,14 +264,14 @@ Expr ForwardRewrite(const Expr& expr,
* operators without annotation.
* \return The updated program.
*/
Expr RewriteAnnotatedOps(const Expr& expr, int fallback_device);
TVM_DLL Expr RewriteAnnotatedOps(const Expr& expr, int fallback_device);

/*!
* \brief Collect the device mapping information of each expression.
* \param expr The expression.
* \return The device mapping.
*/
Map<Expr, Integer> CollectDeviceInfo(const Expr& expr);
TVM_DLL Map<Expr, Integer> CollectDeviceInfo(const Expr& expr);

/*! \brief A hashing structure in the style of std::hash. */
struct StructuralHash {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define TVM_DLL __declspec(dllimport)
#endif
#else
#define TVM_DLL
#define TVM_DLL __attribute__((visibility("default")))
#endif
#endif

Expand Down
14 changes: 7 additions & 7 deletions include/tvm/runtime/device_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ constexpr int kTempAllocaAlignment = 64;
constexpr int kMaxStackAlloca = 1024;

/*!
* \brief TVM Runtime Device API, abstracts the device
* \brief TVM Runtime Device API, abstracts the device
* specific interface for memory management.
*/
class DeviceAPI {
class TVM_DLL DeviceAPI {
public:
/*! \brief virtual destructor */
virtual ~DeviceAPI() {}
Expand Down Expand Up @@ -103,15 +103,15 @@ class DeviceAPI {
*
* \param ctx The context of allocation.
*/
TVM_DLL virtual TVMStreamHandle CreateStream(TVMContext ctx);
virtual TVMStreamHandle CreateStream(TVMContext ctx);

/*!
* \brief Free a stream of execution
*
* \param ctx The context of the stream
* \param stream The pointer to be freed.
*/
TVM_DLL virtual void FreeStream(TVMContext ctx, TVMStreamHandle stream);
virtual void FreeStream(TVMContext ctx, TVMStreamHandle stream);

/*!
* \brief Synchronize the stream
Expand All @@ -137,7 +137,7 @@ class DeviceAPI {
* \param event_src The source stream to synchronize.
* \param event_dst The destination stream to synchronize.
*/
TVM_DLL virtual void SyncStreamFromTo(TVMContext ctx,
virtual void SyncStreamFromTo(TVMContext ctx,
TVMStreamHandle event_src,
TVMStreamHandle event_dst);
/*!
Expand All @@ -156,7 +156,7 @@ class DeviceAPI {
* \param type_hint The type of elements. Only needed by certain backends such
* as OpenGL, as nbytes is sufficient for most backends.
*/
TVM_DLL virtual void* AllocWorkspace(TVMContext ctx,
virtual void* AllocWorkspace(TVMContext ctx,
size_t nbytes,
TVMType type_hint = {});
/*!
Expand All @@ -165,7 +165,7 @@ class DeviceAPI {
* \param ctx The context of allocation.
* \param ptr The pointer to be freed.
*/
TVM_DLL virtual void FreeWorkspace(TVMContext ctx, void* ptr);
virtual void FreeWorkspace(TVMContext ctx, void* ptr);

/*!
* \brief Get device API base don context.
Expand Down
2 changes: 1 addition & 1 deletion nnvm/include/nnvm/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define NNVM_DLL __declspec(dllimport)
#endif
#else
#define NNVM_DLL
#define NNVM_DLL __attribute__((visibility("default")))
#endif

/*! \brief manually define unsigned int */
Expand Down
2 changes: 1 addition & 1 deletion src/relay/backend/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class InterpreterStateNode : public Node {
v->Visit("stack", &stack);
}

TVM_DLL static InterpreterState make(Expr current_expr, Stack stack);
static InterpreterState make(Expr current_expr, Stack stack);

static constexpr const char* _type_key = "relay.InterpreterState";
TVM_DECLARE_NODE_TYPE_INFO(InterpreterStateNode, Node);
Expand Down
Loading

0 comments on commit db5e100

Please sign in to comment.