Skip to content

Commit a8043b8

Browse files
committed
[REFACTOR][FFI] Phase out legacy C API
This PR phases out the legacy c api in favor of the new FFI C API. Also removes the redirection sccafolding for registry.h - include <tvm/runtime/registry.h> => include <tvm/ffi/function.h> - include <tvm/runtime/c_runtime_api.h> => include <tvm/runtime/base.h> - TVM_REGISTER_GLOBAL => TVM_FFI_REGISTER_GLOBAL The cleanup will greatly simplify the overall FFI surface of the project and allows us to move towards an unified clean API based on tvm ffi.
1 parent ada7c7c commit a8043b8

File tree

625 files changed

+3211
-5383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

625 files changed

+3211
-5383
lines changed

apps/android_rpc/app/src/main/jni/tvm_runtime.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
#include "../ffi/src/ffi/object.cc"
4343
#include "../ffi/src/ffi/testing.cc"
4444
#include "../ffi/src/ffi/traceback.cc"
45-
#include "../src/runtime/c_runtime_api.cc"
46-
#include "../src/runtime/container.cc"
4745
#include "../src/runtime/cpu_device_api.cc"
46+
#include "../src/runtime/device_api.cc"
4847
#include "../src/runtime/dso_library.cc"
4948
#include "../src/runtime/file_utils.cc"
5049
#include "../src/runtime/library_module.cc"
@@ -53,7 +52,6 @@
5352
#include "../src/runtime/minrpc/minrpc_logger.cc"
5453
#include "../src/runtime/module.cc"
5554
#include "../src/runtime/ndarray.cc"
56-
#include "../src/runtime/object.cc"
5755
#include "../src/runtime/profiling.cc"
5856
#include "../src/runtime/registry.cc"
5957
#include "../src/runtime/rpc/rpc_channel.cc"

apps/cpp_rpc/rpc_env.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
* \file rpc_env.cc
2121
* \brief Server environment of the RPC.
2222
*/
23-
#include <tvm/runtime/registry.h>
23+
#include <tvm/ffi/function.h>
24+
#include <tvm/runtime/logging.h>
25+
#include <tvm/runtime/module.h>
2426

2527
#include <cerrno>
2628
#ifndef _WIN32

apps/cpp_rpc/rpc_env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#ifndef TVM_APPS_CPP_RPC_ENV_H_
2525
#define TVM_APPS_CPP_RPC_ENV_H_
2626

27-
#include <tvm/runtime/registry.h>
27+
#include <tvm/ffi/function.h>
2828

2929
#include <string>
3030

apps/cpp_rpc/rpc_server.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* \file rpc_server.cc
2222
* \brief RPC Server implementation.
2323
*/
24-
#include <tvm/runtime/registry.h>
24+
#include <tvm/ffi/function.h>
2525
#if defined(__linux__) || defined(__ANDROID__) || defined(__APPLE__)
2626
#include <signal.h>
2727
#include <sys/select.h>
@@ -398,6 +398,6 @@ void RPCServerCreate(std::string host, int port, int port_end, std::string track
398398
rpc.Start();
399399
}
400400

401-
TVM_REGISTER_GLOBAL("rpc.ServerCreate").set_body_typed(RPCServerCreate);
401+
TVM_FFI_REGISTER_GLOBAL("rpc.ServerCreate").set_body_typed(RPCServerCreate);
402402
} // namespace runtime
403403
} // namespace tvm

apps/cpp_rpc/rpc_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include <string>
2828

29-
#include "tvm/runtime/c_runtime_api.h"
29+
#include "tvm/runtime/base.h"
3030

3131
namespace tvm {
3232
namespace runtime {

apps/hexagon_launcher/launcher_core.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
#include "launcher_core.h"
2121

22+
#include <tvm/ffi/function.h>
2223
#include <tvm/runtime/c_backend_api.h>
2324
#include <tvm/runtime/packed_func.h>
24-
#include <tvm/runtime/registry.h>
2525

2626
#include <fstream>
2727
#include <ios>

apps/ios_rpc/tvmrpc/RPCServer.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
#import "RPCServer.h"
2525

26+
#include <tvm/ffi/function.h>
2627
#include <tvm/runtime/packed_func.h>
27-
#include <tvm/runtime/registry.h>
2828

2929
#include <random>
3030
#include <string>

apps/ios_rpc/tvmrpc/TVMRuntime.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#import <Foundation/Foundation.h>
2525

26-
#include <tvm/runtime/registry.h>
26+
#include <tvm/ffi/function.h>
2727

2828
#include "RPCArgs.h"
2929

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

5252
} // namespace detail
5353

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

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

111111
// Add UnsignedDSOLoader plugin in global registry
112-
TVM_REGISTER_GLOBAL("runtime.module.loadfile_dylib_custom")
112+
TVM_FFI_REGISTER_GLOBAL("runtime.module.loadfile_dylib_custom")
113113
.set_body_packed([](ffi::PackedArgs args, ffi::Any* rv) {
114114
auto n = make_object<UnsignedDSOLoader>();
115115
n->Init(args[0]);

docs/arch/device_target_interactions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ then be registered with the following steps.
153153

154154
#. Register the function to the tvm registry::
155155

156-
TVM_REGISTER_GLOBAL("device_api.foo").set_body_typed(FooDeviceAPI::Global);
156+
TVM_FFI_REGISTER_GLOBAL("device_api.foo").set_body_typed(FooDeviceAPI::Global);
157157

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

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

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

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

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

230230
The code generator takes two arguments. The first is the ``IRModule``
231231
to compile, and the second is the ``Target`` that describes the device

0 commit comments

Comments
 (0)