1 /* Copyright (c) 2014 Mark D. Hill and David A. Wood
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "libutil/String.h"
33 #include "model/Model.h"
36 using namespace LibUtil
;
38 static PyObject
*DSENTError
;
39 static PyObject
* dsent_initialize(PyObject
*, PyObject
*);
40 static PyObject
* dsent_finalize(PyObject
*, PyObject
*);
41 static PyObject
* dsent_computeRouterPowerAndArea(PyObject
*, PyObject
*);
42 static PyObject
* dsent_computeLinkPower(PyObject
*, PyObject
*);
44 // Create DSENT configuration map. This map is supposed to retain all
45 // the information between calls to initialize() and finalize().
46 map
<String
, String
> params
;
47 DSENT::Model
*ms_model
;
50 static PyMethodDef DSENTMethods
[] = {
51 {"initialize", dsent_initialize
, METH_O
,
52 "initialize dsent using a config file."},
54 {"finalize", dsent_finalize
, METH_NOARGS
,
55 "finalize dsent by dstroying the config object"},
57 {"computeRouterPowerAndArea", dsent_computeRouterPowerAndArea
,
58 METH_VARARGS
, "compute quantities related power consumption of a router"},
60 {"computeLinkPower", dsent_computeLinkPower
, METH_O
,
61 "compute quantities related power consumption of a link"},
72 m
= Py_InitModule("dsent", DSENTMethods
);
73 if (m
== NULL
) return;
75 DSENTError
= PyErr_NewException("dsent.error", NULL
, NULL
);
76 Py_INCREF(DSENTError
);
77 PyModule_AddObject(m
, "error", DSENTError
);
84 dsent_initialize(PyObject
*self
, PyObject
*arg
)
86 const char *config_file
= PyString_AsString(arg
);
87 //Read the arguments sent from the python script
93 ms_model
= DSENT::initialize(config_file
, params
);
99 dsent_finalize(PyObject
*self
, PyObject
*args
)
102 DSENT::finalize(params
, ms_model
);
109 dsent_computeRouterPowerAndArea(PyObject
*self
, PyObject
*args
)
112 unsigned int num_in_port
;
113 unsigned int num_out_port
;
114 unsigned int num_vclass
;
115 unsigned int num_vchannels
;
116 unsigned int num_buffers
;
118 unsigned int flit_width
;
119 const char *input_port_buffer_model
;
120 const char *crossbar_model
;
121 const char *sa_arbiter_model
;
122 const char *clk_tree_model
;
123 unsigned int clk_tree_num_levels
;
124 const char *clk_tree_wire_layer
;
125 double clk_tree_wire_width_mult
;
127 // Read the arguments sent from the python script
128 if (!PyArg_ParseTuple(args
, "KIIIIII", &frequency
, &num_in_port
,
129 &num_out_port
, &num_vclass
, &num_vchannels
,
130 &num_buffers
, &flit_width
)) {
134 assert(frequency
> 0.0);
135 assert(num_in_port
!= 0);
136 assert(num_out_port
!= 0);
137 assert(num_vclass
!= 0);
138 assert(flit_width
!= 0);
140 vector
<unsigned int> num_vchannels_vec(num_vclass
, num_vchannels
);
141 vector
<unsigned int> num_buffers_vec(num_vclass
, num_buffers
);
143 map
<string
, double> outputs
;
145 params
["Frequency"] = String(frequency
);
146 params
["NumberInputPorts"] = String(num_in_port
);
147 params
["NumberOutputPorts"] = String(num_out_port
);
148 params
["NumberVirtualNetworks"] = String(num_vclass
);
149 params
["NumberVirtualChannelsPerVirtualNetwork"] =
150 vectorToString
<unsigned int>(num_vchannels_vec
);
151 params
["NumberBuffersPerVirtualChannel"] =
152 vectorToString
<unsigned int>(num_buffers_vec
);
153 params
["NumberBitsPerFlit"] = String(flit_width
);
156 DSENT::run(params
, ms_model
, outputs
);
159 PyObject
*r
= PyTuple_New(outputs
.size());
162 // Prepare the output. The assumption is that all the output
163 for (const auto &it
: outputs
) {
164 PyObject
*s
= PyTuple_New(2);
165 PyTuple_SetItem(s
, 0, PyString_FromString(it
.first
.c_str()));
166 PyTuple_SetItem(s
, 1, PyFloat_FromDouble(it
.second
));
168 PyTuple_SetItem(r
, index
, s
);
177 dsent_computeLinkPower(PyObject
*self
, PyObject
*arg
)
179 uint64_t frequency
= PyLong_AsLongLong(arg
);
181 // Read the arguments sent from the python script
182 if (frequency
== -1) {
187 map
<string
, double> outputs
;
188 params
["Frequency"] = String(frequency
);
191 DSENT::run(params
, ms_model
, outputs
);
194 PyObject
*r
= PyTuple_New(outputs
.size());
197 // Prepare the output. The assumption is that all the output
198 for (const auto &it
: outputs
) {
199 PyObject
*s
= PyTuple_New(2);
200 PyTuple_SetItem(s
, 0, PyString_FromString(it
.first
.c_str()));
201 PyTuple_SetItem(s
, 1, PyFloat_FromDouble(it
.second
));
203 PyTuple_SetItem(r
, index
, s
);
211 dsent_printAvailableModels(PyObject
* self
, PyObject
*args
)