diff --git a/python/tvm/autotvm/measure/measure_methods.py b/python/tvm/autotvm/measure/measure_methods.py index 802abe019013351256b4298cfb72803a887255e2..ff93704edb442bdce2588360b6f8fea252ebd421 100644 --- a/python/tvm/autotvm/measure/measure_methods.py +++ b/python/tvm/autotvm/measure/measure_methods.py @@ -467,6 +467,12 @@ def run_through_rpc(measure_input, build_result, ctx.sync() costs = time_f(*args).results + + # clean up remote files + remote.remove(build_result.filename) + remote.remove(os.path.splitext(build_result.filename)[0] + '.so') + remote.remove('') + if len(costs) > 2: # remove largest and smallest value to reduce variance costs = list(costs) costs.sort() diff --git a/python/tvm/rpc/client.py b/python/tvm/rpc/client.py index ae44e5a799339a02e7dc1deda165bdc6611d3775..c975ec64aa7607a727ec2c99386d14d1849c2fe0 100644 --- a/python/tvm/rpc/client.py +++ b/python/tvm/rpc/client.py @@ -103,6 +103,19 @@ class RPCSession(object): "tvm.rpc.server.download") return self._remote_funcs["download"](path) + def remove(self, path): + """Remove file from remote temp folder. + + Parameters + ---------- + path: str + The relative location to remote temp folder. + """ + if "remove" not in self._remote_funcs: + self._remote_funcs["remove"] = self.get_function( + "tvm.rpc.server.remove") + self._remote_funcs["remove"](path) + def load_module(self, path): """Load a remote module, the file need to be uploaded first. diff --git a/src/runtime/file_util.cc b/src/runtime/file_util.cc index 4df335a54f25a6408443ac6e9944869db03a7315..ff579d12112d1275f358e3a5c04b20b64b55d579 100644 --- a/src/runtime/file_util.cc +++ b/src/runtime/file_util.cc @@ -142,5 +142,9 @@ void LoadMetaDataFromFile( fs.close(); } +void RemoveFile(const std::string& file_name) { + std::remove(file_name.c_str()); +} + } // namespace runtime } // namespace tvm diff --git a/src/runtime/file_util.h b/src/runtime/file_util.h index de520fa3158c5363753b48f3b8cc509380eda20c..2b797614281be2ea0d57489f37edc3165957a44a 100644 --- a/src/runtime/file_util.h +++ b/src/runtime/file_util.h @@ -71,6 +71,12 @@ void SaveMetaDataToFile( void LoadMetaDataFromFile( const std::string& file_name, std::unordered_map<std::string, FunctionInfo>* fmap); + +/*! + * \brief Remove (unlink) a file. + * \param file_name The file name. + */ +void RemoveFile(const std::string& file_name); } // namespace runtime } // namespace tvm #endif // TVM_RUNTIME_FILE_UTIL_H_ diff --git a/src/runtime/rpc/rpc_server_env.cc b/src/runtime/rpc/rpc_server_env.cc index ca91b88247e5332662de1ef270143e1892794130..fb8d95d60b95fbd7b95076ea229d0ea3125edfb6 100644 --- a/src/runtime/rpc/rpc_server_env.cc +++ b/src/runtime/rpc/rpc_server_env.cc @@ -35,5 +35,12 @@ TVM_REGISTER_GLOBAL("tvm.rpc.server.download") *rv = arr; }); +TVM_REGISTER_GLOBAL("tvm.rpc.server.remove") +.set_body([](TVMArgs args, TVMRetValue *rv) { + std::string file_name = RPCGetPath(args[0]); + LOG(INFO) << "Remove " << file_name; + RemoveFile(file_name); + }); + } // namespace runtime } // namespace tvm