Skip to content

Commit 3fa6db8

Browse files
committed
bug fix to avoid early unmapping of the workgroups, and maintain the correct fetch/issue order per wavefront
1 parent e20f339 commit 3fa6db8

File tree

9 files changed

+62
-38
lines changed

9 files changed

+62
-38
lines changed

src/arch/southern-islands/emulator/WorkGroup.h

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class WorkGroup
132132
/// simulator
133133
bool finished_timing = false;
134134

135+
/// Number of instructions issued for this workgroup
136+
long long inflight_instructions = 0;
137+
135138
/// Wavefront pool that the work group is associated with.
136139
WavefrontPool *wavefront_pool = nullptr;
137140

src/arch/southern-islands/timing/BranchUnit.cc

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20+
#include <arch/southern-islands/emulator/WorkGroup.h>
2021
#include <arch/southern-islands/emulator/Wavefront.h>
2122

2223
#include "BranchUnit.h"
@@ -103,6 +104,10 @@ void BranchUnit::Complete()
103104
// Access complete, remove the uop from the queue, and get the
104105
// iterator for the next element
105106
it = write_buffer.erase(it);
107+
assert(uop->getWorkGroup()
108+
->inflight_instructions > 0);
109+
uop->getWorkGroup()->
110+
inflight_instructions--;
106111

107112
// Statistics
108113
num_instructions++;

src/arch/southern-islands/timing/ComputeUnit.cc

+14-16
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void ComputeUnit::Issue(FetchBuffer *fetch_buffer)
178178
"cu=%d "
179179
"wf=%d "
180180
"uop_id=%lld "
181-
"stg=\"i\"\n",
181+
"stg=\"s\"\n",
182182
uop->getIdInComputeUnit(),
183183
index,
184184
uop->getWavefront()->getId(),
@@ -252,24 +252,19 @@ void ComputeUnit::Fetch(FetchBuffer *fetch_buffer,
252252
// be fetched.
253253
if (wavefront->getFinished())
254254
{
255-
Timing::pipeline_debug << misc::fmt(
256-
"wg=%d/wf=%d "
257-
"Fetch:Finished\n",
258-
wavefront->getWorkGroup()->getId(),
259-
wavefront->getId());
260255
continue;
261256
}
262257

263258
// Wavefront is ready but waiting on outstanding
264259
// memory instructions
265-
if (wavefront->isMemoryWait())
260+
if (wavefront_pool_entry->mem_wait)
266261
{
267262
// No outstanding accesses
268263
if (!wavefront_pool_entry->lgkm_cnt &&
269264
!wavefront_pool_entry->exp_cnt &&
270265
!wavefront_pool_entry->vm_cnt)
271266
{
272-
wavefront->setMemoryWait(false);
267+
wavefront_pool_entry->mem_wait = false;
273268
Timing::pipeline_debug << misc::fmt(
274269
"wg=%d/wf=%d "
275270
"Mem-wait:Done\n",
@@ -354,17 +349,17 @@ void ComputeUnit::Fetch(FetchBuffer *fetch_buffer,
354349
// Debug
355350
Timing::pipeline_debug << misc::fmt(
356351
"wg=%d/wf=%d cu=%d wfPool=%d "
357-
"InstID=%lld asm=%s id_in_wf=%lld\n"
358-
"\tInstID=%lld (Fetch)\n",
352+
"inst=%lld asm=%s id_in_wf=%lld\n"
353+
"\tinst=%lld (Fetch)\n",
359354
uop->getWavefront()->getWorkGroup()->
360355
getId(),
361356
uop->getWavefront()->getId(),
362357
index,
363358
uop->getWavefrontPoolId(),
364-
uop->getIdInComputeUnit(),
359+
uop->getId(),
365360
instruction_name.c_str(),
366361
uop->getIdInWavefront(),
367-
uop->getIdInComputeUnit());
362+
uop->getId());
368363
}
369364

370365
// Update last memory accesses
@@ -407,6 +402,7 @@ void ComputeUnit::Fetch(FetchBuffer *fetch_buffer,
407402
uop->fetch_ready = timing->getCycle() + fetch_latency;
408403

409404
// Insert uop into fetch buffer
405+
uop->getWorkGroup()->inflight_instructions++;
410406
fetch_buffer->addUop(std::move(uop));
411407

412408
instructions_processed++;
@@ -529,6 +525,8 @@ void ComputeUnit::AddWorkGroup(WorkGroup *work_group)
529525
{
530526
// Make sure an entry is emptied up
531527
assert(work_groups[index] == nullptr);
528+
assert(work_groups.size() <=
529+
(unsigned) gpu->getWorkGroupsPerComputeUnit());
532530

533531
// Set the new work group to the empty entry
534532
work_groups[index] = work_group;
@@ -581,10 +579,6 @@ void ComputeUnit::UnmapWorkGroup(WorkGroup *work_group)
581579
// Unmap wavefronts from instruction buffer
582580
work_group->wavefront_pool->UnmapWavefronts(work_group);
583581

584-
// Remove the work group from the running work groups list
585-
NDRange *ndrange = work_group->getNDRange();
586-
ndrange->RemoveWorkGroup(work_group);
587-
588582
// If compute unit is not already in the available list, place
589583
// it there. The vector list of work groups does not shrink,
590584
// when we unmap a workgroup.
@@ -595,6 +589,10 @@ void ComputeUnit::UnmapWorkGroup(WorkGroup *work_group)
595589
// Trace
596590
Timing::trace << misc::fmt("si.unmap_wg cu=%d wg=%d\n", index,
597591
work_group->getId());
592+
593+
// Remove the work group from the running work groups list
594+
NDRange *ndrange = work_group->getNDRange();
595+
ndrange->RemoveWorkGroup(work_group);
598596
}
599597

600598

src/arch/southern-islands/timing/ExecutionUnit.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20+
#include <arch/southern-islands/emulator/WorkGroup.h>
21+
#include <arch/southern-islands/emulator/Wavefront.h>
22+
2023
#include "BranchUnit.h"
2124
#include "Timing.h"
2225

23-
2426
namespace SI
2527
{
2628

src/arch/southern-islands/timing/LdsUnit.cc

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20+
#include <arch/southern-islands/emulator/WorkGroup.h>
2021
#include <arch/southern-islands/emulator/Wavefront.h>
2122
#include <arch/southern-islands/emulator/WorkItem.h>
2223

@@ -109,6 +110,10 @@ void LdsUnit::Complete()
109110

110111
// Access complete, remove the uop from the queue
111112
it = write_buffer.erase(it);
113+
assert(uop->getWorkGroup()
114+
->inflight_instructions > 0);
115+
uop->getWorkGroup()->
116+
inflight_instructions--;
112117

113118
// Statistics
114119
num_instructions++;

src/arch/southern-islands/timing/ScalarUnit.cc

+15-20
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,18 @@ void ScalarUnit::Complete()
150150
uop->getWavefrontPoolEntry()->lgkm_cnt--;
151151
}
152152

153+
if (!uop->scalar_memory_read)
154+
{
155+
// Update wavefront pool entry
156+
uop->getWavefrontPoolEntry()->ready = true;
157+
}
153158

154159
// Check for "wait" instruction
155160
// If a wait instruction was executed and there are outstanding
156161
// memory accesses, set the wavefront to waiting
157162
if (uop->memory_wait)
158163
{
159164
uop->getWavefrontPoolEntry()->mem_wait = true;
160-
uop->getWavefrontPoolEntry()->ready = true;
161165
}
162166

163167
// Check for "barrier" instruction
@@ -179,16 +183,7 @@ void ScalarUnit::Complete()
179183
assert(wavefront->getWavefrontPoolEntry());
180184
if (!wavefront->getWavefrontPoolEntry()->
181185
wait_for_barrier)
182-
{
183-
Timing::pipeline_debug << misc::fmt(
184-
"\tInstID=%lld id_in_wf=%lld "
185-
"at Barrier:wait for wf=%d\n",
186-
uop->getIdInComputeUnit(),
187-
uop->getIdInWavefront(),
188-
wavefront->
189-
getId());
190186
barrier_complete = false;
191-
}
192187
}
193188

194189
// If all wavefronts have reached the barrier,
@@ -214,9 +209,6 @@ void ScalarUnit::Complete()
214209
uop->getIdInWavefront(),
215210
uop->getWavefront()->getId());
216211
}
217-
218-
// Update wavefront pool entry
219-
uop->getWavefrontPoolEntry()->ready = true;
220212
}
221213

222214
if (uop->wavefront_last_instruction)
@@ -239,8 +231,15 @@ void ScalarUnit::Complete()
239231

240232
// Check if the work group is finished. If so, unmap
241233
// the work group
242-
if (work_group->finished_timing)
234+
if (work_group->finished_timing &&
235+
work_group->inflight_instructions == 1)
236+
{
237+
Timing::pipeline_debug << misc::fmt(
238+
"wg=%d "
239+
"WGFinished\n",
240+
work_group->getId());
243241
compute_unit->UnmapWorkGroup(uop->getWorkGroup());
242+
}
244243
}
245244

246245
// Trace
@@ -252,6 +251,8 @@ void ScalarUnit::Complete()
252251

253252
// Access complete, remove the uop from the queue
254253
it = write_buffer.erase(it);
254+
assert(uop->getWorkGroup()->inflight_instructions > 0);
255+
uop->getWorkGroup()->inflight_instructions--;
255256

256257
// Statistics
257258
num_instructions++;
@@ -639,12 +640,6 @@ void ScalarUnit::Read()
639640
uop->read_ready = compute_unit->getTiming()->getCycle() +
640641
read_latency;
641642

642-
if (!uop->at_barrier && !uop->memory_wait &&
643-
!uop->wavefront_last_instruction)
644-
{
645-
uop->getWavefrontPoolEntry()->ready_next_cycle = true;
646-
}
647-
648643
// Trace
649644
Timing::trace << misc::fmt("si.inst "
650645
"id=%lld "

src/arch/southern-islands/timing/SimdUnit.cc

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1818
*/
1919

20+
#include <arch/southern-islands/emulator/WorkGroup.h>
2021
#include <arch/southern-islands/emulator/Wavefront.h>
2122

2223
#include "SimdUnit.h"
@@ -111,6 +112,10 @@ void SimdUnit::Complete()
111112
// Remove uop from the exec buffer and get the iterator to the
112113
// next element
113114
it = exec_buffer.erase(it);
115+
assert(uop->getWorkGroup()
116+
->inflight_instructions > 0);
117+
uop->getWorkGroup()->
118+
inflight_instructions--;
114119
}
115120

116121
}

src/arch/southern-islands/timing/VectorMemoryUnit.cc

+12
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ void VectorMemoryUnit::Complete()
114114
// Access complete, remove the uop from the queue and get the
115115
// iterator for the next element
116116
it = write_buffer.erase(it);
117+
assert(uop->getWorkGroup()
118+
->inflight_instructions > 0);
119+
uop->getWorkGroup()->
120+
inflight_instructions--;
117121

118122
// Statistics
119123
num_instructions++;
@@ -302,6 +306,14 @@ void VectorMemoryUnit::Memory()
302306

303307
// Access global memory
304308
assert(!uop->global_memory_witness);
309+
Timing::pipeline_debug << misc::fmt(
310+
"\t\t@%lld inst=%lld "
311+
"id_in_wf=%lld wg=%d/wf=%d (VecMem)\n",
312+
compute_unit->getTiming()->getCycle(),
313+
uop->getId(),
314+
uop->getIdInWavefront(),
315+
uop->getWorkGroup()->getId(),
316+
uop->getWavefront()->getId());
305317
for (auto wi_it = uop->getWavefront()->getWorkItemsBegin(),
306318
wi_e = uop->getWavefront()->getWorkItemsEnd();
307319
wi_it != wi_e;

src/arch/southern-islands/timing/WavefrontPool.h

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class WavefrontPoolEntry
7373
/// Return the associated wavefront
7474
Wavefront *getWavefront() const { return wavefront; }
7575

76-
7776

7877

7978
//

0 commit comments

Comments
 (0)