-
Notifications
You must be signed in to change notification settings - Fork 9
/
wfdispatcher.go
234 lines (192 loc) · 5.55 KB
/
wfdispatcher.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package cu
import (
"log"
"github.com/sarchlab/akita/v3/sim"
"github.com/sarchlab/mgpusim/v3/insts"
"github.com/sarchlab/mgpusim/v3/protocol"
"github.com/sarchlab/mgpusim/v3/timing/wavefront"
)
// A WfDispatcher initialize wavefronts
type WfDispatcher interface {
DispatchWf(
now sim.VTimeInSec,
wf *wavefront.Wavefront,
location protocol.WfDispatchLocation,
)
}
// A WfDispatcherImpl will register the wavefront in wavefront pool and
// initialize all the registers
type WfDispatcherImpl struct {
cu *ComputeUnit
Latency int
}
// NewWfDispatcher creates a default WfDispatcher
func NewWfDispatcher(cu *ComputeUnit) *WfDispatcherImpl {
d := new(WfDispatcherImpl)
d.cu = cu
d.Latency = 0
return d
}
// DispatchWf starts or continues a wavefront dispatching process.
func (d *WfDispatcherImpl) DispatchWf(
now sim.VTimeInSec,
wf *wavefront.Wavefront,
location protocol.WfDispatchLocation,
) {
d.setWfInfo(wf, location)
d.initRegisters(wf)
}
func (d *WfDispatcherImpl) setWfInfo(
wf *wavefront.Wavefront,
location protocol.WfDispatchLocation,
) {
wf.SIMDID = location.SIMDID
wf.SRegOffset = location.SGPROffset
wf.VRegOffset = location.VGPROffset
wf.LDSOffset = location.LDSOffset
wf.PC = wf.Packet.KernelObject + wf.CodeObject.KernelCodeEntryByteOffset
wf.EXEC = wf.InitExecMask
}
//nolint:gocyclo,funlen
func (d *WfDispatcherImpl) initRegisters(wf *wavefront.Wavefront) {
co := wf.CodeObject
pkt := wf.Packet
SGPRPtr := 0
if co.EnableSgprPrivateSegmentBuffer() {
// log.Printf("EnableSgprPrivateSegmentBuffer is not supported")
// fmt.Printf("s%d SGPRPrivateSegmentBuffer\n", SGPRPtr/4)
SGPRPtr += 16
}
if co.EnableSgprDispatchPtr() {
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 2, 0, wf.SRegOffset,
insts.Uint64ToBytes(wf.PacketAddress),
false,
})
// fmt.Printf("s%d SGPRDispatchPtr\n", SGPRPtr/4)
SGPRPtr += 8
}
if co.EnableSgprQueuePtr() {
log.Printf("EnableSgprQueuePtr is not supported")
// fmt.Printf("s%d SGPRQueuePtr\n", SGPRPtr/4)
SGPRPtr += 8
}
if co.EnableSgprKernelArgSegmentPtr() {
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 2, 0, wf.SRegOffset,
insts.Uint64ToBytes(pkt.KernargAddress),
false,
})
// fmt.Printf("s%d SGPRKernelArgSegmentPtr\n", SGPRPtr/4)
SGPRPtr += 8
}
if co.EnableSgprDispatchID() {
log.Printf("EnableSgprDispatchID is not supported")
// fmt.Printf("s%d SGPRDispatchID\n", SGPRPtr/4)
SGPRPtr += 8
}
if co.EnableSgprFlatScratchInit() {
log.Printf("EnableSgprFlatScratchInit is not supported")
// fmt.Printf("s%d SGPRFlatScratchInit\n", SGPRPtr/4)
SGPRPtr += 8
}
if co.EnableSgprPrivateSegementSize() {
log.Printf("EnableSgprPrivateSegmentSize is not supported")
// fmt.Printf("s%d SGPRPrivateSegmentSize\n", SGPRPtr/4)
SGPRPtr += 4
}
if co.EnableSgprGridWorkGroupCountX() {
// fmt.Printf("s%d WorkGroupCountX\n", SGPRPtr/4)
wgCountX := (pkt.GridSizeX + uint32(pkt.WorkgroupSizeX) - 1) /
uint32(pkt.WorkgroupSizeX)
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(wgCountX),
false,
})
SGPRPtr += 4
}
if co.EnableSgprGridWorkGroupCountY() {
// fmt.Printf("s%d WorkGroupCountY\n", SGPRPtr/4)
wgCountY := (pkt.GridSizeY + uint32(pkt.WorkgroupSizeY) - 1) /
uint32(pkt.WorkgroupSizeY)
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(wgCountY),
false,
})
SGPRPtr += 4
}
if co.EnableSgprGridWorkGroupCountZ() {
// fmt.Printf("s%d WorkGroupCountZ\n", SGPRPtr/4)
wgCountZ := (pkt.GridSizeZ + uint32(pkt.WorkgroupSizeZ) - 1) /
uint32(pkt.WorkgroupSizeZ)
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(wgCountZ),
false,
})
SGPRPtr += 4
}
if co.EnableSgprWorkGroupIDX() {
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(uint32(wf.WG.IDX)),
false,
})
// fmt.Printf("s%d WorkGroupIdX\n", SGPRPtr/4)
SGPRPtr += 4
}
if co.EnableSgprWorkGroupIDY() {
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(uint32(wf.WG.IDY)),
false,
})
// fmt.Printf("s%d WorkGroupIdY\n", SGPRPtr/4)
SGPRPtr += 4
}
if co.EnableSgprWorkGroupIDZ() {
d.cu.SRegFile.Write(RegisterAccess{
0, insts.SReg(SGPRPtr / 4), 1, 0, wf.SRegOffset,
insts.Uint32ToBytes(uint32(wf.WG.IDZ)),
false,
})
// fmt.Printf("s%d WorkGroupIdZ\n", SGPRPtr/4)
SGPRPtr += 4
}
if co.EnableSgprWorkGroupInfo() {
log.Printf("EnableSgprPrivateSegmentSize is not supported")
SGPRPtr += 4
}
if co.EnableSgprPrivateSegmentWaveByteOffset() {
log.Printf("EnableSgprPrivateSegentWaveByteOffset is not supported")
SGPRPtr += 4
}
var x, y, z int
for i := wf.FirstWiFlatID; i < wf.FirstWiFlatID+64; i++ {
z = i / (wf.WG.SizeX * wf.WG.SizeY)
y = i % (wf.WG.SizeX * wf.WG.SizeY) / wf.WG.SizeX
x = i % (wf.WG.SizeX * wf.WG.SizeY) % wf.WG.SizeX
laneID := i - wf.FirstWiFlatID
d.cu.VRegFile[wf.SIMDID].Write(RegisterAccess{
0, insts.VReg(0), 1, laneID, wf.VRegOffset,
insts.Uint32ToBytes(uint32(x)),
false,
})
if co.EnableVgprWorkItemID() > 0 {
d.cu.VRegFile[wf.SIMDID].Write(RegisterAccess{
0, insts.VReg(1), 1, laneID, wf.VRegOffset,
insts.Uint32ToBytes(uint32(y)),
false,
})
}
if co.EnableVgprWorkItemID() > 1 {
d.cu.VRegFile[wf.SIMDID].Write(RegisterAccess{
0, insts.VReg(2), 1, laneID, wf.VRegOffset,
insts.Uint32ToBytes(uint32(z)),
false,
})
}
}
}