<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59503>59503</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Lowering from GPU to LLVM fails when same kernel is called multiple times
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          asprasad
      </td>
    </tr>
</table>

<pre>
    The following IR that uses the GPU dialect fails to lower to LLVM while trying to target an NVIDIA GPU. It fails because the generated LLVM has multiple definitions of the globals used to hold kernel names and the cubin. 

```MLIR
// File: test.mlir
module attributes {gpu.container_module} {
  func.func @main() {
    %one = arith.constant 1 : index    
    %sx = arith.constant 12 : index

 gpu.launch_func  @main_kernel::@empty_kernel blocks in (%one, %one, %one) threads in (%sx, %one, %one) args()
    %token_1 = gpu.wait async

 gpu.launch_func  @main_kernel::@empty_kernel blocks in (%one, %one, %one) threads in (%sx, %one, %one) args()
    %token_2 = gpu.wait async

 return
  }

 gpu.module @main_kernel {
    gpu.func @empty_kernel() kernel {
      gpu.return
    }
 }
}
```
Running the below command line on the above IR results in an error (multiple definitions of a global).
```
mlir-opt test.mlir -pass-pipeline='builtin.module(gpu.module(strip-debuginfo,convert-gpu-to-nvvm, gpu-to-cubin))'| mlir-opt -gpu-to-llvm
```

The exact error message is the following.
> error: redefinition of symbol named 'main_kernel_empty_kernel_kernel_name'
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUVV1vqzgQ_TXOyygRMaGEBx56m82qUu9qVe3e12qAAbw1NrLHTfPvV4bQpLq92ueVkDH4jH3OeD7Qe9UZolJk30R2WGHg3roS_ejQY7OqbHMu_-oJWqu1PSnTweMzcI8MwZMH7gl-__NvaBRqqhlaVNoDW9D2RC5Onp5-fIdTrzQBu3PcgC0wuo4Y0MAfPx4Pj_dxjw08LvYV1Rg8Tbt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