MCPcopy Index your code
hub / github.com/apache/tvm / NativeServerLoop

Class NativeServerLoop

jvm/core/src/main/java/org/apache/tvm/rpc/NativeServerLoop.java:29–97  ·  view source on GitHub ↗

Call native ServerLoop on socket file descriptor.

Source from the content-addressed store, hash-verified

27 * Call native ServerLoop on socket file descriptor.
28 */
29public class NativeServerLoop implements Runnable {
30 private final Function fsend;
31 private final Function frecv;
32
33 /**
34 * Constructor for NativeServerLoop.
35 * @param fsend socket.send function.
36 * @param frecv socket.recv function.
37 */
38 public NativeServerLoop(final Function fsend, final Function frecv) {
39 this.fsend = fsend;
40 this.frecv = frecv;
41 }
42
43 @Override
44 public void run() {
45 File tempDir = null;
46 try {
47 tempDir = serverEnv();
48 System.err.println("starting server loop...");
49 RPC.getApi("ServerLoop").pushArg(fsend).pushArg(frecv).invoke();
50 System.err.println("done server loop...");
51 } catch (IOException e) {
52 e.printStackTrace();
53 } finally {
54 if (tempDir != null) {
55 String[] entries = tempDir.list();
56 for (String s : entries) {
57 File currentFile = new File(tempDir.getPath(), s);
58 if (!currentFile.delete()) {
59 System.err.println(
60 "[WARN] Couldn't delete temporary file " + currentFile.getAbsolutePath());
61 }
62 }
63 if (!tempDir.delete()) {
64 System.err.println(
65 "[WARN] Couldn't delete temporary directory " + tempDir.getAbsolutePath());
66 }
67 }
68 }
69 }
70
71 private static File serverEnv() throws IOException {
72 // Server environment function return temp dir.
73 final File tempDir = File.createTempFile("tvm4j_rpc_", "");
74 if (!tempDir.delete() || !tempDir.mkdir()) {
75 throw new IOException("Couldn't create directory " + tempDir.getAbsolutePath());
76 }
77
78 Function.register("tvm.rpc.server.workpath", new Function.Callback() {
79 @Override
80 public Object invoke(TVMValue... args) {
81 return tempDir + File.separator + args[0].asString();
82 }
83 }, true);
84
85 Function.register("tvm.rpc.server.load_module", new Function.Callback() {
86 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…