leandron commented on a change in pull request #7304:
URL: https://github.com/apache/tvm/pull/7304#discussion_r576752576



##########
File path: python/tvm/driver/tvmc/common.py
##########
@@ -91,18 +272,37 @@ def target_from_cli(target):
     -------
     tvm.target.Target
         an instance of target device information
+    codegens : list of dict
+        This list preserves the order in which codegens were
+        provided via command line. Each Dict contains three keys:
+        'kind', containing the name of the codegen; 'opts' containing
+        a key-value for all options passed via CLI; 'raw',
+        containing the plain string for this codegen
     """
+    extra_codegens = []
 
     if os.path.exists(target):
         with open(target) as target_file:
-            logger.info("using target input from file: %s", target)
+            logger.info("target input is a path: %s", target)
             target = "".join(target_file.readlines())
+    elif is_inline_json(target):
+        logger.info("target input is inline JSON: %s", target)
+    else:
+        logger.info("target input is plain text: %s", target)
+        try:
+            parsed_targets = parse_target(target)
+        except ValueError as ex:
+            raise TVMCException(f"Error parsing target string '{target}'.\nThe 
error was: {ex}")
+
+        validate_targets(parsed_targets)
+        target = parsed_targets[-1]["raw"]
+        extra_codegens = parsed_targets[:-1] if len(parsed_targets) > 1 else []
 
     # TODO(@leandron) We don't have an API to collect a list of supported
     #       targets yet
     logger.debug("creating target from input: %s", target)
 
-    return tvm.target.Target(target)
+    return tvm.target.Target(target), extra_codegens

Review comment:
       Does this refer to the RFC at 
https://discuss.tvm.apache.org/t/rfc-composite-target/7744? I see your point 
for the internal APIs, but having the target exclusively in JSON makes 
prototyping and experimenting with different targets and combinations of 
targets, unnecessarily difficult from a command-line point of view.
   
   From the JSON syntax I read in the Discuss thread above, I couldn't find 
something in there that we can't express in the format of an inline target at 
the moment - I might be wrong. Concretely, it represents a list of a sorted 
list of devices, and a fallback target host.
   
   **Specifically for TVMC**, I feel the solution is to come up with a way the 
the command line do the work of converting inline targets, to satisfy the 
internal APIs with the JSON format it needs, as well as accept the JSON 
specification. I think we should go on that direction.
   
   It looks more meaningful for an end user familiar with any other compiler, 
to type: `--target="ethos-n77, opencl, llvm"`, rather than encode that into a 
`target_spec.json` and use `--target=target_spec.json` or even to have 
`--target="{ 'kind': 'composite', 'target_host': 'llvm', 'devices': [{'kind': 
'ethos-n77'}, {'kind': 'opencl'}]}"`.
   
   It is TVMC role to - when support arrives - to get from 
`--target="ethos-n77, opencl, llvm"`, and end-up with `{ 'kind': 'composite', 
'target_host': 'llvm', 'devices': [{'kind': 'ethos-n77'}, {'kind': 
'opencl'}]}"` to satisfy the internal APIs.
   
   @comaniac @junrushao1994 what do you think?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to