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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 3rdparty/cutlass_fpA_intB_gemm
1 change: 0 additions & 1 deletion apps/hexagon_launcher/launcher_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

#include <fstream>
#include <ios>
Expand Down
2 changes: 1 addition & 1 deletion apps/hexagon_launcher/launcher_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include <dlpack/dlpack.h>
#include <dmlc/json.h>
#include <tvm/ffi/function.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/module.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/packed_func.h>

#include <string>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion apps/ios_rpc/tvmrpc/RPCServer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#import "RPCServer.h"

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

#include <random>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion docs/arch/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The following code block provides an example in C++

.. code:: c

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

void MyAdd(ffi::PackedArgs args, ffi::Any* rv) {
// automatically convert arguments to desired type.
Expand Down
6 changes: 6 additions & 0 deletions ffi/include/tvm/ffi/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,5 +583,11 @@ struct AnyEqual {
};

} // namespace ffi

// Expose to the tvm namespace for usability
// Rationale: no ambiguity even in root
using tvm::ffi::Any;
using tvm::ffi::AnyView;

} // namespace tvm
#endif // TVM_FFI_ANY_H_
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 @@ -34,19 +34,26 @@
#define TVM_FFI_WEAK __attribute__((weak))
#endif

// Defines two macros
// TVM_FFI_DLL: marks the function as a DLL export/import
// depending on whether TVM_FFI_EXPORTS is defined
// TVM_FFI_DLL_EXPORT: always marks the function as a DLL export
#if !defined(TVM_FFI_DLL) && defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
#define TVM_FFI_DLL EMSCRIPTEN_KEEPALIVE
#define TVM_FFI_DLL_EXPORT EMSCRIPTEN_KEEPALIVE
#endif
#if !defined(TVM_FFI_DLL) && defined(_MSC_VER)
#ifdef TVM_FFI_EXPORTS
#define TVM_FFI_DLL __declspec(dllexport)
#else
#define TVM_FFI_DLL __declspec(dllimport)
#endif
#define TVM_FFI_DLL_EXPORT __declspec(dllexport)
#endif
#ifndef TVM_FFI_DLL
#define TVM_FFI_DLL __attribute__((visibility("default")))
#define TVM_FFI_DLL_EXPORT __attribute__((visibility("default")))
#endif

#ifdef __cplusplus
Expand Down
48 changes: 48 additions & 0 deletions ffi/include/tvm/ffi/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,54 @@ inline int32_t TypeKeyToIndex(std::string_view type_key) {
#define TVM_FFI_REGISTER_GLOBAL(OpName) \
TVM_FFI_STR_CONCAT(TVM_FFI_FUNC_REG_VAR_DEF, __COUNTER__) = ::tvm::ffi::Function::Registry(OpName)

/*!
* \brief Export typed function as a SafeCallType symbol.
*
* \param ExportName The symbol name to be exported.
* \param Function The typed function.
* \note ExportName and Function must be different,
* see code examples below.
*
* \sa ffi::TypedFunction
*
* \code
*
* int AddOne_(int x) {
* return x + 1;
* }
*
* // Expose the function as "AddOne"
* TVM_FFI_DLL_EXPORT_TYPED_FUNC(AddOne, AddOne_);
*
* // Expose the function as "SubOne"
* TVM_FFI_DLL_EXPORT_TYPED_FUNC(SubOne, [](int x) {
* return x - 1;
* });
*
* // The following code will cause compilation error.
* // Because the same Function and ExportName
* // TVM_FFI_DLL_EXPORT_TYPED_FUNC(AddOne_, AddOne_);
*
* // The following code is OK, assuming the macro
* // is in a different namespace from xyz
* // TVM_FFI_DLL_EXPORT_TYPED_FUNC(AddOne_, xyz::AddOne_);
*
* \endcode
*/
#define TVM_FFI_DLL_EXPORT_TYPED_FUNC(ExportName, Function) \
extern "C" { \
TVM_FFI_DLL_EXPORT int ExportName(void* self, TVMFFIAny* args, int32_t num_args, \
TVMFFIAny* result) { \
TVM_FFI_SAFE_CALL_BEGIN(); \
using FuncInfo = ::tvm::ffi::details::FunctionInfo<decltype(Function)>; \
static std::string name = #ExportName; \
::tvm::ffi::details::unpack_call<typename FuncInfo::RetType>( \
std::make_index_sequence<FuncInfo::num_args>{}, &name, Function, \
reinterpret_cast<const ::tvm::ffi::AnyView*>(args), num_args, \
reinterpret_cast<::tvm::ffi::Any*>(result)); \
TVM_FFI_SAFE_CALL_END(); \
} \
}
} // namespace ffi
} // namespace tvm
#endif // TVM_FFI_FUNCTION_H_
2 changes: 1 addition & 1 deletion include/tvm/ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@

#include <dmlc/common.h>
#include <tvm/ffi/container/map.h>
#include <tvm/ffi/function.h>
#include <tvm/ir/expr.h>
#include <tvm/node/structural_equal.h>
#include <tvm/node/structural_hash.h>
#include <tvm/runtime/packed_func.h>

#include <functional>
#include <string>
Expand Down
6 changes: 3 additions & 3 deletions include/tvm/ir/env_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#ifndef TVM_IR_ENV_FUNC_H_
#define TVM_IR_ENV_FUNC_H_

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

#include <string>
#include <utility>
Expand Down Expand Up @@ -142,8 +142,8 @@ class TypedEnvFunc<R(Args...)> : public ObjectRef {
if constexpr (std::is_same_v<R, void>) {
n->func(std::forward<Args>(args)...);
} else {
Any res = n->func(std::forward<Args>(args)...);
if constexpr (std::is_same_v<R, Any>) {
ffi::Any res = n->func(std::forward<Args>(args)...);
if constexpr (std::is_same_v<R, ffi::Any>) {
return res;
} else {
return std::move(res).cast<R>();
Expand Down
1 change: 0 additions & 1 deletion include/tvm/ir/source_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <tvm/ffi/function.h>
#include <tvm/node/node.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>

#include <fstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/module.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>

namespace tvm {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/cost_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#define TVM_META_SCHEDULE_COST_MODEL_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/string.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/meta_schedule/measure_candidate.h>
#include <tvm/meta_schedule/runner.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/tir/schedule/schedule.h>

#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#define TVM_META_SCHEDULE_DATABASE_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/expr.h>
#include <tvm/ir/module.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>
#include <tvm/tir/schedule/schedule.h>
#include <tvm/tir/schedule/trace.h>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/feature_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#define TVM_META_SCHEDULE_FEATURE_EXTRACTOR_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/string.h>
#include <tvm/meta_schedule/measure_candidate.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>

namespace tvm {
namespace meta_schedule {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/measure_callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define TVM_META_SCHEDULE_MEASURE_CALLBACK_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/string.h>
#include <tvm/meta_schedule/builder.h>
#include <tvm/meta_schedule/measure_candidate.h>
Expand All @@ -29,7 +30,6 @@
#include <tvm/meta_schedule/tune_context.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>

namespace tvm {
namespace meta_schedule {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/mutator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#ifndef TVM_META_SCHEDULE_MUTATOR_H_
#define TVM_META_SCHEDULE_MUTATOR_H_

#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/support/random_engine.h>
#include <tvm/tir/schedule/schedule.h>
#include <tvm/tir/schedule/trace.h>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/postproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#ifndef TVM_META_SCHEDULE_POSTPROC_H_
#define TVM_META_SCHEDULE_POSTPROC_H_

#include <tvm/ffi/function.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/tir/schedule/schedule.h>

namespace tvm {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#define TVM_META_SCHEDULE_PROFILER_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/module.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#define TVM_META_SCHEDULE_RUNNER_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/expr.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>

namespace tvm {
namespace meta_schedule {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/schedule_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/expr.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/tir/schedule/schedule.h>

namespace tvm {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/search_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define TVM_META_SCHEDULE_SEARCH_STRATEGY_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/meta_schedule/arg_info.h>
#include <tvm/meta_schedule/cost_model.h>
Expand All @@ -28,7 +29,6 @@
#include <tvm/meta_schedule/runner.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/tir/schedule/schedule.h>

namespace tvm {
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/space_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#define TVM_META_SCHEDULE_SPACE_GENERATOR_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ir/module.h>
#include <tvm/meta_schedule/mutator.h>
#include <tvm/meta_schedule/postproc.h>
#include <tvm/meta_schedule/schedule_rule.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/target/target.h>
#include <tvm/tir/schedule/schedule.h>

Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/task_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define TVM_META_SCHEDULE_TASK_SCHEDULER_H_

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/meta_schedule/builder.h>
#include <tvm/meta_schedule/cost_model.h>
Expand All @@ -28,7 +29,6 @@
#include <tvm/meta_schedule/tune_context.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/support/random_engine.h>

#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/tvm/meta_schedule/tune_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/expr.h>
Expand All @@ -31,7 +32,6 @@
#include <tvm/meta_schedule/space_generator.h>
#include <tvm/node/reflection.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <tvm/support/random_engine.h>
#include <tvm/target/target.h>

Expand Down
Loading
Loading