<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56366>56366</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`mgpuMemHostRegisterMemRef`'s descriptor argument's rank may be larger than one
</td>
</tr>
<tr>
<th>Labels</th>
<td>
bug,
mlir:gpu
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aqjune
</td>
</tr>
</table>
<pre>
https://github.com/llvm/llvm-project/blob/f7a80c3d08d4821e621fc88d6a2e435291f82dff/mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp#L175
The `descriptor`'s type specifies that its rank must be 1, but in runtime a memref value with any rank can be given to `gpu.host_register` (which invokes this function).
In this case, the memory layout of the `StridedMemRefType<char, 1>` struct type is different from the original struct type, causing the access to `descriptor->sizes[i]` in the below for loop to be out-of-bounds access and actually access `descriptor->strides`.
To address this, either `gpu.host_register` must only take one-dimensional memref only, or `mgpuMemHostRegisterMemRef`'s `descriptor` must be, e.g. `void*` and its interpretation must depend on the `rank` input.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVNtu2zgQ_Rr6hbBAUxfLD3pIc0ELtC_ZAH0sKHIkMaFIlRdnvV-_QylGsl0ssAUM0eRwzpxzZqTeqUs3xbgEUt4Q_oC_Uccp9YV0M26MOV-X_eLdM8iI2964HpfhKFomS8VaVbX8AA0_DLJtVSM4VGXNT4eh5WoY8OpstM84Oufd_wkyRe3svR21BTy5TUo8Jhv1DN-9WBbwoZDLQnj59XCsCbsj7GZ7Pk1AScMUBOn1Ep3HDeHHQONlARoWkHrQgNtJRKpjoF7YFzqnEGkP9ED4Le0TRiz1Wz0q6Ayzh4GehUlAX1E-FfayJUphc96oz2BpdLn0uKRiciH-8DDqECEzoIS3r5OWEwKf3ctaXwc6JCuzTsJPxUcRX-wWlyJAZhRRFJJw_kKNuDjk54b1EKH_iF4rUN9gfoThCUWS8lZOwue8Aynvc_UQfZJxswBhlR4G8GAjHbybVyDnNVotzMerGUGKFLQd1ztCSgjhTeW7wXssEvRfEEj9SZP6LhfUds3owbhXOjhPjXNLzkSvkP7eDfveJavCFVRYhX9jEsZcrmf_rrJKDXj-D7eeHBVK-ZUbupZpAzYJ_H92Y223s1gqihdkZGGvsNU2YC_Qg7d-5wsZzK1AMyKhyZ8R6_ENavP8OmC_Tt11qFY-xVjkC2enFeE3OZoV5_nTFpEWD1HkSdiSFCyAYWevTc6ztvm6pFjsVFeqU3kSu6ijge7_sHunRoUfE4qN6_k2_uKSO2Mwgq7hq2GzJ7vkze-_-zqEhD3iD3VTNs1u6irWM9WqHupW9HVdloIJaA6S96Kvqr7aGYFzEjocH8J5n0Z8Zs9wWb8K5Q1qy2f13U53nHHOjqxijDdVW3Am--aEOEfF8IPCSMVgFtoUmVXh_Ljz3UoQcQMGDVoT3oMiBD1agLU44osUJ-c78fM5of5VSrfq-Bs-Cavj">