Hi all, I am not sure the MySimObject will be allowed by the Python code. If I recall correctly, when I tried there was something about the Params being programmatically forward declared somewhere, and it didn't exist without the template arguments.
Some time ago I have embedded templates to Python https://gem5-review.googlesource.com/c/public/gem5/+/11629. The usage is explained in the commit message, but this is a basic approach which does not cover all aspects of templates. It worked for what I wanted to do, but since it was not desired mainstream, I let it go. Regards,Daniel Em sexta-feira, 22 de fevereiro de 2019 03:05:39 GMT+1, Jason Lowe-Power <[email protected]> escreveu: Hey Gabe, Could you describe in a little more detail why you want to templatize a SimObject. Since python doesn't have support for templates, I don't really like the idea of supporting this. One option is to have the Python side of the SimObject be the "specialization" and then you'd just have to implement the SimObjectParams::create() function to return the specialized template for each of the types you want to support from Python. Does that make sense? Maybe this is what you meant by "subclassing" For instance: *my_simobject.hh:* template <type T> MySimObject public SimObject { ... }; *my_simobject.cc:* MySimObjectIntParams::create() { return MySimObject<int>(this); } MySimObjectFloatParams::create() { return MySimObject<float>(this); } *MySimObject.py:* class MySimObjectGeneric(SimObject): # I'm not sure if this is exactly right... ... <all of the params> class MySimObjectInt(MySimObjectGeneric): <header file, etc.> class MySimObjectFloat(MySimObjectGeneric): <header file, etc.> I would say that if the above doesn't work now, we should update things so it does work. However, I don't think we should do any of this *automatically* for templated SimObjects. Cheers, Jason On Fri, Feb 15, 2019 at 5:55 PM Gabe Black <[email protected]> wrote: > Hi folks. I'm trying to create a SimObject out of a templated class (the > python Param type uses a specialization of it), and the pybind11 generated > code doesn't compile because the predeclaration of the class type isn't > syntactically correct since it's a template. I can work around this problem > by, for instance, subclassing it and then using that subclass (at least I > think I can, I haven't tried it yet), but it would be nice if the system > could handle it. > > It's not obvious how to fix it since it's not obvious from the fully > specified type how it should be prototyped, so it's not a quick fix. Has > anyone attempted to get this to work, and/or have a solution? > > Thanks! > Gabe > _______________________________________________ > gem5-dev mailing list > [email protected] > http://m5sim.org/mailman/listinfo/gem5-dev _______________________________________________ gem5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/gem5-dev _______________________________________________ gem5-dev mailing list [email protected] http://m5sim.org/mailman/listinfo/gem5-dev
