-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCProgram.tla
More file actions
1168 lines (1019 loc) · 54.1 KB
/
Copy pathMCProgram.tla
File metadata and controls
1168 lines (1019 loc) · 54.1 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---- MODULE MCProgram ----
\* MCProgram combines the shader-specific program facts emitted by Homunculus with the
\* hand-written dynamic-block machinery from Sec. 3 / Sec. 4 of the paper. The generated part of
\* this module supplies the static CFG, instructions, and operands; the handwritten part tracks the
\* dynamic execution graph and classifies instructions as independent, synchronous, or collective.
LOCAL INSTANCE Integers
LOCAL INSTANCE Naturals
LOCAL INSTANCE Sequences
LOCAL INSTANCE FiniteSets
\* LOCAL INSTANCE MCLayout
LOCAL INSTANCE TLC
VARIABLES globalVars, threadLocals, state, DynamicBlockSet, globalCounter
(* Layout Configuration *)
Threads == {tid : tid \in 1..NumThreads}
(* Variable *)
Var(varScope, varName, varValue, index) ==
[scope |-> varScope,
name |-> varName,
value |-> varValue,
index |-> index]
Index(idx) ==
[realIndex |-> idx]
IsVar(var) ==
/\ "scope" \in DOMAIN var
/\ "name" \in DOMAIN var
/\ "value" \in DOMAIN var
/\ "index" \in DOMAIN var
IsArray(var) ==
/\ IsVar(var)
/\ var.index.realIndex >= 0
\* We do it only to make TLC happy, as index could be an expression
IsIndex(var) ==
/\ "realIndex" \in DOMAIN var
IsLiteral(var) ==
/\ IsVar(var)
/\ var.scope = "literal"
IsLocal(var) ==
/\ IsVar(var)
/\ var.scope = "local"
IsShared(var) ==
/\ IsVar(var)
/\ var.scope = "shared"
IsGlobal(var) ==
/\ IsVar(var)
/\ var.scope = "global"
IsVariable(var) ==
\/ IsLocal(var)
\/ IsShared(var)
\/ IsGlobal(var)
IsIntermediate(var) ==
/\ IsVar(var)
/\ var.scope = "intermediate"
GlobalInvocationId(tid) == tid-1
LocalInvocationId(tid) == GlobalInvocationId(tid) % WorkGroupSize
WorkGroupId(tid) == GlobalInvocationId(tid) \div WorkGroupSize
SubgroupId(tid) == LocalInvocationId(tid) \div SubgroupSize
SubgroupInvocationId(tid) == LocalInvocationId(tid) % SubgroupSize
ThreadsWithinWorkGroup(wgid) == {tid \in Threads : WorkGroupId(tid) = wgid}
ThreadsWithinWorkGroupNonTerminated(wgid) == {tid \in Threads : WorkGroupId(tid) = wgid /\ state[tid] # "terminated"}
ThreadsWithinSubgroup(sid, wgid) == {tid \in Threads : SubgroupId(tid) = sid} \intersect ThreadsWithinWorkGroup(wgid)
ThreadsWithinSubgroupNonTerminated(sid, wgid) == {tid \in Threads : SubgroupId(tid) = sid /\ state[tid] # "terminated"} \intersect ThreadsWithinWorkGroup(wgid)
NumSubgroupsPerWorkgroup == WorkGroupSize \div SubgroupSize
(* Expression *)
Inter(S) ==
{ x \in UNION S : \A t \in S : x \in t }
Range(f) == { f[x] : x \in DOMAIN f }
Max(S) == CHOOSE s \in S : \A t \in S : s >= t
Min(S) == CHOOSE s \in S : \A t \in S : s <= t
MinIndices(s, allowedIndices) ==
LET allowedValues == {s[i] : i \in DOMAIN s \cap allowedIndices}
minVal == IF allowedValues = {} THEN 1000
ELSE Min(allowedValues)
IN {i \in DOMAIN s \cap allowedIndices : s[i] = minVal}
Push(seq, x) ==
Append(seq, x)
\* For simplicity we can pop an empty stack
\* Which will be a noop
Pop(seq) ==
SubSeq(seq, 1, Len(seq)-1)
PopUntilBlock(seq, blockIdx) ==
LET idxSet == {i \in DOMAIN seq : seq[i].blockIdx = blockIdx}
IN
IF idxSet = {} THEN
seq
ELSE
SubSeq(seq, 1, Max(idxSet) - 1)
VarExists(workgroupId, var) ==
\* IF IsShared(var) \/ IsGlobal(var) THEN
IF IsGlobal(var) THEN
\E variable \in globalVars : variable.name = var.name
ELSE
\E variable \in threadLocals[workgroupId] : (variable.name = var.name /\ variable.scope = var.scope)
(* todo: resolve scope if duplicate name *)
GetVar(workgroupId, var) ==
IF IsGlobal(var) THEN
CHOOSE variable \in globalVars : variable.name = var.name
ELSE
CHOOSE variable \in threadLocals[workgroupId]: (variable.name = var.name /\ variable.scope = var.scope)
\* only mangling local and intermediate variables
Mangle(t, var) ==
IF var.scope = "local" THEN
Var(var.scope, Append(ToString(t), Append(var.scope, var.name)), var.value, var.index)
ELSE IF var.scope = "shared" THEN
Var(var.scope, Append(ToString(WorkGroupId(t)), Append(var.scope, var.name)), var.value, var.index)
ELSE IF var.scope = "intermediate" THEN
Var(var.scope, Append(ToString(t), Append(var.scope, var.name)), var.value, var.index)
ELSE
var
GetVal(workgroupId, var) ==
IF IsLiteral(var) THEN
var.value
ELSE IF VarExists(workgroupId, var) THEN
IF IsIndex(var.index) /\ var.index.realIndex >= 0 THEN
GetVar(workgroupId, var).value[var.index.realIndex]
ELSE
GetVar(workgroupId, var).value
ELSE
/\ Print("Don't has such variable", var)
/\ FALSE
(* Binary Expr *)
\* Mimic Lazy evaluation
BinaryExpr(Op, lhs, rhs) ==
[operator |-> Op,
left |-> lhs,
right |-> rhs]
LessThan(lhs, rhs) == lhs < rhs
LessThanOrEqual(lhs, rhs) == lhs <= rhs
GreaterThan(lhs, rhs) == lhs > rhs
GreaterThanOrEqual(lhs, rhs) == lhs >= rhs
Equal(lhs, rhs) == lhs = rhs
NotEqual(lhs, rhs) == lhs /= rhs
Plus(lhs, rhs) == lhs + rhs
Minus(lhs, rhs) == lhs - rhs
Multiply(lhs, rhs) == lhs * rhs
Indexing(lhs, idx) == lhs[idx]
BinarOpSet == {"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual", "Equal", "NotEqual", "Plus", "Minus", "Multiply", "Indexing"}
IsBinaryExpr(expr) ==
IF IsVar(expr) = TRUE THEN
FALSE
ELSE
/\ "operator" \in DOMAIN expr
/\ "left" \in DOMAIN expr
/\ "right" \in DOMAIN expr
/\ expr["operator"] \in BinarOpSet
(* Unary Expr *)
UnaryExpr(Op, rhs) == [operator |-> Op, right |-> rhs]
Not(rhs) ==
/\ IF rhs = FALSE THEN
TRUE
ELSE
FALSE
Neg(rhs) == -rhs
UnaryOpSet == {"Not", "Neg"}
IsUnaryExpr(expr) ==
IF IsVar(expr) THEN
FALSE
ELSE
/\ "operator" \in DOMAIN expr
/\ "right" \in DOMAIN expr
/\ expr["operator"] \in UnaryOpSet
IsExpression(var) ==
\/ IsBinaryExpr(var)
\/ IsUnaryExpr(var)
\* We have to delcare the recursive function before we can use it for mutual recursion
RECURSIVE ApplyBinaryExpr(_, _, _)
RECURSIVE ApplyUnaryExpr(_, _, _)
EvalExpr(t, workgroupId, expr) ==
IF IsIndex(expr) THEN
expr.realIndex
ELSE IF IsBinaryExpr(expr) = TRUE THEN
ApplyBinaryExpr(t, workgroupId, expr)
ELSE IF IsUnaryExpr(expr) = TRUE THEN
ApplyUnaryExpr(t, workgroupId, expr)
ELSE
GetVal(workgroupId, Mangle(t, expr))
\* GetVal(workgroupId, expr)
ApplyBinaryExpr(t, workgroupId, expr) ==
LET lhsValue == EvalExpr(t, workgroupId, expr["left"])
rhsValue == EvalExpr(t, workgroupId, expr["right"])
IN
IF expr["operator"] = "LessThan" THEN
LessThan(lhsValue, rhsValue)
ELSE IF expr["operator"] = "LessThanOrEqual" THEN
LessThanOrEqual(lhsValue, rhsValue)
ELSE IF expr["operator"] = "GreaterThan" THEN
GreaterThan(lhsValue, rhsValue)
ELSE IF expr["operator"] = "GreaterThanOrEqual" THEN
GreaterThanOrEqual(lhsValue, rhsValue)
ELSE IF expr["operator"] = "Equal" THEN
Equal(lhsValue, rhsValue)
ELSE IF expr["operator"] = "NotEqual" THEN
NotEqual(lhsValue, rhsValue)
ELSE IF expr["operator"] = "Plus" THEN
Plus(lhsValue, rhsValue)
ELSE IF expr["operator"] = "Minus" THEN
Minus(lhsValue, rhsValue)
ELSE IF expr["operator"] = "Multiply" THEN
Multiply(lhsValue, rhsValue)
ELSE IF expr["operator"] = "Indexing" THEN
Indexing(lhsValue, rhsValue)
ELSE
FALSE
ApplyUnaryExpr(t, workgroupId, expr) ==
/\ LET rhsValue == EvalExpr(t, workgroupId, expr["right"])
IN
/\ IF expr["operator"] = "Not" THEN
Not(rhsValue)
ELSE IF expr["operator"] = "Neg" THEN
Neg(rhsValue)
ELSE
FALSE
(* Thread Configuration *)
\* Table 1 / Sec. 4 instantiate SIMT-Step by statically partitioning instructions into independent,
\* synchronous, and collective sets. Many model extensions only need to adjust these sets and keep
\* MCThreads.ExecuteInstruction in sync with the resulting predicates.
InstructionSet == {"Assert", "Assignment", "OpAtomicLoad", "OpAtomicStore", "OpAtomicIncrement" , "OpAtomicDecrement", "OpGroupAll", "OpGroupAny", "OpGroupNonUniformAll", "OpGroupNonUniformAllEqual",
"OpGroupNonUniformAny", "OpGroupNonUniformBroadcast", "OpAtomicCompareExchange" ,"OpAtomicExchange", "OpBranch", "OpBranchConditional", "OpSwitch", "OpControlBarrier", "OpLoopMerge",
"OpSelectionMerge", "OpLabel", "Terminate", "OpLogicalOr", "OpLogicalAnd", "OpLogicalEqual", "OpLogicalNotEqual", "OpLogicalNot", "OpShiftLeftLogical", "OpShiftRightLogical", "OpBitcast", "OpBitwiseOr", "OpBitwiseAnd",
"OpEqual", "OpNotEqual", "OpLess", "OpLessOrEqual", "OpGreater", "OpGreaterOrEqual",
"OpAdd", "OpAtomicAdd", "OpSub", "OpAtomicSub", "OpAtomicOr", "OpAtomicAnd", "OpMul", "OpMod"}
VariableScope == {"global", "shared", "local", "literal", "intermediate"}
ScopeOperand == {"workgroup", "subgroup", "tangle"}
MemoryOperationSet == {"OpAtomicLoad", "OpAtomicStore", "OpAtomicIncrement" , "OpAtomicDecrement",
"OpAtomicAdd" , "OpAtomicSub", "OpAtomicCompareExchange" ,"OpAtomicExchange", "OpAtomicOr", "OpAtomicAnd"}
BranchInstructionSet == {"OpBranch", "OpBranchConditional", "OpSwitch"}
IsMemoryOperation(inst) ==
inst \in MemoryOperationSet
\* SIMT-Step subgroup collectives (always collective in every model).
SubgroupInstructionSet == {"OpGroupAll", "OpGroupAny", "OpGroupNonUniformAll", "OpGroupNonUniformAllEqual", "OpGroupNonUniformAny", "OpGroupNonUniformBroadcast"}
\* Per Table 1 in the paper: map the model label to its collective set.
CollectiveInstructionSet ==
LET base == SubgroupInstructionSet IN
CASE Synchronization = "CM" -> base \cup MemoryOperationSet \cup BranchInstructionSet \cup {"OpLabel"}
[] Synchronization = "SM" -> base \cup BranchInstructionSet \cup {"OpLabel"}
[] Synchronization = "SCF" -> base \cup BranchInstructionSet \cup {"OpLabel"}
[] Synchronization = "SSO" -> base
[] OTHER -> base
\* Only SM maps memory ops to the Arrive/Execute semantics (§4.2).
SynchronousInstructionSet ==
CASE Synchronization = "CM" -> {}
[] Synchronization = "SM" -> MemoryOperationSet
[] Synchronization = "SCF" -> {}
[] Synchronization = "SSO" -> {}
[] OTHER -> {}
IndependentInstructionSet == InstructionSet \ (CollectiveInstructionSet \cup SynchronousInstructionSet)
IsCollectiveInstruction(instr) == instr \in CollectiveInstructionSet
IsSynchronousInstruction(instr) == instr \in SynchronousInstructionSet
IsIndependentInstruction(instr) == instr \in IndependentInstructionSet
\* DynamicBlock is the implementation counterpart of the paper's dynamic block / dynamic basic
\* block object. labelIdx names the static basic block, id distinguishes multiple dynamic instances,
\* mergeStack implements the per-block merge-target stack from Sec. 4, sis records synchronous
\* instruction status, and the thread-set fields refine the paper's active/unknown participation sets.
DynamicBlock(sis, currentThreadSet, executeSet, notExecuteSet, unknownSet, labelIdx, id, mergeStack, children) ==
[
sis |-> sis,
currentThreadSet |-> currentThreadSet,
executeSet |-> executeSet,
notExecuteSet |-> notExecuteSet,
unknownSet |-> unknownSet,
labelIdx |-> labelIdx,
id |-> id,
mergeStack |-> mergeStack,
children |-> children
]
(* Program *)
EntryLabel == Min({idx \in 1..Len(ThreadInstructions[1]) : ThreadInstructions[1][idx] = "OpLabel"})
MaxInstructionIdx == Len(ThreadInstructions[1])
\* SIS keeps the Arrive/Execute flag for each workgroup, subgroup, and instruction (§4.2).
EmptySIS == [wg \in 1..NumWorkGroups |-> [sg \in 1..NumSubgroupsPerWorkgroup |-> [pc \in 1..MaxInstructionIdx |-> FALSE]]]
SetSISFlag(db, wgid, sg, pc, val) == [db EXCEPT !.sis[wgid][sg][pc] = val]
SubgroupIndex(tid) == SubgroupId(tid) + 1
ReplaceDB(DBSet, oldDB, newDB) == (DBSet \ {oldDB}) \union {newDB}
\* Helper: update the SIS flag for a particular workgroup/subgroup/pc entry.
SetSISInDB(DBSet, oldDB, wgid, sg, pc, val) == ReplaceDB(DBSet, oldDB, SetSISFlag(oldDB, wgid, sg, pc, val))
(* CFG *)
\* Synchronization == "Collective"
INSTANCE ProgramConf
(* Inovactions within a tangle are required to execute tangled instruction concurrently, examples or opGroup operations and opControlBarrier *)
TangledInstructionSet == {"OpControlBarrier, OpGroupAll", "OpGroupAny", "OpGroupNonUniformAll", "OpGroupNonUniformAllEqual", "OpGroupNonUniformAny", "OpGroupNonUniformBroadcast"}
MergedInstructionSet == {"OpLoopMerge", "OpSelectionMerge"}
BlockTerminationInstructionSet == {"OpBranch", "OpBranchConditional", "OpSwitch", "Terminate"}
ConstructTypeSet == {"Selection", "Loop", "Switch", "Continue", "Case"}
\* Tangle:
Tangle(ts) ==
[threads |-> ts]
OrderSet(set) == CHOOSE seq \in [1..Cardinality(set) -> set]: Range(seq) = set
\* make non-order-sensitive sequence becomes enumerable
SeqToSet(seq) == { seq[i]: i \in 1..Len(seq) }
\* update the sequence of sets
newSeqOfSets(seq, idx, newSet) == [seq EXCEPT ![idx] = newSet]
\* BoundedSeq: return a set of all sequences of length at most n, this helps to make the sequence enumerable
BoundedSeq(S, N) == UNION { [1..n -> S]: n \in 0..N}
\* helper function to extract the OpLabel field from the block
ExtractOpLabelIdxSet(blocks) ==
{blocks[blockIdx].opLabelIdx : blockIdx \in 1..Len(blocks)}
\* mergeBlock is the current merge block,
\* return header block for current merge block
FindHeaderBlock(blocks, mBlock) ==
CHOOSE block \in SeqToSet(blocks) : mBlock.opLabelIdx = block.mergeBlock
(* Helper function to find the block that starts with the given index to OpLabel *)
FindBlockbyOpLabelIdx(blocks, index) ==
CHOOSE block \in SeqToSet(blocks): block.opLabelIdx = index
(* Helper function to find the block that ends with the given index to termination instruction *)
FindBlockByTerminationIns(blocks, index) ==
CHOOSE block \in SeqToSet(blocks): block.terminatedInstrIdx = index
GetSwitchTargets(block) ==
LET
switchInstrIdx == block.terminatedInstrIdx
switchTargets == {GetVal(-1, ThreadArguments[1][switchInstrIdx][i]) : i \in 2..Len(ThreadArguments[1][switchInstrIdx])}
IN
switchTargets
\* function to determine if the merge instruction contains the given label as operand
\* mergeInsIdx is the pc of the merge instruction
\* opLabel is the value(label) that we are looking for
MergeInstContainsLabel(mergeInsIdx, opLabel) ==
IF ThreadInstructions[1][mergeInsIdx] = "OpLoopMerge" THEN
ThreadArguments[1][mergeInsIdx][1].name = opLabel \/ ThreadArguments[1][mergeInsIdx][2].name = opLabel
ELSE IF ThreadInstructions[1][mergeInsIdx] = "OpSelectionMerge" THEN
ThreadArguments[1][mergeInsIdx][1].name = opLabel
ELSE
FALSE
MergeInstContainsLabelIdx(mergeInsIdx, opLabelIdx) ==
IF ThreadInstructions[1][mergeInsIdx] = "OpLoopMerge" THEN
GetVal(-1, ThreadArguments[1][mergeInsIdx][1]) = opLabelIdx
\/ GetVal(-1, ThreadArguments[1][mergeInsIdx][2]) = opLabelIdx
ELSE IF ThreadInstructions[1][mergeInsIdx] = "OpSelectionMerge" THEN
GetVal(-1, ThreadArguments[1][mergeInsIdx][1]) = opLabelIdx
ELSE
FALSE
IsTerminationInstruction(instr) ==
instr \in BlockTerminationInstructionSet
IsBranchInstruction(instr) ==
instr \in BranchInstructionSet
IsMergedInstruction(instr) ==
instr \in MergedInstructionSet
IsOpLabel(instr) ==
instr = "OpLabel"
IsMergeBlock(blockIdx) ==
/\ \E construct \in ControlFlowConstructs : construct.mergeBlock = blockIdx
IsConstructHeaderBlock(blockIdx) ==
/\ \E construct \in ControlFlowConstructs : construct.headerBlock = blockIdx
IsHeaderBlock(block) ==
block.mergeBlock # -1
IsLoopHeaderBlock(block) ==
/\ IsHeaderBlock(block)
/\ block.constructType = "Loop"
IsContinueBlock(blockIdx) ==
/\ \E construct \in ControlFlowConstructs : construct.constructType = "Loop" /\ construct.continueTarget = blockIdx
IsContinueBlockOf(currentBlock, headerBlock) ==
/\ IsLoopHeaderBlock(headerBlock)
/\ IsMergeBlock(currentBlock.opLabelIdx)
/\ headerBlock.continueBlock = currentBlock.opLabelIdx
IsExitBlock(block) ==
IsTerminationInstruction(block.terminatedInstrIdx)
(* Helper function to find the block that contains the given index *)
FindCurrentBlock(blocks, index) ==
CHOOSE block \in SeqToSet(blocks): block.opLabelIdx <= index /\ block.terminatedInstrIdx >= index
\* lookback function that helps to determine if the current block is a merge block
\* startIdx is the pc of the instruction(OpLabel) that starts the current block
DetermineBlockType(startIdx) ==
IF \E instIdx \in 1..(startIdx-1):
IsMergedInstruction(ThreadInstructions[1][instIdx])
/\ MergeInstContainsLabelIdx(instIdx, startIdx)
THEN
TRUE
ELSE
FALSE
\* it is only possible for a thread to be in one DB at a time
CurrentDynamicBlock(wgid, tid) ==
CHOOSE DB \in DynamicBlockSet : tid \in DB.currentThreadSet[wgid]
FindDB(labelIdx) ==
CHOOSE DB \in DynamicBlockSet : DB.labelIdx = labelIdx
IsMergeBlockOfLoop(blockIdx) ==
/\ \E construct \in ControlFlowConstructs : construct.constructType = "Loop" /\ construct.mergeBlock = blockIdx
GetConstructOfLoop(mergeBlockIdx) ==
CHOOSE construct \in ControlFlowConstructs : construct.constructType = "Loop" /\ construct.mergeBlock = mergeBlockIdx
BlocksInSameLoopConstruct(headerIdx, mergeIdx) ==
CHOOSE construct \in ControlFlowConstructs : construct.constructType = "Loop" /\ construct.headerBlock = headerIdx /\ construct.mergeBlock = mergeIdx
IsBlockWithinLoop(blockIdx) ==
LET matchingConstructs == {c \in ControlFlowConstructs : blockIdx \in c.blocks}
IN
/\ matchingConstructs # {}
/\ \E c \in matchingConstructs : c.constructType = "Loop"
\* This function is useful because it helps to determine the blocks that are being affeced by the change of tangle of current block
BlocksInSameConstruct(mergeIdx) ==
CHOOSE construct \in ControlFlowConstructs : construct.mergeBlock = mergeIdx
UniqueBlockId(blockIdx, counter) ==
[blockIdx |-> blockIdx,
counter |-> counter]
Iteration(blockIdx, iter) ==
[blockIdx |-> blockIdx,
iter |-> iter]
FindIteration(blockIdx, iterationsVec, tid) ==
IF Len(iterationsVec) = 0
THEN
Iteration(blockIdx, 0)
ELSE IF iterationsVec[Len(iterationsVec)].blockIdx = blockIdx
THEN
iterationsVec[Len(iterationsVec)]
ELSE
Iteration(blockIdx, 0)
SameMergeStack(left, mergeBlock) ==
IF Len(mergeBlock) = 0 THEN
TRUE
ELSE IF Len(left) >= Len(mergeBlock) THEN
SubSeq(left, 1, Len(mergeBlock)) = mergeBlock
ELSE
FALSE
SameSwitchHeader(targetDB, currentDB) ==
/\ \E DB \in DynamicBlockSet :
\* find DB that is the switch header block
/\ \E construct \in ControlFlowConstructs :
/\ construct.constructType = "Switch"
/\ construct.headerBlock = DB.labelIdx
\* and contains the target DB as its child
/\ \E child \in DB.children : child.blockIdx = targetDB.labelIdx /\ child.counter = targetDB.id
\* and contains the current DB as its child
/\ \E child \in DB.children : child.blockIdx = currentDB.labelIdx /\ child.counter = currentDB.id
FindSwitchHeader(block) ==
CHOOSE DB \in DynamicBlockSet :
\E construct \in ControlFlowConstructs :
/\ construct.constructType = "Switch"
/\ construct.headerBlock = DB.labelIdx
/\ construct.mergeBlock = DB.mergeStack[Len(DB.mergeStack)].blockIdx
SameIterationVector(left, right) ==
/\ Len(left) = Len(right)
/\ \A idx \in 1..Len(left):
/\ left[idx].blockIdx = right[idx].blockIdx
/\ left[idx].iter = right[idx].iter
CanMergeSameIterationVector(curr, remaining) ==
\E idx \in 1..Len(remaining):
SameIterationVector(curr, remaining[idx])
\* Branch evolution (SIMT-Step §4): updates dynamic blocks when a thread takes a branch.
\* This is the thread-local control-flow path: it updates the dynamic execution graph when a single
\* thread leaves a dynamic block. If a new model changes when branches/labels/merges should be
\* collective, inspect this operator together with BranchConditionalUpdateSubgroup below.
BranchUpdate(wgid, t, pc, opLabelIdxSet, chosenBranchIdx, falseLabels) ==
LET
currentCounter == globalCounter
currentBranchOptions == OrderSet(opLabelIdxSet)
currentDB == CurrentDynamicBlock(wgid, t)
falseLabelIdxSet == falseLabels \ {chosenBranchIdx}
labelIdxSet == {DB.labelIdx : DB \in DynamicBlockSet}
choosenBlock == FindBlockbyOpLabelIdx(Blocks, chosenBranchIdx)
currentBlock == FindBlockbyOpLabelIdx(Blocks, currentDB.labelIdx)
currentChildren == currentDB.children
currentMergeStack == currentDB.mergeStack
\* it determines if the current db has already created the dynamic block for branching
childrenContainsAllBranchDB == \A i \in 1..Len(currentBranchOptions):
\E child \in currentChildren: child.blockIdx = currentBranchOptions[i]
isHeaderBlock == IsHeaderBlock(currentBlock)
isMergeBlock == IsMergeBlock(currentBlock.opLabelIdx)
\* check if current header block already has a merge block
mergeStackContainsCurrent == isHeaderBlock /\ Len(currentMergeStack) # 0 /\ currentMergeStack[Len(currentMergeStack)].blockIdx = currentBlock.mergeBlock
updatedMergeStack ==
IF mergeStackContainsCurrent \/ isHeaderBlock = FALSE THEN
currentMergeStack
ELSE
Push(currentMergeStack, UniqueBlockId(currentBlock.mergeBlock, currentCounter + 1))
\* update the children if firstly reach the divergence
\* otherwise keep as it is
counterAfterMergeStack ==
IF isHeaderBlock = FALSE \/ mergeStackContainsCurrent THEN
currentCounter
ELSE
currentCounter + 1
updatedChildren ==
IF childrenContainsAllBranchDB THEN
currentChildren
ELSE
currentChildren \union
{
IF IsMergeBlock(currentBranchOptions[i]) /\ \E index \in DOMAIN updatedMergeStack: updatedMergeStack[index].blockIdx = currentBranchOptions[i]
THEN
UniqueBlockId(currentBranchOptions[i], updatedMergeStack[(CHOOSE index \in DOMAIN updatedMergeStack: updatedMergeStack[index].blockIdx = currentBranchOptions[i])].counter)
\* treat switch construct specially
ELSE IF \E DB \in DynamicBlockSet: DB.labelIdx = currentBranchOptions[i] /\ SameSwitchHeader(DB, currentDB) THEN
UniqueBlockId(currentBranchOptions[i], (CHOOSE DB \in DynamicBlockSet: DB.labelIdx = currentBranchOptions[i] /\ SameSwitchHeader(DB, currentDB)).id)
ELSE
UniqueBlockId(currentBranchOptions[i], counterAfterMergeStack + i)
: i \in 1..Len(currentBranchOptions)
}
updatedCounter == currentCounter + Cardinality(updatedChildren) - Cardinality(currentChildren) + Len(updatedMergeStack) - Len(currentMergeStack)
mergeBlock == currentBlock.mergeBlock
\* exsiting dynamic blocks for false labels
existingFalseLabelIdxSet == {
falselabelIdx \in falseLabelIdxSet:
\E DB \in DynamicBlockSet: DB.labelIdx = falselabelIdx /\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
}
\* we want to update the blocks in construct if choosen block is merge block
constructUpdate ==
IF IsMergeBlock(chosenBranchIdx) THEN
LET construct == BlocksInSameConstruct(chosenBranchIdx)
IN
construct.blocks \union {construct.continueTarget}
ELSE
{}
\* this is set of all threads that are not terminated and still in the current construct
unionSet ==
[wg \in 1..NumWorkGroups |-> currentDB.currentThreadSet[wg] \union currentDB.executeSet[wg] \union currentDB.notExecuteSet[wg] \union currentDB.unknownSet[wg]]
IN
<< updatedCounter,
\* update the existing dynamic blocks
{
\* if the constructUpdate is not empty, it means we are exiting a construct, all the dynamic blocks in that construct should be properly updated
\* remove current thread from all set as it is not partcipating in the construct anymore
IF DB.labelIdx \in constructUpdate /\ SameMergeStack(DB.mergeStack, currentMergeStack) THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \ {t}],
[ DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \ {t}],
[ DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \ {t}],
[ DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ {t}],
DB.labelIdx,
DB.id,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedMergeStack
ELSE
DB.mergeStack
,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedChildren
ELSE
DB.children)
\* if encounter current dynamic block
ELSE IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \ {t}],
DB.executeSet,
DB.notExecuteSet,
DB.unknownSet,
DB.labelIdx,
DB.id,
updatedMergeStack,
updatedChildren)
\* if encounter choosen dynamic block
\* whether its in current DB's children or on the top of the merge stack, we update it
ELSE IF DB.labelIdx = chosenBranchIdx
/\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \union {t}],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \union {t}],
DB.notExecuteSet,
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ {t}],
DB.labelIdx,
DB.id,
DB.mergeStack,
DB.children)
\* Encounter the block that is not choosen by the branch instruction
\* we don't update the existing set for merge block as threads will eventually reach there unless they terminate early
ELSE IF DB.labelIdx \in falseLabelIdxSet
/\ IsMergeBlock(DB.labelIdx) = FALSE
/\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
THEN
DynamicBlock(DB.sis,
DB.currentThreadSet,
DB.executeSet,
[DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \union {t}],
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ {t}],
DB.labelIdx,
DB.id,
DB.mergeStack,
DB.children)
ELSE
DB
: DB \in DynamicBlockSet
}
\* union with the new true branch DB if does not exist
\union
(
IF \E DB \in DynamicBlockSet:
DB.labelIdx = chosenBranchIdx /\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
THEN
{}
ELSE
IF chosenBranchIdx \in constructUpdate THEN
{DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN unionSet[wgid] \ {t} ELSE unionSet[wg]],
chosenBranchIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = chosenBranchIdx
IN
child.counter,
updatedMergeStack,
{})
}
\* if the choosen block is a merge block , we need to pop the merge stack of current DB.
ELSE IF IsMergeBlock(chosenBranchIdx) THEN
{
DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN {t} ELSE {}],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN {t} ELSE {}],
[wg \in 1..NumWorkGroups |-> {}],
\* [wg \in 1..NumWorkGroups |-> IF wg = wgid THEN ThreadsWithinWorkGroupNonTerminated(wgid-1) \ {t} ELSE ThreadsWithinWorkGroupNonTerminated(wg-1)],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN unionSet[wgid] \ {t} ELSE unionSet[wg]],
chosenBranchIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = chosenBranchIdx
IN
child.counter,
PopUntilBlock(updatedMergeStack, chosenBranchIdx),
{}
)
}
ELSE
{
DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN {t} ELSE {}],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN {t} ELSE {}],
\* [wg \in 1..NumWorkGroups |-> DB.notExecuteSet[wg]],
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN unionSet[wgid] \ {t} ELSE unionSet[wg]],
chosenBranchIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = chosenBranchIdx
IN
child.counter,
updatedMergeStack,
{})
}
)
\* union with the new false branch DB if does not exist
\union
(
{
\* thread is exiting the construct, we also need to create a new dynamic block for false label and remove current thread from all sets of new block.
IF falselabelIdx \in constructUpdate THEN
DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> {}],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN unionSet[wgid] \ {t} ELSE unionSet[wg]],
falselabelIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = falselabelIdx
IN
child.counter,
updatedMergeStack,
{})
\* if new false branch is merge block, we need to pop the merge stack of current DB.
ELSE IF IsMergeBlock(falselabelIdx) = TRUE THEN
DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> {}], \* currently no thread is executing the false block
[wg \in 1..NumWorkGroups |-> {}], \* currently no thread has executed the false block
\* We don't know if the threads executed in precedessor DB will execute the block or not
[wg \in 1..NumWorkGroups |-> {}],
\* we don't know if the threads executed in precedessor DB will execute the block or not
\* [wg \in 1..NumWorkGroups |-> ThreadsWithinWorkGroupNonTerminated(wg-1)],
[wg \in 1..NumWorkGroups |-> unionSet[wg]],
falselabelIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = falselabelIdx
IN
child.counter,
PopUntilBlock(updatedMergeStack, falselabelIdx),
{})
ELSE
DynamicBlock(EmptySIS,
[wg \in 1..NumWorkGroups |-> {}], \* currently no thread is executing the false block
[wg \in 1..NumWorkGroups |-> {}], \* currently no thread has executed the false block
\* current thread is not executed in the false block, but we don't know if the threads executed in precedessor DB will execute the block or not
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN {t} ELSE {}],
\* we don't know if the threads executed in precedessor DB will execute the block or not
\* [wg \in 1..NumWorkGroups |-> IF wg = wgid THEN ThreadsWithinWorkGroupNonTerminated(wgid-1) \ {t} ELSE ThreadsWithinWorkGroupNonTerminated(wg-1)],
[wg \in 1..NumWorkGroups |-> IF wg = wgid THEN unionSet[wgid] \ {t} ELSE unionSet[wg]],
falselabelIdx,
LET child == CHOOSE child \in updatedChildren: child.blockIdx = falselabelIdx
IN
child.counter,
updatedMergeStack,
{})
: falselabelIdx \in (falseLabelIdxSet \ existingFalseLabelIdxSet)
}
)>>
\* Collective control flow
\* Subgroup-wide counterpart of BranchUpdate, corresponding to the paper's collective control-flow
\* rules where aligned active threads leave and enter basic blocks together and the child dynamic
\* blocks are created with known participation.
BranchConditionalUpdateSubgroup(wgid, active_subgroup_threads, pc, opLabelIdxSet, trueThreads, falseThreads, trueLabelVal, falseLabelVal) ==
LET
currentCounter == globalCounter
currentBranchOptions == OrderSet(opLabelIdxSet)
\* Use any thread from the subgroup to get current dynamic block (they should all be in the same block)
representative_thread == CHOOSE t \in active_subgroup_threads: TRUE
currentDB == CurrentDynamicBlock(wgid, representative_thread)
falseLabelIdxSet == IF falseThreads = {} THEN
{}
ELSE
opLabelIdxSet \ {trueLabelVal, falseLabelVal}
labelIdxSet == {DB.labelIdx : DB \in DynamicBlockSet}
choosenTrueBlock == FindBlockbyOpLabelIdx(Blocks, trueLabelVal)
choosenFalseBlock == IF falseThreads = {} THEN
[
opLabelIdx |-> -1,
terminatedInstrIdx |-> -1,
tangle |-> <<{}>>,
merge |-> FALSE,
initialized |-> <<TRUE>>,
constructType |-> "Selection",
mergeBlock |-> -1,
continueBlock |-> -1,
defaultBlock |-> -1,
caseBlocks |-> <<>>
]
ELSE
FindBlockbyOpLabelIdx(Blocks, falseLabelVal)
currentBlock == FindBlockbyOpLabelIdx(Blocks, currentDB.labelIdx)
currentChildren == currentDB.children
currentMergeStack == currentDB.mergeStack
\* it determines if the current db has already created the dynamic block for branching
childrenContainsAllBranchDB == \A i \in 1..Len(currentBranchOptions):
\E child \in currentChildren: child.blockIdx = currentBranchOptions[i]
isHeaderBlock == IsHeaderBlock(currentBlock)
isMergeBlock == IsMergeBlock(currentBlock.opLabelIdx)
\* check if current header block already has a merge block
mergeStackContainsCurrent == isHeaderBlock /\ Len(currentMergeStack) # 0 /\ currentMergeStack[Len(currentMergeStack)].blockIdx = currentBlock.mergeBlock
updatedMergeStack ==
IF mergeStackContainsCurrent \/ isHeaderBlock = FALSE THEN
currentMergeStack
ELSE
Push(currentMergeStack, UniqueBlockId(currentBlock.mergeBlock, currentCounter + 1))
\* update the children if firstly reach the divergence
counterAfterMergeStack ==
IF isHeaderBlock = FALSE \/ mergeStackContainsCurrent THEN
currentCounter
ELSE
currentCounter + 1
updatedChildren ==
IF childrenContainsAllBranchDB THEN
currentChildren
ELSE
currentChildren \union
{
IF IsMergeBlock(currentBranchOptions[i]) /\ \E index \in DOMAIN updatedMergeStack: updatedMergeStack[index].blockIdx = currentBranchOptions[i]
THEN
UniqueBlockId(currentBranchOptions[i], updatedMergeStack[(CHOOSE index \in DOMAIN updatedMergeStack: updatedMergeStack[index].blockIdx = currentBranchOptions[i])].counter)
\* treat switch construct specially
ELSE IF \E DB \in DynamicBlockSet: DB.labelIdx = currentBranchOptions[i] /\ SameSwitchHeader(DB, currentDB) THEN
UniqueBlockId(currentBranchOptions[i], (CHOOSE DB \in DynamicBlockSet: DB.labelIdx = currentBranchOptions[i] /\ SameSwitchHeader(DB, currentDB)).id)
ELSE
UniqueBlockId(currentBranchOptions[i], counterAfterMergeStack + i)
: i \in 1..Len(currentBranchOptions)
}
\* We only update the merge stack if the current block is a header block and if firstly reach the divergence
\* globalCounter is only updated when we firstly reach the divergence
updatedCounter == currentCounter + Cardinality(updatedChildren) - Cardinality(currentChildren) + Len(updatedMergeStack) - Len(currentMergeStack)
mergeBlock == currentBlock.mergeBlock
\* existing dynamic blocks for false labels (not chosen by any thread)
existingFalseLabelIdxSet == {
falselabelIdx \in falseLabelIdxSet:
\E DB \in DynamicBlockSet: DB.labelIdx = falselabelIdx /\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
}
\* we want to update the blocks in construct if choosen block is merge block
constructUpdateTrue ==
IF IsMergeBlock(choosenTrueBlock.opLabelIdx) THEN
LET construct == BlocksInSameConstruct(choosenTrueBlock.opLabelIdx)
IN
construct.blocks \union {construct.continueTarget}
ELSE
{}
constructUpdateFalse ==
IF IsMergeBlock(choosenFalseBlock.opLabelIdx) THEN
LET construct == BlocksInSameConstruct(choosenFalseBlock.opLabelIdx)
IN
construct.blocks \union {construct.continueTarget}
ELSE
{}
\* this is set of all threads that are not terminated and still in the current construct
unionSet ==
[wg \in 1..NumWorkGroups |-> currentDB.currentThreadSet[wg] \union currentDB.executeSet[wg] \union currentDB.notExecuteSet[wg] \union currentDB.unknownSet[wg]]
IN
<< updatedCounter,
\* update the existing dynamic blocks
{
\* if the constructUpdate is not empty for true branch, remove true threads from construct blocks
IF DB.labelIdx \in constructUpdateTrue /\ SameMergeStack(DB.mergeStack, currentMergeStack) THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \ trueThreads],
[ DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \ trueThreads],
[ DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \ trueThreads],
[ DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ trueThreads],
DB.labelIdx,
DB.id,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedMergeStack
ELSE
DB.mergeStack,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedChildren
ELSE
DB.children)
\* if the constructUpdate is not empty for false branch, remove false threads from construct blocks
ELSE IF DB.labelIdx \in constructUpdateFalse /\ SameMergeStack(DB.mergeStack, currentMergeStack) THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \ falseThreads],
[ DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \ falseThreads],
[ DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \ falseThreads],
[ DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ falseThreads],
DB.labelIdx,
DB.id,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedMergeStack
ELSE
DB.mergeStack,
IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
updatedChildren
ELSE
DB.children)
\* if encounter current dynamic block, remove all active threads
ELSE IF DB.labelIdx = currentDB.labelIdx /\ DB.id = currentDB.id THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \ active_subgroup_threads],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \ active_subgroup_threads],
[DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \ active_subgroup_threads],
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ active_subgroup_threads],
DB.labelIdx,
DB.id,
updatedMergeStack,
updatedChildren)
\* if encounter true branch dynamic block, add true threads
ELSE IF DB.labelIdx = trueLabelVal
/\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
THEN
IF IsMergeBlock(trueLabelVal) THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \union trueThreads],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \union trueThreads],
DB.notExecuteSet,
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ trueThreads],
DB.labelIdx,
DB.id,
DB.mergeStack,
DB.children)
ELSE
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \union trueThreads],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \union trueThreads],
[DB.notExecuteSet EXCEPT ![wgid] = DB.notExecuteSet[wgid] \union falseThreads],
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ active_subgroup_threads],
DB.labelIdx,
DB.id,
DB.mergeStack,
DB.children)
\* if encounter false branch dynamic block, add false threads
ELSE IF DB.labelIdx = falseLabelVal
/\ \E child \in updatedChildren: child.blockIdx = DB.labelIdx /\ child.counter = DB.id
THEN
IF IsMergeBlock(falseLabelVal) THEN
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \union falseThreads],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \union falseThreads],
DB.notExecuteSet,
[DB.unknownSet EXCEPT ![wgid] = DB.unknownSet[wgid] \ falseThreads],
DB.labelIdx,
DB.id,
DB.mergeStack,
DB.children)
ELSE
DynamicBlock(DB.sis,
[DB.currentThreadSet EXCEPT ![wgid] = DB.currentThreadSet[wgid] \union falseThreads],
[DB.executeSet EXCEPT ![wgid] = DB.executeSet[wgid] \union falseThreads],