<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55698>55698</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
AMDGPU/TeraScale: `Node emitted out of order - late` assertion with `clpeak`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
illwieckz
</td>
</tr>
</table>
<pre>
I'm currently running LLVM from commit 69f7f15683c451378dbe9029a0bd2dbd029bcf3a (very recent but old enough to avoid opaque pointer mismatch with mesa and other stuff) and Mesa from commit `b2b810ebff657b3d24d93a1fdbd6adc79bc38153`.
When running the `clpeak` OpenCL benchmark on R600/TeraScale devices, I get this assertion: ```llvm-project/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp:285: llvm::Register llvm::InstrEmitter::getVR(llvm::SDValue, lvm::DenseMap<llvm::SDValue, llvm::Register>&): Assertion `I != VRBaseMap.end() && "Node emitted out of order - late"' failed.```
The source code of the OpenCL benchmark:
- https://github.com/krrishnarraj/clpeak
I reproduced it on:
- AMD Radeon HD 6970 RV970 Cayman XT (TeraScale 3)
- AMD Radeon HD 5870 RV870 Cypress XT (TeraScale 2)
This is the errors I get:
```
$ clpeak -d 0
Platform: Clover
Device: AMD CAYMAN (DRM 2.50.0 / 5.13.0-44-generic, LLVM 15.0.0)
Driver version : 22.2.0-devel (Linux x64)
Compute units : 12
Clock frequency : 880 MHz
clpeak: llvm-project/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp:285: llvm::Register llvm::InstrEmitter::getVR(llvm::SDValue, llvm::DenseMap<llvm::SDValue, llvm::Register>&): Assertion `I != VRBaseMap.end() && "Node emitted out of order - late"' failed.
Aborted
$ clpeak -d 1
Platform: Clover
Device: AMD CYPRESS (DRM 2.50.0 / 5.13.0-44-generic, LLVM 15.0.0)
Driver version : 22.2.0-devel (Linux x64)
Compute units : 10
Clock frequency : 850 MHz
clpeak: llvm-project/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp:285: llvm::Register llvm::InstrEmitter::getVR(llvm::SDValue, llvm::DenseMap<llvm::SDValue, llvm::Register>&): Assertion `I != VRBaseMap.end() && "Node emitted out of order - late"' failed.
Aborted
```
For reference, this is what I get on GCN2 (assuming it works):
```
clpeak -d 0
Platform: Clover
Device: AMD Radeon R9 390 Series (hawaii, LLVM 15.0.0, DRM 3.41, 5.13.0-45-generic)
Driver version : 22.2.0-devel (Linux x64)
Compute units : 44
Clock frequency : 1080 MHz
Global memory bandwidth (GBPS)
float : 11.29
float2 : 11.28
float4 : 11.27
float8 : 10.57
float16 : 4.77
Single-precision compute (GFLOPS)
float : 5881.14
float2 : 5895.50
float4 : 5880.94
float8 : 5824.35
float16 : 5799.34
No half precision support! Skipped
Double-precision compute (GFLOPS)
double : 747.48
double2 : 749.21
double4 : 744.47
double8 : 742.23
double16 : 738.79
Integer compute (GIOPS)
int : 1946.12
int2 : 1960.41
int4 : 1975.52
int8 : 1945.99
int16 : 1977.48
Integer compute Fast 24bit (GIOPS)
int : 5566.71
int2 : 5400.64
int4 : 5528.86
int8 : 5435.56
int16 : 5298.62
Transfer bandwidth (GBPS)
enqueueWriteBuffer : 18.55
enqueueReadBuffer : 19.62
enqueueWriteBuffer non-blocking : 18.71
enqueueReadBuffer non-blocking : 19.38
enqueueMapBuffer(for read) : 32317.29
memcpy from mapped ptr : 19.53
enqueueUnmap(after write) : 32987.46
memcpy to mapped ptr : 18.72
Kernel launch latency : 67.25 us
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztWN1zmzgQ_2vsl51oQCA-Hvzg2E2auSTt2Gl6fRQgbBoscQLipn_9rTD4A5xk-nA3vZnzEGxY7fdPq91EKnmZ3Iyov4G41lrIKn8BXUuZyRXc3j7eQaoV0tRmk1Xghamf2swLnNhltuMHSSRCi4bcihKaRAn-jOLU4TCiwbPQKEnEKBKiugKVJyCkqldrq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