Nikos Nikoleris has submitted this change and it was merged. (
https://gem5-review.googlesource.com/11510 )
Change subject: python: Add support for multiplying proxies to compatible
Param
......................................................................
python: Add support for multiplying proxies to compatible Param
Previously we allowed multiplications between proxy Param and
compatible constants (int, long, float). This change extends this
functionality and adds support for multiplying with between proxy
Param and compatible proxy Param.
Change-Id: I23a083881ae4d770e818895b893534767cd2472d
Reviewed-by: Andreas Sandberg <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/11510
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
---
M src/python/m5/proxy.py
1 file changed, 34 insertions(+), 14 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
diff --git a/src/python/m5/proxy.py b/src/python/m5/proxy.py
index a99d371..c0bf84a 100644
--- a/src/python/m5/proxy.py
+++ b/src/python/m5/proxy.py
@@ -1,3 +1,15 @@
+# Copyright (c) 2018 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
# Copyright (c) 2004-2006 The Regents of The University of Michigan
# All rights reserved.
#
@@ -35,11 +47,13 @@
import copy
+import params
+
class BaseProxy(object):
def __init__(self, search_self, search_up):
self._search_self = search_self
self._search_up = search_up
- self._multiplier = None
+ self._multipliers = []
def __str__(self):
if self._search_self and not self._search_up:
@@ -56,23 +70,29 @@
"cannot set attribute '%s' on proxy object" % attr
super(BaseProxy, self).__setattr__(attr, value)
- # support multiplying proxies by constants
+ # support for multiplying proxies by constants or other proxies to
+ # other params
def __mul__(self, other):
- if not isinstance(other, (int, long, float)):
- raise TypeError, "Proxy multiplier must be integer"
- if self._multiplier == None:
- self._multiplier = other
- else:
- # support chained multipliers
- self._multiplier *= other
+ if not (isinstance(other, (int, long, float)) or isproxy(other)):
+ raise TypeError, \
+ "Proxy multiplier must be a constant or a proxy to a param"
+ self._multipliers.append(other)
return self
__rmul__ = __mul__
- def _mulcheck(self, result):
- if self._multiplier == None:
- return result
- return result * self._multiplier
+ def _mulcheck(self, result, base):
+ for multiplier in self._multipliers:
+ if isproxy(multiplier):
+ multiplier = multiplier.unproxy(base)
+ # assert that we are multiplying with a compatible
+ # param
+ if not isinstance(multiplier, params.NumericParamValue):
+ raise TypeError, \
+ "Proxy multiplier must be a numerical param"
+ multiplier = multiplier.getValue()
+ result *= multiplier
+ return result
def unproxy(self, base):
obj = base
@@ -105,7 +125,7 @@
raise RuntimeError, "Cycle in unproxy"
result = result.unproxy(obj)
- return self._mulcheck(result)
+ return self._mulcheck(result, base)
def getindex(obj, index):
if index == None:
--
To view, visit https://gem5-review.googlesource.com/11510
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I23a083881ae4d770e818895b893534767cd2472d
Gerrit-Change-Number: 11510
Gerrit-PatchSet: 2
Gerrit-Owner: Nikos Nikoleris <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Nikos Nikoleris <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev