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
15 changes: 0 additions & 15 deletions include/tvm/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,6 @@ TVM_DLL int TVMModGetFunction(TVMModuleHandle mod,
int query_imports,
TVMFunctionHandle *out);

/*!
* \brief Precompile the function under given context.
* Many TVMFunctionHandle is initialized lazily,
* This call eagerly prepares the resources under given context.
* Useful for benchmarking purposes.
*
* \param mod The module handle.
* \param func_name The name of the function.
* \param ctx The context to be precompiled on.
* \return 0 when no error is thrown, -1 when failure happens
*/
TVM_DLL int TVMModPreCompile(TVMModuleHandle mod,
const char* func_name,
TVMContext ctx);

/*!
* \brief Free the Module
* \param mod The module to be freed.
Expand Down
18 changes: 3 additions & 15 deletions include/tvm/runtime/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ class ModuleNode {
virtual ~ModuleNode() {}
/*! \return The module type key */
virtual const char* type_key() const = 0;
/*!
* \brief Eagerly compile the function under certain context,
* assuming that it is used by the current thread.
*
* This is useful for benchmarking to eliminate lazy compilation
* overhead during the first execution of the kernel.
*
* \param name The name of the function.
* \param ctx The context to be executed.
*/
virtual void PreCompile(const std::string& name, TVMContext ctx) = 0;
/*!
* \brief Get a PackedFunc from module.
*
Expand All @@ -113,22 +102,21 @@ class ModuleNode {
* \param format The format of the file.
*/
virtual void SaveToFile(const std::string& file_name,
const std::string& format) = 0;
const std::string& format);
/*!
* \brief Save the module to binary stream.
* \param stream The binary stream to save to.
* \note It is recommended to implement this for device modules,
* but not necessarily host modules.
* We can use this to do AOT loading of bundled device functions.
*/
virtual void SaveToBinary(dmlc::Stream* stream) = 0;
virtual void SaveToBinary(dmlc::Stream* stream);
/*!
* \brief Get the source code of module, when available.
* \param format Format of the source code, can be empty by default.
* \return Possible source code when available.
*/
virtual std::string GetSource(
const std::string& format = "") = 0;
virtual std::string GetSource(const std::string& format = "");
/*!
* \brief Get a function from current environment
* The environment includes all the imports as well as Global functions.
Expand Down
14 changes: 0 additions & 14 deletions python/tvm/_ffi/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ def import_module(self, module):
"""
check_call(_LIB.TVMModImport(self.handle, module.handle))

def precompile(self, func_name, ctx):
"""Add module to the import list of current one.

Parameters
----------
func_name : str
The name of function to be precompiled.

ctx : Context
The context to be precompiled.
"""
check_call(_LIB.TVMModPreCompile(
self.handle, c_str(func_name), ctx))

def __getitem__(self, name):
if not isinstance(name, string_types):
raise ValueError("Can only take string as function name")
Expand Down
11 changes: 0 additions & 11 deletions src/codegen/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ class LLVMModuleNode final : public runtime::ModuleNode {
return "llvm";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
if (ee_ == nullptr) LazyInitJIT();
std::lock_guard<std::mutex> lock(mutex_);
const std::string& fname = (name == runtime::symbol::tvm_module_main ?
entry_func_ : name);
BackendPackedCFunc faddr =
reinterpret_cast<BackendPackedCFunc>(ee_->getFunctionAddress(fname));
CHECK(faddr != nullptr)
<< "Failed to Precompile function " << name;
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
Expand Down
11 changes: 0 additions & 11 deletions src/codegen/source_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class SourceModuleNode final : public runtime::ModuleNode {
const char* type_key() const {
return "source";
}
void PreCompile(const std::string& name, TVMContext ctx) final {
}
PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
Expand All @@ -31,15 +29,6 @@ class SourceModuleNode final : public runtime::ModuleNode {
return PackedFunc();
}

void SaveToFile(const std::string& file_name,
const std::string& format) final {
LOG(FATAL) << "SourceModule: SaveToFile not supported";
}

void SaveToBinary(dmlc::Stream* stream) final {
LOG(FATAL) << "SourceModule: SaveToBinary not supported";
}

std::string GetSource(const std::string& format) final {
return code_;
}
Expand Down
11 changes: 0 additions & 11 deletions src/codegen/stack_vm/stack_vm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class StackVMModuleNode : public runtime::ModuleNode {
return "stackvm";
}

void PreCompile(const std::string& name, TVMContext ctx) final {}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
Expand All @@ -33,15 +31,6 @@ class StackVMModuleNode : public runtime::ModuleNode {
});
}

void SaveToFile(const std::string& file_name,
const std::string& format) final {
LOG(FATAL) << "StackVMModule: SaveToFile not supported";
}

void SaveToBinary(dmlc::Stream* stream) final {
LOG(FATAL) << "StackVMModule: SaveToBinary not supported";
}

std::string GetSource(const std::string& format) final {
std::ostringstream os;
for (const auto& kv : fmap_) {
Expand Down
11 changes: 0 additions & 11 deletions src/codegen/verilog/verilog_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class VerilogModuleNode : public runtime::ModuleNode {
const char* type_key() const {
return "verilog";
}
void PreCompile(const std::string& name, TVMContext ctx) final {
}

PackedFunc GetFunction(
const std::string& name,
Expand Down Expand Up @@ -57,15 +55,6 @@ class VerilogModuleNode : public runtime::ModuleNode {
return PackedFunc(f);
}

void SaveToFile(const std::string& file_name,
const std::string& format) final {
LOG(FATAL) << "VerilogModule: SaveToFile not supported";
}

void SaveToBinary(dmlc::Stream* stream) final {
LOG(FATAL) << "VerilogModule: SaveToBinary not supported";
}

std::string GetSource(const std::string& format) final {
return m_.code;
}
Expand Down
8 changes: 0 additions & 8 deletions src/runtime/c_runtime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,6 @@ int TVMModGetFunction(TVMModuleHandle mod,
API_END();
}

int TVMModPreCompile(TVMModuleHandle mod,
const char* func_name,
TVMContext ctx) {
API_BEGIN();
(*static_cast<Module*>(mod))->PreCompile(func_name, ctx);
API_END();
}

int TVMModFree(TVMModuleHandle mod) {
API_BEGIN();
delete static_cast<Module*>(mod);
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/cuda/cuda_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class CUDAModuleNode : public runtime::ModuleNode {
return "cuda";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
CUDA_CALL(cudaSetDevice(ctx.device_id));
cudaFree(nullptr);
this->GetFunc(ctx.device_id, name);
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final;
Expand Down
17 changes: 0 additions & 17 deletions src/runtime/dso_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class DSOModuleNode final : public ModuleNode {
return "dso";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
GetFuncPtr(name);
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
Expand All @@ -48,19 +44,6 @@ class DSOModuleNode final : public ModuleNode {
});
}

void SaveToFile(const std::string& file_name,
const std::string& format) final {
LOG(FATAL) << "DSOModule: SaveToFile not supported";
}

void SaveToBinary(dmlc::Stream* stream) final {
LOG(FATAL) << "DSOModule: SaveToBinary not supported";
}

std::string GetSource(const std::string& format) final {
return "";
}

void Init(const std::string& name) {
Load(name);
CHECK(lib_handle_ != nullptr)
Expand Down
4 changes: 0 additions & 4 deletions src/runtime/metal/metal_module.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ explicit MetalModuleNode(std::string data,
return "metal";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
GetPipelineState(ctx.device_id, name);
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final;
Expand Down
14 changes: 14 additions & 0 deletions src/runtime/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ Module Module::LoadFromFile(const std::string& file_name,
return m;
}

void ModuleNode::SaveToFile(const std::string& file_name,
const std::string& format) {
LOG(FATAL) << "Module[" << type_key() << "] does not support SaveToFile";
}

void ModuleNode::SaveToBinary(dmlc::Stream* stream) {
LOG(FATAL) << "Module[" << type_key() << "] does not support SaveToBinary";
}

std::string ModuleNode::GetSource(const std::string& format) {
LOG(FATAL) << "Module[" << type_key() << "] does not support GetSource";
return "";
}

const PackedFunc* ModuleNode::GetFuncFromEnv(const std::string& name) {
auto it = import_cache_.find(name);
if (it != import_cache_.end()) return it->second.get();
Expand Down
6 changes: 0 additions & 6 deletions src/runtime/opencl/opencl_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ class OpenCLModuleNode : public ModuleNode {
return "opencl";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
InstallKernel(cl::OpenCLWorkspace::Global(),
cl::OpenCLThreadEntry::ThreadLocal(),
name, kid_map_.at(name));
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final;
Expand Down
12 changes: 0 additions & 12 deletions src/runtime/rpc/rpc_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,13 @@ class RPCModuleNode final : public ModuleNode {
return "rpc";
}

void PreCompile(const std::string& name, TVMContext ctx) final {
}

PackedFunc GetFunction(
const std::string& name,
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
RPCFuncHandle handle = GetFuncHandle(name);
return WrapRemote(handle);
}

void SaveToFile(const std::string& file_name,
const std::string& format) final {
LOG(FATAL) << "RPCModule: SaveToFile not supported";
}

void SaveToBinary(dmlc::Stream* stream) final {
LOG(FATAL) << "RPCModule: SaveToBinary not supported";
}

std::string GetSource(const std::string& format) final {
if (module_handle_ != nullptr) {
std::string ret = sess_->CallRemote(
Expand Down