Skip to content

Commit e74ee0c

Browse files
committed
[TVM] Reduce symbol visibility of shared modules (*.so files)
Default compilation of Linux shared library modules (*.so files) exports all symbols. This creates large module files as the export symbol table contains too many entries. The correct approach is to export nothing by default. Anything that needs to be exported must be explicitly specified. This is done by the following steps: In the Makefile, add "-fvisibility=hidden" flag. You can search for "-fPIC" to find the appropriate place to add the flag. This hides symbols by default if not explicitly specified otherwise. To declare of any symbol to be exported, add this attribute: __attribute__((visibility("default"))) The attribute string can be added using a macro definition. It should be added right before the return type for functions, or right after the 'class' or 'struct' keyword for class/struct. To supress Doxygen parser warnings, modify docs/Doxyfile and add to PRE_DEFINED: TVM_DLL= NNVM_DLL= __attribute__(x)= For more info on shared module export symbol visibility read: https://gcc.gnu.org/wiki/Visibility Update submodule HalideIR to 7a3287d3883fdeac3aba2a7f3865c7ab78e1925c and dlpack to 5c792cef3aee54ad8b7000111c9dc1797f327b59. Explicitly export __gnu_f2h_ieee() which is needed in a unit test. Move the visibility specifier to header files.
1 parent 8818faa commit e74ee0c

File tree

14 files changed

+67
-85
lines changed

14 files changed

+67
-85
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ else(MSVC)
8686
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
8787
add_compile_options(-O0 -Wall -fPIC -fvisibility=hidden -std=c++11)
8888
else()
89-
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
90-
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
89+
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden ${CMAKE_C_FLAGS}")
90+
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fvisibility=hidden -std=c++11 ${CMAKE_CXX_FLAGS}")
9191
endif ()
9292
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND
9393
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)

docs/Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ INCLUDE_FILE_PATTERNS =
19741974
# recursively expanded use the := operator instead of the = operator.
19751975
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
19761976

1977-
PREDEFINED = DMLC_USE_CXX11
1977+
PREDEFINED = DMLC_USE_CXX11 TVM_DLL= NNVM_DLL= __attribute__(x)=
19781978

19791979
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
19801980
# tag can be used to specify a list of macro names that should be expanded. The

include/tvm/ir_operator.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -332,26 +332,6 @@ TVM_DLL Expr max(Expr a, Expr b);
332332
* index types(int32, int64) when possible.
333333
*/
334334
TVM_DLL Expr min(Expr a, Expr b);
335-
/*!
336-
* \brief right shift
337-
*
338-
* \param a left operand
339-
* \param b right operand
340-
* \return The result expression.
341-
* \note this function does eager constant folding for
342-
* index types(int32, int64) when possible.
343-
*/
344-
TVM_DLL Expr operator>>(Expr a, Expr b);
345-
/*!
346-
* \brief left shift
347-
*
348-
* \param a left operand
349-
* \param b right operand
350-
* \return The result expression.
351-
* \note this function does eager constant folding for
352-
* index types(int32, int64) when possible.
353-
*/
354-
TVM_DLL Expr operator<<(Expr a, Expr b);
355335
/*!
356336
* \brief take bitwise and of two values
357337
*

include/tvm/ir_pass.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace ir {
2727
* \param vrange The range information about the variable.
2828
* \return Canonicalized statement.
2929
*/
30-
EXPORT Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());
30+
TVM_DLL Expr Simplify(Expr expr, Map<Var, Range> vrange = Map<Var, Range>());
3131

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

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

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

9797
/*!
9898
* \brief Whether the expression have side effect.
9999
* \return whether expression have side effect
100100
*/
101-
bool HasSideEffect(const Expr& e);
101+
TVM_DLL bool HasSideEffect(const Expr& e);
102102

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

126126
/*!
127127
* \brief Substitute the var specified in key->var to be value.

include/tvm/ir_visitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class TVM_DLL IRVisitor {
131131
* \param node The ir to be visited.
132132
* \param fvisit The visitor function to be applied.
133133
*/
134-
void PostOrderVisit(const NodeRef& node, std::function<void(const NodeRef&)> fvisit);
134+
TVM_DLL void PostOrderVisit(const NodeRef& node, std::function<void(const NodeRef&)> fvisit);
135135

136136
} // namespace ir
137137
} // namespace tvm

include/tvm/relay/pass.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace relay {
2727
*
2828
* \return A type checked expression with its checked_type field populated.
2929
*/
30-
Expr InferType(const Expr& expr, const Module& mod);
30+
TVM_DLL Expr InferType(const Expr& expr, const Module& mod);
3131

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

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

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

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

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

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

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

133133
/*! \brief Get all variables from expression expr.
134134
*
135135
* \param expr the expression.
136136
*
137137
* \return List of all vars, in the PostDFS order in the expression.
138138
*/
139-
tvm::Array<Var> AllVars(const Expr& expr);
139+
TVM_DLL tvm::Array<Var> AllVars(const Expr& expr);
140140

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

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

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

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

185185
/*! \brief Get all type variables in expression expr.
186186
*
187187
* \param expr the expression.
188188
*
189189
* \return List of type vars, in the PostDFS order in the expression.
190190
*/
191-
tvm::Array<TypeVar> AllTypeVars(const Expr& expr);
191+
TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Expr& expr);
192192

193193
/*! \brief Get all type variables in type t.
194194
*
195195
* \param t the type.
196196
*
197197
* \return List of type vars, in the PostDFS order visited by type.
198198
*/
199-
tvm::Array<TypeVar> AllTypeVars(const Type& t);
199+
TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Type& t);
200200

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

216216
/*!
217217
* \brief Fold constant expressions.
218218
* \param expr the expression to be optimized.
219219
* \return The optimized expression.
220220
*/
221-
Expr FoldConstant(const Expr& expr);
221+
TVM_DLL Expr FoldConstant(const Expr& expr);
222222

223223
/*!
224224
* \brief Fuse operations into expr into seperate functions.
225225
* \param expr The expression.
226226
* \param fuse_opt_level Optimization level.
227227
* \return The optimized expression.
228228
*/
229-
Expr FuseOps(const Expr& expr, int fuse_opt_level);
229+
TVM_DLL Expr FuseOps(const Expr& expr, int fuse_opt_level);
230230

231231
/*!
232232
* \brief Apply rewrite rules to rewrite the expr in post DFS order.
@@ -238,7 +238,7 @@ Expr FuseOps(const Expr& expr, int fuse_opt_level);
238238
* an Expr consumed by multiple callers.
239239
* \return The rewritten expression.
240240
*/
241-
Expr ForwardRewrite(const Expr& expr,
241+
TVM_DLL Expr ForwardRewrite(const Expr& expr,
242242
const std::string& rewrite_map_attr_name,
243243
std::function<NodeRef(const Call&)> fcontext = nullptr,
244244
std::function<Expr(const Expr&)> fmulti_ref_trigger = nullptr);
@@ -252,7 +252,7 @@ Expr ForwardRewrite(const Expr& expr,
252252
* an Expr consumed by multiple callers.
253253
* \return The rewritten expression.
254254
*/
255-
Expr ForwardRewrite(const Expr& expr,
255+
TVM_DLL Expr ForwardRewrite(const Expr& expr,
256256
const FForwardRewrite& rewrite_func,
257257
std::function<NodeRef(const Call&)> fcontext = nullptr,
258258
std::function<Expr(const Expr&)> fmulti_ref_trigger = nullptr);
@@ -264,14 +264,14 @@ Expr ForwardRewrite(const Expr& expr,
264264
* operators without annotation.
265265
* \return The updated program.
266266
*/
267-
Expr RewriteAnnotatedOps(const Expr& expr, int fallback_device);
267+
TVM_DLL Expr RewriteAnnotatedOps(const Expr& expr, int fallback_device);
268268

269269
/*!
270270
* \brief Collect the device mapping information of each expression.
271271
* \param expr The expression.
272272
* \return The device mapping.
273273
*/
274-
Map<Expr, Integer> CollectDeviceInfo(const Expr& expr);
274+
TVM_DLL Map<Expr, Integer> CollectDeviceInfo(const Expr& expr);
275275

276276
/*! \brief A hashing structure in the style of std::hash. */
277277
struct StructuralHash {

include/tvm/runtime/c_runtime_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define TVM_DLL __declspec(dllimport)
3939
#endif
4040
#else
41-
#define TVM_DLL
41+
#define TVM_DLL __attribute__((visibility("default")))
4242
#endif
4343
#endif
4444

include/tvm/runtime/device_api.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ constexpr int kTempAllocaAlignment = 64;
3737
constexpr int kMaxStackAlloca = 1024;
3838

3939
/*!
40-
* \brief TVM Runtime Device API, abstracts the device
40+
* \brief TVM Runtime Device API, abstracts the device
4141
* specific interface for memory management.
4242
*/
43-
class DeviceAPI {
43+
class TVM_DLL DeviceAPI {
4444
public:
4545
/*! \brief virtual destructor */
4646
virtual ~DeviceAPI() {}
@@ -103,15 +103,15 @@ class DeviceAPI {
103103
*
104104
* \param ctx The context of allocation.
105105
*/
106-
TVM_DLL virtual TVMStreamHandle CreateStream(TVMContext ctx);
106+
virtual TVMStreamHandle CreateStream(TVMContext ctx);
107107

108108
/*!
109109
* \brief Free a stream of execution
110110
*
111111
* \param ctx The context of the stream
112112
* \param stream The pointer to be freed.
113113
*/
114-
TVM_DLL virtual void FreeStream(TVMContext ctx, TVMStreamHandle stream);
114+
virtual void FreeStream(TVMContext ctx, TVMStreamHandle stream);
115115

116116
/*!
117117
* \brief Synchronize the stream
@@ -137,7 +137,7 @@ class DeviceAPI {
137137
* \param event_src The source stream to synchronize.
138138
* \param event_dst The destination stream to synchronize.
139139
*/
140-
TVM_DLL virtual void SyncStreamFromTo(TVMContext ctx,
140+
virtual void SyncStreamFromTo(TVMContext ctx,
141141
TVMStreamHandle event_src,
142142
TVMStreamHandle event_dst);
143143
/*!
@@ -156,7 +156,7 @@ class DeviceAPI {
156156
* \param type_hint The type of elements. Only needed by certain backends such
157157
* as OpenGL, as nbytes is sufficient for most backends.
158158
*/
159-
TVM_DLL virtual void* AllocWorkspace(TVMContext ctx,
159+
virtual void* AllocWorkspace(TVMContext ctx,
160160
size_t nbytes,
161161
TVMType type_hint = {});
162162
/*!
@@ -165,7 +165,7 @@ class DeviceAPI {
165165
* \param ctx The context of allocation.
166166
* \param ptr The pointer to be freed.
167167
*/
168-
TVM_DLL virtual void FreeWorkspace(TVMContext ctx, void* ptr);
168+
virtual void FreeWorkspace(TVMContext ctx, void* ptr);
169169

170170
/*!
171171
* \brief Get device API base don context.

nnvm/include/nnvm/c_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define NNVM_DLL __declspec(dllimport)
1717
#endif
1818
#else
19-
#define NNVM_DLL
19+
#define NNVM_DLL __attribute__((visibility("default")))
2020
#endif
2121

2222
/*! \brief manually define unsigned int */

src/relay/backend/interpreter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class InterpreterStateNode : public Node {
145145
v->Visit("stack", &stack);
146146
}
147147

148-
TVM_DLL static InterpreterState make(Expr current_expr, Stack stack);
148+
static InterpreterState make(Expr current_expr, Stack stack);
149149

150150
static constexpr const char* _type_key = "relay.InterpreterState";
151151
TVM_DECLARE_NODE_TYPE_INFO(InterpreterStateNode, Node);

0 commit comments

Comments
 (0)