Skip to content

Commit 5cfa07a

Browse files
authored
Fix incorrect odd parity calculation in control packet header (#1122)
1 parent 181e901 commit 5cfa07a

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/test/control_packet_to_half_dma_cpy_nd.mlir

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module attributes {hal.executable.target = #executable_target_amdaie_xclbin_fb}
3232

3333
// -----
3434

35-
// CHECK: 0x80032000
35+
// CHECK: 0x00032000
3636
// CHECK: 0x00000000
3737
// CHECK-LABEL: @write_one_word_data
3838
// CHECK: %[[C0:.*]] = arith.constant 0 : index
@@ -130,94 +130,94 @@ module attributes {hal.executable.target = #executable_target_amdaie_xclbin_fb}
130130
%1 = amdaie.logicalobjectfifo.placeholder{%tile_0_2} : !amdaie.logicalobjectfifo<memref<?xi32>>
131131
%2 = amdaie.connection(%1 {%channel_0}, %0 {%channel}) {connection_type = #amdaie<connection_type Packet>} : (!amdaie.logicalobjectfifo<memref<?xi32>>, !amdaie.logicalobjectfifo<memref<?xi32>>)
132132
amdaie.controlcode {
133-
// CHECK: 0x80032000
133+
// CHECK: 0x00032000
134134
// CHECK: 0x00000000
135135
amdaie.npu.control_packet write {address = 2301952 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
136-
// CHECK: 0x0001DE10
136+
// CHECK: 0x8001DE10
137137
// CHECK: 0x00000002
138138
amdaie.npu.control_packet write {address = 2219536 : ui32, data = array<i32: 2>, length = 1 : ui32, stream_id = 0 : ui32}
139-
// CHECK: 0x8001DE18
139+
// CHECK: 0x0001DE18
140140
// CHECK: 0x00000002
141141
amdaie.npu.control_packet write {address = 2219544 : ui32, data = array<i32: 2>, length = 1 : ui32, stream_id = 0 : ui32}
142-
// CHECK: 0x8001DE00
142+
// CHECK: 0x0001DE00
143143
// CHECK: 0x00000002
144144
amdaie.npu.control_packet write {address = 2219520 : ui32, data = array<i32: 2>, length = 1 : ui32, stream_id = 0 : ui32}
145-
// CHECK: 0x0001DE08
145+
// CHECK: 0x8001DE08
146146
// CHECK: 0x00000002
147147
amdaie.npu.control_packet write {address = 2219528 : ui32, data = array<i32: 2>, length = 1 : ui32, stream_id = 0 : ui32}
148-
// CHECK: 0x80320000
148+
// CHECK: 0x00320000
149149
// CHECK: 0x20000115
150150
// CHECK: 0x00550000
151151
// CHECK: 0x00070CE0
152152
// CHECK: 0x00010001
153153
amdaie.npu.control_packet write {address = 2228224 : ui32, data = array<i32: 536871189, 5570560, 462048, 65537>, length = 4 : ui32, stream_id = 0 : ui32}
154-
// CHECK: 0x00320010
154+
// CHECK: 0x80320010
155155
// CHECK: 0x00010001
156156
// CHECK: 0x00038837
157157
// CHECK: 0x00000000
158158
// CHECK: 0x00000000
159159
amdaie.npu.control_packet write {address = 2228240 : ui32, data = array<i32: 65537, 231479, 0, 0>, length = 4 : ui32, stream_id = 0 : ui32}
160-
// CHECK: 0x00320020
160+
// CHECK: 0x80320020
161161
// CHECK: 0x000388B7
162162
// CHECK: 0x000000C0
163163
// CHECK: 0x00000000
164164
// CHECK: 0x00010001
165165
amdaie.npu.control_packet write {address = 2228256 : ui32, data = array<i32: 231607, 192, 0, 65537>, length = 4 : ui32, stream_id = 0 : ui32}
166-
// CHECK: 0x80320030
166+
// CHECK: 0x00320030
167167
// CHECK: 0x180010BB
168168
// CHECK: 0x080001C0
169169
// CHECK: 0x80190000
170170
// CHECK: 0x00010802
171171
amdaie.npu.control_packet write {address = 2228272 : ui32, data = array<i32: 402657467, 134218176, -2145845248, 67586>, length = 4 : ui32, stream_id = 0 : ui32}
172-
// CHECK: 0x00320040
172+
// CHECK: 0x80320040
173173
// CHECK: 0x10000115
174174
// CHECK: 0x20190000
175175
// CHECK: 0x7E993803
176176
// CHECK: 0xC2990FFC
177177
amdaie.npu.control_packet write {address = 2228288 : ui32, data = array<i32: 268435733, 538509312, 2123970563, -1030156292>, length = 4 : ui32, stream_id = 0 : ui32}
178-
// CHECK: 0x80320050
178+
// CHECK: 0x00320050
179179
// CHECK: 0xF6590FFC
180180
// CHECK: 0x48BB1F3C
181181
// CHECK: 0x10081803
182182
// CHECK: 0xFFC67000
183183
amdaie.npu.control_packet write {address = 2228304 : ui32, data = array<i32: -161935364, 1220222780, 268965891, -3772416>, length = 4 : ui32, stream_id = 0 : ui32}
184-
// CHECK: 0x80320060
184+
// CHECK: 0x00320060
185185
// CHECK: 0x10000819
186186
// CHECK: 0x00010001
187187
// CHECK: 0x00010001
188188
// CHECK: 0xC2D90001
189189
amdaie.npu.control_packet write {address = 2228320 : ui32, data = array<i32: 268437529, 65537, 65537, -1025966079>, length = 4 : ui32, stream_id = 0 : ui32}
190-
// CHECK: 0x00320070
190+
// CHECK: 0x80320070
191191
// CHECK: 0x000107FC
192192
// CHECK: 0x00010001
193193
// CHECK: 0x00010001
194194
// CHECK: 0x07FC7ED9
195195
amdaie.npu.control_packet write {address = 2228336 : ui32, data = array<i32: 67580, 65537, 65537, 133988057>, length = 4 : ui32, stream_id = 0 : ui32}
196-
// CHECK: 0x00320080
196+
// CHECK: 0x80320080
197197
// CHECK: 0x10001819
198198
// CHECK: 0x00010001
199199
// CHECK: 0x00010001
200200
// CHECK: 0x3FFFE019
201201
amdaie.npu.control_packet write {address = 2228352 : ui32, data = array<i32: 268441625, 65537, 65537, 1073733657>, length = 4 : ui32, stream_id = 0 : ui32}
202-
// CHECK: 0x0001DE10
202+
// CHECK: 0x8001DE10
203203
// CHECK: 0x00000000
204204
amdaie.npu.control_packet write {address = 2219536 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
205-
// CHECK: 0x8001DE18
205+
// CHECK: 0x0001DE18
206206
// CHECK: 0x00000000
207207
amdaie.npu.control_packet write {address = 2219544 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
208-
// CHECK: 0x8001DE00
208+
// CHECK: 0x0001DE00
209209
// CHECK: 0x00000000
210210
amdaie.npu.control_packet write {address = 2219520 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
211-
// CHECK: 0x0001DE08
211+
// CHECK: 0x8001DE08
212212
// CHECK: 0x00000000
213213
amdaie.npu.control_packet write {address = 2219528 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
214-
// CHECK: 0x80032000
214+
// CHECK: 0x00032000
215215
// CHECK: 0x00000002
216216
amdaie.npu.control_packet write {address = 2301952 : ui32, data = array<i32: 2>, length = 1 : ui32, stream_id = 0 : ui32}
217-
// CHECK: 0x80032000
217+
// CHECK: 0x00032000
218218
// CHECK: 0x00000000
219219
amdaie.npu.control_packet write {address = 2301952 : ui32, data = array<i32: 0>, length = 1 : ui32, stream_id = 0 : ui32}
220-
// CHECK: 0x80032000
220+
// CHECK: 0x00032000
221221
// CHECK: 0x00000001
222222
amdaie.npu.control_packet write {address = 2301952 : ui32, data = array<i32: 1>, length = 1 : ui32, stream_id = 0 : ui32}
223223
amdaie.end

runtime/src/iree-amd-aie/aie_runtime/iree_aie_runtime.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,10 @@ FailureOr<uint32_t> AMDAIEDeviceModel::getCtrlPktHeader(
343343
(address << ctrlPktHeaderFormat.addressShift);
344344
// Mask to keep the lower 31 bits (bits 30:0).
345345
uint32_t lower31Bits = header & 0x7FFFFFFF;
346-
// Compute the odd parity bit (1 if the count of 1's is odd, 0 if even).
347-
uint32_t parity = llvm::popcount(lower31Bits) % 2;
346+
// Compute the odd parity bit. It is set to 1 if the number of 1's in
347+
// lower31Bits is even, ensuring the total count (including this bit) becomes
348+
// odd. Otherwise, it is set to 0.
349+
uint32_t parity = (llvm::popcount(lower31Bits) + 1) % 2;
348350
// Set the parity bit in the most significant bit (bit 31).
349351
return (parity << 31) | lower31Bits;
350352
}

0 commit comments

Comments
 (0)