Skip to content

Commit 924552e

Browse files
committed
closes #17
1 parent b771efd commit 924552e

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/computesim/core.nim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ const
140140
InvalidId* = high(uint32) # Sentinel value for empty/invalid
141141
142142
iterator threadsInGroup*(group: SubgroupThreadIDs): uint32 =
143-
var idx: uint32 = 0
144-
while group[idx] != InvalidId:
145-
yield group[idx]
146-
inc idx
143+
let length = group[0]
144+
for i in 1..length:
145+
yield group[i]

src/computesim/debug.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ proc formatThreadList(group: SubgroupThreadIDs): string =
3838
result.add("}")
3939

4040
proc formatThreadValues(group: SubgroupThreadIDs, commands: SubgroupCommands): string =
41-
let firstThreadId = group[0]
41+
let firstThreadId = group[1]
4242
let opKind = commands[firstThreadId].kind
4343
case opKind
4444
of subgroupBroadcast, subgroupBroadcastFirst, subgroupAdd, subgroupMin, subgroupMax,

src/computesim/lockstep.nim

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,27 +116,25 @@ proc runThreads*(threads: SubgroupThreads; workGroup: WorkGroupContext,
116116
(threadStates[threadId] == atSubBarrier and canReconverge) or canPassBarrier):
117117
var found = false
118118
for groupIdx in 0..<numGroups:
119-
let firstThreadId = threadGroups[groupIdx][0]
119+
let firstThreadId = threadGroups[groupIdx][1] # First thread is at index 1
120120
if commands[firstThreadId].id == commands[threadId].id:
121-
# Find first empty slot in group
122-
for slot in 0..<SubgroupSize:
123-
if threadGroups[groupIdx][slot] == InvalidId:
124-
threadGroups[groupIdx][slot] = threadId
125-
threadGroups[groupIdx][slot + 1] = InvalidId
126-
break
121+
let currentLen = threadGroups[groupIdx][0]
122+
threadGroups[groupIdx][currentLen + 1] = threadId
123+
threadGroups[groupIdx][0] = currentLen + 1
127124
found = true
128125
break
129126
if not found:
130-
threadGroups[numGroups][0] = threadId
131-
threadGroups[numGroups][1] = InvalidId
127+
# Create new group
128+
threadGroups[numGroups][0] = 1 # Length is 1
129+
threadGroups[numGroups][1] = threadId
132130
inc numGroups
133131

134132
template execSubgroupOp(op: untyped) =
135133
op(results, commands, threadGroups[groupIdx], firstThreadId, opId, showDebugOutput)
136134

137135
# Process operation groups
138136
for groupIdx in 0..<numGroups:
139-
let firstThreadId = threadGroups[groupIdx][0]
137+
let firstThreadId = threadGroups[groupIdx][1]
140138
let opKind = commands[firstThreadId].kind
141139
let opId = commands[firstThreadId].id
142140
case opKind:

0 commit comments

Comments
 (0)