Some questions about Windows

I recently spent two weeks debugging in the Windwos environment and found some problems about AutoTVM.

My env: windows10 intel-CPU ; TVM 0.7dev; python 3.6; LLVM 9.0;

1.On windows, 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown, or non-applicable target (a ‘no particular address’ place holder). So replace 0.0.0.0 with 127.0.0.1 . example

2.On windows,pickle function’s closure seems problematic.

"..\multiprocessing\reduction.py", line 60, in dump
      ForkingPickler(file, protocol).dump(obj)
Can't pickle local object '_wrap_build_func.<locals>._wrapped'

I change the code to this:

def _wrap_build_func(build_func,measure_input, tmp_dir, **kwargs):

    if not hasattr(build_func, "output_format"):
        raise AttributeError("Expect build_func to have the attribute output_format.")
    output_format = build_func.output_format

    tic = time.time()
    try:
            filename = os.path.join(tmp_dir, "tmp_func_%0x.%s" % (
                getrandbits(64), output_format))
            # TODO(tvm-team) consider linline _build_func_common
            func, arg_info = _build_func_common(measure_input, **kwargs)
            func.export_library(filename, build_func)
     except Exception as e:  # pylint: disable=broad-except
          return BuildResult(None, None, e, time.time() - tic)
     return BuildResult(filename, arg_info, None, time.time() - tic)

The use of ‘_wrap_build_func’ function also change, but the changes will be minimal.

3.If the windows10 version < 17063, no ‘tar’ command. My method:

I download the Cygwin and  install tar from it. Then, add it to environment variable.You can use the 'tar' command on Windows Command Prompt.

4.If path on the ‘tar’ command contain ‘:’ (example ‘D;\User\xxx’), need to add the ‘–force-local’. tar code

xxxxxxxx
md += [output]
cmd += ["--force-local"]
cmd += ["-C", temp.temp_dir]
cmd += temp.listdir()
xxxxxxxxxx

5.On the untar function ‘code’, If the ‘tar_file’ and ‘directory’ path is in ‘xxx\xxx\xxx’ format and ‘\’ needs to be replaced with ‘/’. Otherwise,Python failed to execute the tar command.

if platform.system() == "Windows":
     if tar_file.find('\\') != -1:
          tar_file = '/'.join(tar_file.split('\\'))
     if directory.find('\\') != -1:
          directory = '/'.join(directory.split('\\'))

6.The Windows Socket error 10048 , Address already in use.So add 10048 to the list

7.Use the LocalRunner ,after starting the Tracker, server don’t connect it. You need to compile cpp_rpc and start the tvm_rpc.exe. You also can use process-pool.

8.The basegraphtuner. benchmark_layout_transform is creating tracker and server in a loop,On windows this’s a big price to pay. code 1 and code 2.

I think we can add some judgment reuse tracker and server.example:

def set_task(self, task):
        if self.tracker and server:

            self.task = task
            tracker = Tracker('0.0.0.0', port=9000, port_end=10000, silent=True)
            device_key = '$local$device$%d' % tracker.port
            server = Server('0.0.0.0', port=9000, port_end=10000,
                        key=device_key,
                        use_popen=True, silent=True,
                        tracker_addr=(tracker.host, tracker.port))
            self.key = device_key
            self.host = tracker.host
            self.port = tracker.port

            super(LocalRunner, self).set_task(task)
            self.server = server
            self.tracker = tracker
        return self.server, self.tracker

9." Compilation error: lld-link: error: : undefined symbol: tvm_main"

This is a temporary fix, annotation “tvm_main”:

Thanks for sharing all of this—really solid findings. Working with AutoTVM on Windows definitely brings some unique challenges, and your notes highlight the key issues really clearly.

  1. Using 127.0.0.1 instead of 0.0.0.0 That makes sense. 0.0.0.0 can act unexpectedly on Windows, so switching to 127.0.0.1 is a smart workaround for local setups.
  2. Pickle and multiprocessing closures Yep, this is a common Windows issue since it doesn’t use fork. Moving the wrapped function to the top level is the right call—glad to see you already figured that out.
  3. Missing tar command Good tip—Cygwin works, or even Git Bash or WSL. In some cases, using Python’s built-in tarfile module could help skip the shell command entirely.
  4. Handling : in Windows paths for tar Adding --force-local is a solid workaround when paths include a drive letter. Windows really doesn’t like the colon in CLI tools unless handled this way.
  5. Backslash issues in tar commands Yeah, replacing \ with / helps when shelling out commands. You might also consider using pathlib.Path.as_posix() to keep things cleaner.
  6. Socket error 10048 Pretty typical when sockets don’t release fast enough. Adding specific handling for error 10048 is a good call.
  7. LocalRunner + cpp_rpc That’s a gotcha for a lot of people. Compiling and manually starting tvm_rpc.exe is necessary, and it’s not super obvious. Documenting this better would help a lot.
  8. Tracker/server creation in loops Definitely inefficient on Windows. Your reuse logic looks like a clean improvement—it’d be great to see something like this upstreamed.
  9. Linker error for tvm_main Seen this too. Annotating or stubbing tvm_main is a workable fix for now, but it’d be good to understand why it’s getting pulled in at all during linking.