Skip to content

Commit ef50162

Browse files
authored
[MODULE/RUNTIME] Remove Precompile, simplify module (#174)
1 parent 84aeaf4 commit ef50162

File tree

15 files changed

+18
-142
lines changed

15 files changed

+18
-142
lines changed

include/tvm/runtime/c_runtime_api.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,6 @@ TVM_DLL int TVMModGetFunction(TVMModuleHandle mod,
182182
int query_imports,
183183
TVMFunctionHandle *out);
184184

185-
/*!
186-
* \brief Precompile the function under given context.
187-
* Many TVMFunctionHandle is initialized lazily,
188-
* This call eagerly prepares the resources under given context.
189-
* Useful for benchmarking purposes.
190-
*
191-
* \param mod The module handle.
192-
* \param func_name The name of the function.
193-
* \param ctx The context to be precompiled on.
194-
* \return 0 when no error is thrown, -1 when failure happens
195-
*/
196-
TVM_DLL int TVMModPreCompile(TVMModuleHandle mod,
197-
const char* func_name,
198-
TVMContext ctx);
199-
200185
/*!
201186
* \brief Free the Module
202187
* \param mod The module to be freed.

include/tvm/runtime/module.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ class ModuleNode {
7676
virtual ~ModuleNode() {}
7777
/*! \return The module type key */
7878
virtual const char* type_key() const = 0;
79-
/*!
80-
* \brief Eagerly compile the function under certain context,
81-
* assuming that it is used by the current thread.
82-
*
83-
* This is useful for benchmarking to eliminate lazy compilation
84-
* overhead during the first execution of the kernel.
85-
*
86-
* \param name The name of the function.
87-
* \param ctx The context to be executed.
88-
*/
89-
virtual void PreCompile(const std::string& name, TVMContext ctx) = 0;
9079
/*!
9180
* \brief Get a PackedFunc from module.
9281
*
@@ -113,22 +102,21 @@ class ModuleNode {
113102
* \param format The format of the file.
114103
*/
115104
virtual void SaveToFile(const std::string& file_name,
116-
const std::string& format) = 0;
105+
const std::string& format);
117106
/*!
118107
* \brief Save the module to binary stream.
119108
* \param stream The binary stream to save to.
120109
* \note It is recommended to implement this for device modules,
121110
* but not necessarily host modules.
122111
* We can use this to do AOT loading of bundled device functions.
123112
*/
124-
virtual void SaveToBinary(dmlc::Stream* stream) = 0;
113+
virtual void SaveToBinary(dmlc::Stream* stream);
125114
/*!
126115
* \brief Get the source code of module, when available.
127116
* \param format Format of the source code, can be empty by default.
128117
* \return Possible source code when available.
129118
*/
130-
virtual std::string GetSource(
131-
const std::string& format = "") = 0;
119+
virtual std::string GetSource(const std::string& format = "");
132120
/*!
133121
* \brief Get a function from current environment
134122
* The environment includes all the imports as well as Global functions.

python/tvm/_ffi/function.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,6 @@ def import_module(self, module):
116116
"""
117117
check_call(_LIB.TVMModImport(self.handle, module.handle))
118118

119-
def precompile(self, func_name, ctx):
120-
"""Add module to the import list of current one.
121-
122-
Parameters
123-
----------
124-
func_name : str
125-
The name of function to be precompiled.
126-
127-
ctx : Context
128-
The context to be precompiled.
129-
"""
130-
check_call(_LIB.TVMModPreCompile(
131-
self.handle, c_str(func_name), ctx))
132-
133119
def __getitem__(self, name):
134120
if not isinstance(name, string_types):
135121
raise ValueError("Can only take string as function name")

src/codegen/llvm/llvm_module.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ class LLVMModuleNode final : public runtime::ModuleNode {
3333
return "llvm";
3434
}
3535

36-
void PreCompile(const std::string& name, TVMContext ctx) final {
37-
if (ee_ == nullptr) LazyInitJIT();
38-
std::lock_guard<std::mutex> lock(mutex_);
39-
const std::string& fname = (name == runtime::symbol::tvm_module_main ?
40-
entry_func_ : name);
41-
BackendPackedCFunc faddr =
42-
reinterpret_cast<BackendPackedCFunc>(ee_->getFunctionAddress(fname));
43-
CHECK(faddr != nullptr)
44-
<< "Failed to Precompile function " << name;
45-
}
46-
4736
PackedFunc GetFunction(
4837
const std::string& name,
4938
const std::shared_ptr<ModuleNode>& sptr_to_self) final {

src/codegen/source_module.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class SourceModuleNode final : public runtime::ModuleNode {
2121
const char* type_key() const {
2222
return "source";
2323
}
24-
void PreCompile(const std::string& name, TVMContext ctx) final {
25-
}
2624
PackedFunc GetFunction(
2725
const std::string& name,
2826
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
@@ -31,15 +29,6 @@ class SourceModuleNode final : public runtime::ModuleNode {
3129
return PackedFunc();
3230
}
3331

34-
void SaveToFile(const std::string& file_name,
35-
const std::string& format) final {
36-
LOG(FATAL) << "SourceModule: SaveToFile not supported";
37-
}
38-
39-
void SaveToBinary(dmlc::Stream* stream) final {
40-
LOG(FATAL) << "SourceModule: SaveToBinary not supported";
41-
}
42-
4332
std::string GetSource(const std::string& format) final {
4433
return code_;
4534
}

src/codegen/stack_vm/stack_vm_module.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class StackVMModuleNode : public runtime::ModuleNode {
1616
return "stackvm";
1717
}
1818

19-
void PreCompile(const std::string& name, TVMContext ctx) final {}
20-
2119
PackedFunc GetFunction(
2220
const std::string& name,
2321
const std::shared_ptr<ModuleNode>& sptr_to_self) final {
@@ -33,15 +31,6 @@ class StackVMModuleNode : public runtime::ModuleNode {
3331
});
3432
}
3533

36-
void SaveToFile(const std::string& file_name,
37-
const std::string& format) final {
38-
LOG(FATAL) << "StackVMModule: SaveToFile not supported";
39-
}
40-
41-
void SaveToBinary(dmlc::Stream* stream) final {
42-
LOG(FATAL) << "StackVMModule: SaveToBinary not supported";
43-
}
44-
4534
std::string GetSource(const std::string& format) final {
4635
std::ostringstream os;
4736
for (const auto& kv : fmap_) {

src/codegen/verilog/verilog_module.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class VerilogModuleNode : public runtime::ModuleNode {
2424
const char* type_key() const {
2525
return "verilog";
2626
}
27-
void PreCompile(const std::string& name, TVMContext ctx) final {
28-
}
2927

3028
PackedFunc GetFunction(
3129
const std::string& name,
@@ -57,15 +55,6 @@ class VerilogModuleNode : public runtime::ModuleNode {
5755
return PackedFunc(f);
5856
}
5957

60-
void SaveToFile(const std::string& file_name,
61-
const std::string& format) final {
62-
LOG(FATAL) << "VerilogModule: SaveToFile not supported";
63-
}
64-
65-
void SaveToBinary(dmlc::Stream* stream) final {
66-
LOG(FATAL) << "VerilogModule: SaveToBinary not supported";
67-
}
68-
6958
std::string GetSource(const std::string& format) final {
7059
return m_.code;
7160
}

src/runtime/c_runtime_api.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,6 @@ int TVMModGetFunction(TVMModuleHandle mod,
196196
API_END();
197197
}
198198

199-
int TVMModPreCompile(TVMModuleHandle mod,
200-
const char* func_name,
201-
TVMContext ctx) {
202-
API_BEGIN();
203-
(*static_cast<Module*>(mod))->PreCompile(func_name, ctx);
204-
API_END();
205-
}
206-
207199
int TVMModFree(TVMModuleHandle mod) {
208200
API_BEGIN();
209201
delete static_cast<Module*>(mod);

src/runtime/cuda/cuda_module.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ class CUDAModuleNode : public runtime::ModuleNode {
4949
return "cuda";
5050
}
5151

52-
void PreCompile(const std::string& name, TVMContext ctx) final {
53-
CUDA_CALL(cudaSetDevice(ctx.device_id));
54-
cudaFree(nullptr);
55-
this->GetFunc(ctx.device_id, name);
56-
}
57-
5852
PackedFunc GetFunction(
5953
const std::string& name,
6054
const std::shared_ptr<ModuleNode>& sptr_to_self) final;

0 commit comments

Comments
 (0)