[Target] Add "features" property to Target (#12121)

This adds a generated property "features" to the `Target` which can
contain a read-only list of available features in line with
https://github.com/apache/tvm-rfcs/pull/78.

Features are re-generated upon parsing into a `Target` object rather than being
attached as `attrs`. The `Target` JSON is therefore stored without the
inferred `features` attached.
This commit is contained in:
Christopher Sidebottom
2022-07-19 14:58:49 +01:00
committed by GitHub
parent 342fbea84e
commit 7bf5fa449c
7 changed files with 109 additions and 1 deletions
+1
View File
@@ -216,6 +216,7 @@ class Device(ctypes.Structure):
"stackvm": 1,
"cpu": 1,
"c": 1,
"test": 1,
"hybrid": 1,
"composite": 1,
"cuda": 2,
+12
View File
@@ -43,6 +43,14 @@ class TargetKind(Object):
return dict(_ffi_api.ListTargetKindOptionsFromName(kind_name))
class TargetFeatures:
def __init__(self, target):
self.target = target
def __getattr__(self, name: str):
return _ffi_api.TargetGetFeature(self.target, name)
@tvm._ffi.register_object
class Target(Object):
"""Target device information, use through TVM API.
@@ -207,6 +215,10 @@ class Target(Object):
def libs(self):
return list(self.attrs.get("libs", []))
@property
def features(self):
return TargetFeatures(self)
def get_kind_attr(self, attr_name):
"""Get additional attribute about the target kind.