-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (56 loc) · 1.68 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Package hotspot provides an interface to HotSpot.
//
// http://lava.cs.virginia.edu/HotSpot
package hotspot
// #cgo CFLAGS: -Isource -Isource/hotspot
// #cgo LDFLAGS: -lm
// #include <stdlib.h>
// #include <string.h>
// #include <circuit.h>
import "C"
import "unsafe"
// Model represents the block variant of the HotSpot model. The thermal system
// under consideration is as follows:
//
// dQ
// diag(C) * -- + G * (Q - Qamb) = P.
// dt
//
// The number of thermal nodes is denoted by Nodes. Then, in the above system,
//
// C is a Nodes-element vector of the thermal capacitance,
// G is a Nodes-by-Nodes matrix of the thermal conductance,
// Q is a Nodes-element vector of the heat dissipation,
// P is a Nodes-element vector of the power consumption, and
// Qamb is a vector of the ambient temperature.
type Model struct {
Cores uint
Nodes uint
C []float64
G []float64
}
// New constructs a thermal RC circuit according to the given configuration.
func New(config *Config) *Model {
const (
sizeOfFloat64 = 8
)
floorplan := C.CString(config.Floorplan)
defer C.free(unsafe.Pointer(floorplan))
configuration := C.CString(config.Configuration)
defer C.free(unsafe.Pointer(configuration))
circuit := C.newCircuit(floorplan, configuration)
defer C.dropCircuit(circuit)
cc := uint(circuit.units)
nc := uint(circuit.nodes)
m := &Model{
Cores: cc,
Nodes: nc,
C: make([]float64, nc),
G: make([]float64, nc*nc),
}
C.memcpy(unsafe.Pointer(&m.C[0]), unsafe.Pointer(circuit.capacitance),
C.size_t(sizeOfFloat64*nc))
C.memcpy(unsafe.Pointer(&m.G[0]), unsafe.Pointer(circuit.conductance),
C.size_t(sizeOfFloat64*nc*nc))
return m
}