tvm
Loading...
Searching...
No Matches
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. Overridable at build time via -DTVM_VERSION="..." (scikit-build-core
32// passes the setuptools_scm-resolved version through CMake). The literal below is the
33// fallback for a bare build with no override.
34#ifndef TVM_VERSION
35#define TVM_VERSION "0.26.dev0"
36#endif
37
38// TVM ships two shared libraries: libtvm_compiler and libtvm_runtime.
39// Each exposes its own DLL macro pair. The two families are defined
40// independently so that each can be overridden separately by downstream
41// embedders who need custom visibility on only one of the two libraries.
42//
43// TVM_DLL / TVM_DLL_EXPORT: symbols in libtvm_compiler.
44// - TVM_DLL is dllexport when TVM_EXPORTS is defined (compiler build),
45// dllimport otherwise (downstream consumers, runtime TUs).
46// - TVM_DLL_EXPORT is always dllexport.
47//
48// TVM_RUNTIME_DLL / TVM_RUNTIME_DLL_EXPORT: symbols in libtvm_runtime.
49// - TVM_RUNTIME_DLL is dllexport when TVM_RUNTIME_EXPORTS is defined
50// (runtime build), dllimport otherwise.
51// - TVM_RUNTIME_DLL_EXPORT is always dllexport.
52//
53// On non-MSVC platforms the import/export decision is made by the dynamic
54// loader, so all four macros expand to visibility("default"). Under
55// Emscripten they expand to EMSCRIPTEN_KEEPALIVE.
56#ifdef __EMSCRIPTEN__
57#include <emscripten/emscripten.h>
58#endif
59
60// --- TVM_DLL family (libtvm_compiler) ---
61#if !defined(TVM_DLL) && defined(__EMSCRIPTEN__)
62#define TVM_DLL EMSCRIPTEN_KEEPALIVE
63#define TVM_DLL_EXPORT EMSCRIPTEN_KEEPALIVE
64#endif
65#if !defined(TVM_DLL) && defined(_MSC_VER)
66#ifdef TVM_EXPORTS
67#define TVM_DLL __declspec(dllexport)
68#else
69#define TVM_DLL __declspec(dllimport)
70#endif
71#define TVM_DLL_EXPORT __declspec(dllexport)
72#endif
73#ifndef TVM_DLL
74#define TVM_DLL __attribute__((visibility("default")))
75#define TVM_DLL_EXPORT __attribute__((visibility("default")))
76#endif
77
78// --- TVM_RUNTIME_DLL family (libtvm_runtime) ---
79#if !defined(TVM_RUNTIME_DLL) && defined(__EMSCRIPTEN__)
80#define TVM_RUNTIME_DLL EMSCRIPTEN_KEEPALIVE
81#define TVM_RUNTIME_DLL_EXPORT EMSCRIPTEN_KEEPALIVE
82#endif
83#if !defined(TVM_RUNTIME_DLL) && defined(_MSC_VER)
84#ifdef TVM_RUNTIME_EXPORTS
85#define TVM_RUNTIME_DLL __declspec(dllexport)
86#else
87#define TVM_RUNTIME_DLL __declspec(dllimport)
88#endif
89#define TVM_RUNTIME_DLL_EXPORT __declspec(dllexport)
90#endif
91#ifndef TVM_RUNTIME_DLL
92#define TVM_RUNTIME_DLL __attribute__((visibility("default")))
93#define TVM_RUNTIME_DLL_EXPORT __attribute__((visibility("default")))
94#endif
95
96#endif // TVM_RUNTIME_BASE_H_