Hello,
In the topology configuration file I accidentally did
childStates.getChild(child), instead of childStates.addChild(child). When I
fixed it, I still got the exact same error, which is:
childStates.addChild(child)
File "/home/alex/Desktop/gem5/gem5-stable/src/python/m5/SimObject.py", line
725, in __getattr__
% (self.__class__.__name__, attr)
AttributeError: object 'ChildStates' has no attribute 'addChild'
Best regards,
Alex Tomala
________________________________
From: Steve Reinhardt <[email protected]>
To: Alex Tomala <[email protected]>
Cc: gem5 users mailing list <[email protected]>
Sent: Thursday, January 2, 2014 6:16:24 PM
Subject: Re: [gem5-users] Calling a C++ function in Python
I'm a little confused about where the 'getChild' call is coming from since
'addChild' is the method you added... are you leaving some parts out of the
code you're posting?
On Thu, Jan 2, 2014 at 3:09 PM, Alex Tomala <[email protected]> wrote:
Hello Steve,
>
>
>I tried the following in a topology configuration file:
>
>
>childStates = ChildStates()
>childStates.addChild(child) #child is the MachineID
>
>
>When I run gem5 I get the following error:
>
>
> childStates.getChild(child)
>
> File "/home/alex/Desktop/gem5/gem5-stable/src/python/m5/SimObject.py", line
>725, in __getattr__
> % (self.__class__.__name__, attr)
>AttributeError: object 'ChildStates' has no attribute 'getChild'
>
>
>This is the only method I tried, but I can't think of any other method to get
>it done.
>
>
>One day I may add some information to the wiki, but I am a tad busy now.
>
>
>Best regards,
>
>
>Alex Tomala
>
>________________________________
>
>From: Steve Reinhardt <[email protected]>
>To: Alex Tomala <[email protected]>; gem5 users mailing list
><[email protected]>
>Sent: Thursday, January 2, 2014 5:22:47 PM
>Subject: Re: [gem5-users] Calling a C++ function in Python
>
>
>
>What have you tried and what problems are you having? It should just be a
>matter of calling 'obj.addChild(x)' on your ChildStates object 'obj'.
>
>
>It looks like you've figured most of this out already, but a lot of the
>current mechanism was added in this changeset (see particularly the comments
>in the added code in SimObject.py):
>http://repo.gem5.org/gem5/rev/45c9f664a365
>
>
>And here's an example of adding a method:
>http://repo.gem5.org/gem5/rev/09dcdb40b109
>
>
>If you're feeling ambitious, it would be great if you'd be willing to write up
>some documentation on how to add callable functions on the wiki, say on this
>page (or a page linked from it):
>http://gem5.org/SimObjects
>
>
>
>Thanks,
>
>
>Steve
>
>
>
>
>On Thu, Jan 2, 2014 at 1:38 PM, Alex Tomala <[email protected]> wrote:
>
>Hello,
>>
>>
>>I partially figure out the solution to the problem. I figured out that you
>>can over ride the exports_method method from the sim object python file to
>>add functions. Now my Python interfacing file looks like this:
>>
>>
>> from m5.params import *
>>from m5.SimObject import SimObject
>>from Controller import RubyController
>>
>>
>>class ChildStates(SimObject):
>>type = 'ChildStates'
>>cxx_class = 'ChildStates'
>>cxx_header = '"mem/protocol/ChildStates.hh"
>>childPorts = Param.Int("Number of Children Ports")
>>@classmethod
>>def export_methods(cls, code):
>> code('''
>>void addChild(MachineID child);
>>''')
>>
>>
>>The *.i file associated with the custom SimObject now contains the proper
>>method. My only problem that I have now is that I don't know how to call the
>>method in Python. I am guessing that I am importing the wrong module or
>>something similar.
>>
>>
>>- Alex
>>
>>
>>
>>
>>
>>________________________________
>> From: Alex Tomala <[email protected]>
>>To: gem5 mailing list <[email protected]>
>>Sent: Wednesday, January 1, 2014 5:03:13 PM
>>Subject: Calling a C++ function in Python
>>
>>
>>
>>Hello,
>>
>>
>>I created a custom SimObject in C++ that has a function that I want to
>>execute in Python. I am wondering how I can interface the function to Python
>>as instance.function_name does not seem to work. The function I am using is
>>called addChild and it takes a MachineID as an input.
>>
>>
>>My current Python interfacing file looks like this:
>>
>>
>>from m5.params import *
>>from m5.SimObject import SimObject
>>from Controller import RubyController
>>
>>
>>class ChildStates(SimObject):
>>type = 'ChildStates'
>>cxx_class = 'ChildStates'
>>cxx_header = '"mem/protocol/ChildStates.hh"
>>childPorts = Param.Int("Number of Children Ports")
>>
>>
>>Best regards,
>>
>>
>>Alex
>>
>>
>>_______________________________________________
>>gem5-users mailing list
>>[email protected]
>>http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users
>>
>
>
>_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users