tvm
base.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 /*
21  * \file tvm/runtime/base.h
22  * \brief base macros
23  */
24 #ifndef TVM_RUNTIME_BASE_H_
25 #define TVM_RUNTIME_BASE_H_
26 
27 // TVM runtime fully relies on TVM FFI C API
28 // we will avoid defining extra C APIs here
29 #include <tvm/ffi/c_api.h>
30 
31 // TVM version
32 #define TVM_VERSION "0.25.dev0"
33 
34 // TVM ships two shared libraries: libtvm_compiler and libtvm_runtime.
35 // Each exposes its own DLL macro pair. The two families are defined
36 // independently so that each can be overridden separately by downstream
37 // embedders who need custom visibility on only one of the two libraries.
38 //
39 // TVM_DLL / TVM_DLL_EXPORT: symbols in libtvm_compiler.
40 // - TVM_DLL is dllexport when TVM_EXPORTS is defined (compiler build),
41 // dllimport otherwise (downstream consumers, runtime TUs).
42 // - TVM_DLL_EXPORT is always dllexport.
43 //
44 // TVM_RUNTIME_DLL / TVM_RUNTIME_DLL_EXPORT: symbols in libtvm_runtime.
45 // - TVM_RUNTIME_DLL is dllexport when TVM_RUNTIME_EXPORTS is defined
46 // (runtime build), dllimport otherwise.
47 // - TVM_RUNTIME_DLL_EXPORT is always dllexport.
48 //
49 // On non-MSVC platforms the import/export decision is made by the dynamic
50 // loader, so all four macros expand to visibility("default"). Under
51 // Emscripten they expand to EMSCRIPTEN_KEEPALIVE.
52 #ifdef __EMSCRIPTEN__
53 #include <emscripten/emscripten.h>
54 #endif
55 
56 // --- TVM_DLL family (libtvm_compiler) ---
57 #if !defined(TVM_DLL) && defined(__EMSCRIPTEN__)
58 #define TVM_DLL EMSCRIPTEN_KEEPALIVE
59 #define TVM_DLL_EXPORT EMSCRIPTEN_KEEPALIVE
60 #endif
61 #if !defined(TVM_DLL) && defined(_MSC_VER)
62 #ifdef TVM_EXPORTS
63 #define TVM_DLL __declspec(dllexport)
64 #else
65 #define TVM_DLL __declspec(dllimport)
66 #endif
67 #define TVM_DLL_EXPORT __declspec(dllexport)
68 #endif
69 #ifndef TVM_DLL
70 #define TVM_DLL __attribute__((visibility("default")))
71 #define TVM_DLL_EXPORT __attribute__((visibility("default")))
72 #endif
73 
74 // --- TVM_RUNTIME_DLL family (libtvm_runtime) ---
75 #if !defined(TVM_RUNTIME_DLL) && defined(__EMSCRIPTEN__)
76 #define TVM_RUNTIME_DLL EMSCRIPTEN_KEEPALIVE
77 #define TVM_RUNTIME_DLL_EXPORT EMSCRIPTEN_KEEPALIVE
78 #endif
79 #if !defined(TVM_RUNTIME_DLL) && defined(_MSC_VER)
80 #ifdef TVM_RUNTIME_EXPORTS
81 #define TVM_RUNTIME_DLL __declspec(dllexport)
82 #else
83 #define TVM_RUNTIME_DLL __declspec(dllimport)
84 #endif
85 #define TVM_RUNTIME_DLL_EXPORT __declspec(dllexport)
86 #endif
87 #ifndef TVM_RUNTIME_DLL
88 #define TVM_RUNTIME_DLL __attribute__((visibility("default")))
89 #define TVM_RUNTIME_DLL_EXPORT __attribute__((visibility("default")))
90 #endif
91 
92 #endif // TVM_RUNTIME_BASE_H_