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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion 3rdparty/cutlass_fpA_intB_gemm
4 changes: 1 addition & 3 deletions apps/android_rpc/app/src/main/jni/tvm_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
#include "../ffi/src/ffi/object.cc"
#include "../ffi/src/ffi/testing.cc"
#include "../ffi/src/ffi/traceback.cc"
#include "../src/runtime/c_runtime_api.cc"
#include "../src/runtime/container.cc"
#include "../src/runtime/cpu_device_api.cc"
#include "../src/runtime/device_api.cc"
#include "../src/runtime/dso_library.cc"
#include "../src/runtime/file_utils.cc"
#include "../src/runtime/library_module.cc"
Expand All @@ -53,7 +52,6 @@
#include "../src/runtime/minrpc/minrpc_logger.cc"
#include "../src/runtime/module.cc"
#include "../src/runtime/ndarray.cc"
#include "../src/runtime/object.cc"
#include "../src/runtime/profiling.cc"
#include "../src/runtime/registry.cc"
#include "../src/runtime/rpc/rpc_channel.cc"
Expand Down
4 changes: 3 additions & 1 deletion apps/cpp_rpc/rpc_env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* \file rpc_env.cc
* \brief Server environment of the RPC.
*/
#include <tvm/runtime/registry.h>
#include <tvm/ffi/function.h>
#include <tvm/runtime/logging.h>
#include <tvm/runtime/module.h>

#include <cerrno>
#ifndef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion apps/cpp_rpc/rpc_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef TVM_APPS_CPP_RPC_ENV_H_
#define TVM_APPS_CPP_RPC_ENV_H_

#include <tvm/runtime/registry.h>
#include <tvm/ffi/function.h>

#include <string>

Expand Down
4 changes: 2 additions & 2 deletions apps/cpp_rpc/rpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* \file rpc_server.cc
* \brief RPC Server implementation.
*/
#include <tvm/runtime/registry.h>
#include <tvm/ffi/function.h>
#if defined(__linux__) || defined(__ANDROID__) || defined(__APPLE__)
#include <signal.h>
#include <sys/select.h>
Expand Down Expand Up @@ -398,6 +398,6 @@ void RPCServerCreate(std::string host, int port, int port_end, std::string track
rpc.Start();
}

TVM_REGISTER_GLOBAL("rpc.ServerCreate").set_body_typed(RPCServerCreate);
TVM_FFI_REGISTER_GLOBAL("rpc.ServerCreate").set_body_typed(RPCServerCreate);
} // namespace runtime
} // namespace tvm
2 changes: 1 addition & 1 deletion apps/cpp_rpc/rpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include <string>

#include "tvm/runtime/c_runtime_api.h"
#include "tvm/runtime/base.h"

namespace tvm {
namespace runtime {
Expand Down
2 changes: 1 addition & 1 deletion apps/hexagon_launcher/launcher_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

#include "launcher_core.h"

#include <tvm/ffi/function.h>
#include <tvm/runtime/c_backend_api.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>

#include <fstream>
#include <ios>
Expand Down
2 changes: 1 addition & 1 deletion apps/ios_rpc/tvmrpc/RPCServer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#import "RPCServer.h"

#include <tvm/ffi/function.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>

#include <random>
#include <string>
Expand Down
8 changes: 4 additions & 4 deletions apps/ios_rpc/tvmrpc/TVMRuntime.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#import <Foundation/Foundation.h>

#include <tvm/runtime/registry.h>
#include <tvm/ffi/function.h>

#include "RPCArgs.h"

Expand Down Expand Up @@ -51,14 +51,14 @@ void LogMessageImpl(const std::string& file, int lineno, int level, const std::s

} // namespace detail

TVM_REGISTER_GLOBAL("tvm.rpc.server.workpath")
TVM_FFI_REGISTER_GLOBAL("tvm.rpc.server.workpath")
.set_body_packed([](ffi::PackedArgs args, ffi::Any* rv) {
static const std::string base_ = NSTemporaryDirectory().UTF8String;
const auto path = args[0].cast<std::string>();
*rv = base_ + "/" + path;
});

TVM_REGISTER_GLOBAL("tvm.rpc.server.load_module")
TVM_FFI_REGISTER_GLOBAL("tvm.rpc.server.load_module")
.set_body_packed([](ffi::PackedArgs args, ffi::Any* rv) {
auto name = args[0].cast<std::string>();
std::string fmt = GetFileFormat(name, "");
Expand Down Expand Up @@ -109,7 +109,7 @@ void Init(const std::string& name) {
};

// Add UnsignedDSOLoader plugin in global registry
TVM_REGISTER_GLOBAL("runtime.module.loadfile_dylib_custom")
TVM_FFI_REGISTER_GLOBAL("runtime.module.loadfile_dylib_custom")
.set_body_packed([](ffi::PackedArgs args, ffi::Any* rv) {
auto n = make_object<UnsignedDSOLoader>();
n->Init(args[0]);
Expand Down
10 changes: 5 additions & 5 deletions docs/arch/device_target_interactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ then be registered with the following steps.

#. Register the function to the tvm registry::

TVM_REGISTER_GLOBAL("device_api.foo").set_body_typed(FooDeviceAPI::Global);
TVM_FFI_REGISTER_GLOBAL("device_api.foo").set_body_typed(FooDeviceAPI::Global);

.. _c_runtime_api.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/c_runtime_api.h
.. _base.h: https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h

#. Add an entry for the new DeviceAPI to the ``TVMDeviceExtType`` enum
in `c_runtime_api.h`_. The value should be an unused value greater
in `base.h`_. The value should be an unused value greater
than ``DLDeviceType::kDLExtDev``, but less than
``DeviceAPIManager::kMaxDeviceAPI``.

#. Add a case in ``DeviceName`` in `device_api.h`_ to convert from the
enum value to a string representation. This string representation
should match the name given to ``TVM_REGISTER_GLOBAL``.
should match the name given to ``TVM_FFI_REGISTER_GLOBAL``.

#. Add entries to the ``DEVICE_TYPE_TO_NAME`` and ``DEVICE_NAME_TO_TYPE`` dictionaries of
:py:class:`tvm.runtime.Device` for the new enum value.
Expand Down Expand Up @@ -225,7 +225,7 @@ the same name as was used in the ``TVM_REGISTER_TARGET_KIND``
definition above. ::

tvm::runtime::Module GeneratorFooCode(IRModule mod, Target target);
TVM_REGISTER_GLOBAL("target.build.foo").set_body_typed(GeneratorFooCode);
TVM_FFI_REGISTER_GLOBAL("target.build.foo").set_body_typed(GeneratorFooCode);

The code generator takes two arguments. The first is the ``IRModule``
to compile, and the second is the ``Target`` that describes the device
Expand Down
2 changes: 1 addition & 1 deletion docs/arch/pass_infra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Python when needed.
return CreateFunctionPass(pass_func, 0, "FoldConstant", {});
}

TVM_REGISTER_GLOBAL("relax.transform.FoldConstant")
TVM_FFI_REGISTER_GLOBAL("relax.transform.FoldConstant")
.set_body_typed(FoldConstant);

} // namespace transform
Expand Down
8 changes: 4 additions & 4 deletions docs/arch/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ The following example registers PackedFunc in C++ and calls from python.
.. code:: c

// register a global packed function in c++
TVM_REGISTER_GLOBAL("myadd")
TVM_FFI_REGISTER_GLOBAL("myadd")
.set_body_packed(MyAdd);

.. code:: python
Expand Down Expand Up @@ -110,7 +110,7 @@ we can pass functions from python (as PackedFunc) to C++.

.. code:: c

TVM_REGISTER_GLOBAL("callhello")
TVM_FFI_REGISTER_GLOBAL("callhello")
.set_body_packed([](ffi::PackedArgs args, ffi::Any* rv) {
PackedFunc f = args[0];
f("hello world");
Expand All @@ -134,7 +134,7 @@ which allows us to embed the PackedFunc into any languages. Besides python, so f
`java`_ and `javascript`_.
This philosophy of embedded API is very like Lua, except that we don't have a new language but use C++.

.. _minimum C API: https://github.com/apache/tvm/blob/main/include/tvm/runtime/c_runtime_api.h
.. _minimum C API: https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h
.. _java: https://github.com/apache/tvm/tree/main/jvm
.. _javascript: https://github.com/apache/tvm/tree/main/web

Expand Down Expand Up @@ -282,7 +282,7 @@ Each argument in PackedFunc contains a union value `TVMValue`_
and a type code. This design allows the dynamically typed language to convert to the corresponding type directly, and statically typed language to
do runtime type checking during conversion.

.. _TVMValue: https://github.com/apache/tvm/blob/main/include/tvm/runtime/c_runtime_api.h#L135
.. _TVMValue: https://github.com/apache/tvm/blob/main/include/tvm/runtime/base.h#L135

The relevant files are

Expand Down
7 changes: 7 additions & 0 deletions ffi/include/tvm/ffi/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
#include <dlpack/dlpack.h>
#include <stdint.h>

// Macros to do weak linking
#ifdef _MSC_VER
#define TVM_FFI_WEAK __declspec(selectany)
#else
#define TVM_FFI_WEAK __attribute__((weak))
#endif

#if !defined(TVM_FFI_DLL) && defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
#define TVM_FFI_DLL EMSCRIPTEN_KEEPALIVE
Expand Down
2 changes: 1 addition & 1 deletion ffi/include/tvm/ffi/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class Function::Registry {
* .set_body_typed(multiply); // will have type int(int, int)
*
* // will have type int(int, int)
* TVM_REGISTER_GLOBAL("sub")
* TVM_FFI_REGISTER_GLOBAL("sub")
* .set_body_typed([](int a, int b) -> int { return a - b; });
*
* \endcode
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/op.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
#ifndef TVM_IR_OP_H_
#define TVM_IR_OP_H_

#include <tvm/ffi/function.h>
#include <tvm/ir/attrs.h>
#include <tvm/ir/env_func.h>
#include <tvm/ir/expr.h>
#include <tvm/ir/type.h>
#include <tvm/node/attr_registry_map.h>
#include <tvm/runtime/logging.h>
#include <tvm/runtime/registry.h>

#include <string>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/ir/source_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#ifndef TVM_IR_SOURCE_MAP_H_
#define TVM_IR_SOURCE_MAP_H_

#include <tvm/ffi/function.h>
#include <tvm/node/node.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/runtime/registry.h>

#include <fstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <tvm/node/repr_printer.h>
#include <tvm/node/structural_equal.h>
#include <tvm/node/structural_hash.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/base.h>
#include <tvm/runtime/object.h>

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/node/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <tvm/ffi/memory.h>
#include <tvm/node/structural_equal.h>
#include <tvm/node/structural_hash.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/base.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/node/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef TVM_NODE_SERIALIZATION_H_
#define TVM_NODE_SERIALIZATION_H_

#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/base.h>
#include <tvm/runtime/object.h>

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/relax/exec_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
#ifndef TVM_RELAX_EXEC_BUILDER_H_
#define TVM_RELAX_EXEC_BUILDER_H_

#include <tvm/ffi/function.h>
#include <tvm/ir/expr.h>
#include <tvm/node/reflection.h>
#include <tvm/node/repr_printer.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/registry.h>
#include <tvm/runtime/relax_vm/bytecode.h>
#include <tvm/runtime/relax_vm/executable.h>

Expand Down
2 changes: 1 addition & 1 deletion include/tvm/relax/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#ifndef TVM_RELAX_TYPE_H_
#define TVM_RELAX_TYPE_H_

#include <tvm/ffi/function.h>
#include <tvm/ir/attrs.h>
#include <tvm/ir/env_func.h>
#include <tvm/ir/type.h>
#include <tvm/runtime/registry.h>
#include <tvm/tir/expr.h>

#include <string>
Expand Down
59 changes: 59 additions & 0 deletions include/tvm/runtime/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* \file tvm/runtime/base.h
* \brief base macros
*/
#ifndef TVM_RUNTIME_BASE_H_
#define TVM_RUNTIME_BASE_H_

// TVM runtime fully relies on TVM FFI C API
// we will avoid defining extra C APIs here
#include <tvm/ffi/c_api.h>

// TVM version
#define TVM_VERSION "0.21.dev0"

// define extra macros for TVM DLL exprt
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#define TVM_DLL EMSCRIPTEN_KEEPALIVE
#endif

// helper macro to suppress unused warning
#if defined(__GNUC__)
#define TVM_ATTRIBUTE_UNUSED __attribute__((unused))
#else
#define TVM_ATTRIBUTE_UNUSED
#endif

#ifndef TVM_DLL
#ifdef _WIN32
#ifdef TVM_EXPORTS
#define TVM_DLL __declspec(dllexport)
#else
#define TVM_DLL __declspec(dllimport)
#endif
#else
#define TVM_DLL __attribute__((visibility("default")))
#endif
#endif

#endif // TVM_RUNTIME_BASE_H_
2 changes: 1 addition & 1 deletion include/tvm/runtime/builtin_fp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef TVM_RUNTIME_BUILTIN_FP16_H_
#define TVM_RUNTIME_BUILTIN_FP16_H_

#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/base.h>

#include <cstdint>

Expand Down
Loading
Loading