Skip to content

Commit 12df4fe

Browse files
committed
[CPP_RPC] export listdir for RPC
1 parent 6c33787 commit 12df4fe

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

apps/cpp_rpc/rpc_env.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ namespace runtime {
7272
*/
7373
void CleanDir(const std::string& dirname);
7474

75+
/*!
76+
* \brief ListDir get the list of files in a directory
77+
* \param dirname The root directory name
78+
* \return vector Files in directory.
79+
*/
80+
std::vector<std::string> ListDir(const std::string& dirname);
81+
7582
/*!
7683
* \brief buld a shared library if necessary
7784
*
@@ -123,6 +130,15 @@ RPCEnv::RPCEnv(const std::string& wd) {
123130
*rv = this->GetPath(args[0]);
124131
});
125132

133+
TVM_REGISTER_GLOBAL("tvm.rpc.server.listdir").set_body([this](TVMArgs args, TVMRetValue* rv) {
134+
std::string dir = this->GetPath(args[0]);
135+
std::ostringstream os;
136+
for (auto d : ListDir(dir)) {
137+
os << d << ",";
138+
}
139+
*rv = os.str();
140+
});
141+
126142
TVM_REGISTER_GLOBAL("tvm.rpc.server.load_module").set_body([this](TVMArgs args, TVMRetValue* rv) {
127143
std::string file_name = this->GetPath(args[0]);
128144
file_name = BuildSharedLibrary(file_name);

python/tvm/rpc/client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ def remove(self, path):
145145
self._remote_funcs["remove"] = self.get_function("tvm.rpc.server.remove")
146146
self._remote_funcs["remove"](path)
147147

148+
def listdir(self, path):
149+
"""ls files from remote temp folder.
150+
151+
Parameters
152+
----------
153+
path: str
154+
The relative location to remote temp folder.
155+
156+
Returns
157+
-------
158+
dirs: str
159+
The files in the given directory with split token ','.
160+
"""
161+
if "listdir" not in self._remote_funcs:
162+
self._remote_funcs["listdir"] = self.get_function("tvm.rpc.server.listdir")
163+
return self._remote_funcs["listdir"](path)
164+
148165
def load_module(self, path):
149166
"""Load a remote module, the file need to be uploaded first.
150167

0 commit comments

Comments
 (0)