<div dir="ltr">I'm trying to develop and apply my custom pass to an OpenMP target offloading code. But when using 'opt' I face the following error:<br>  opt: <stdin>:29:1: error: expected top-level entity<br><div>  source_filename = "test.cpp" </div><div><br></div><div>I receive this error message even if I do not use my pass and just try to use opt with -O1.</div><div><br></div><div>Sample code I tried to build:</div><div>  $ cat test.cpp<br>  int main()<br>  {<br>  #pragma omp target teams distribute parallel for<br>    for(int i=0; i<1000;i++);<br>    return 0;<br>  }</div><div><br></div><div>Command used to build the code and run</div><div>  $ clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_70 test.cpp</div><div>  $ nvprof ./a.out<br>  ==85306== NVPROF is profiling process 85306, command: ./a.out<br>  ==85306== Profiling application: ./a.out<br>  ==85306== Profiling result:<br>            Type  Time(%)      Time     Calls       Avg       Min       Max  Name<br>   GPU activities:   91.79%  30.752us         1  30.752us  30.752us  30.752us  __omp_offloading_2c_715c4b_main_l3<br>                    4.68%  1.5680us         1  1.5680us  1.5680us  1.5680us  [CUDA memcpy DtoH]<br>                    3.53%  1.1840us         1  1.1840us  1.1840us  1.1840us  [CUDA memcpy HtoD]<br>        API calls:   80.54%  362.46ms         1  362.46ms  362.46ms  362.46ms  cuDevicePrimaryCtxRetain<br>                   17.76%  79.946ms         1  79.946ms  79.946ms  79.946ms  cuDevicePrimaryCtxRelease<br>                    1.00%  4.4941ms         1  4.4941ms  4.4941ms  4.4941ms  cuModuleLoadDataEx<br>                    0.54%  2.4175ms         1  2.4175ms  2.4175ms  2.4175ms  cuModuleUnload<br>                    0.10%  446.26us        32  13.945us  2.0710us  174.72us  cuStreamCreate<br>                    0.02%  111.17us        32  3.4730us  2.9480us  13.457us  cuStreamDestroy<br>                    0.01%  64.949us         1  64.949us  64.949us  64.949us  cuStreamSynchronize<br>                    0.01%  44.065us         1  44.065us  44.065us  44.065us  cuMemcpyDtoH<br>                    0.01%  27.451us         1  27.451us  27.451us  27.451us  cuLaunchKernel<br>                    0.00%  12.617us         1  12.617us  12.617us  12.617us  cuDeviceGetPCIBusId<br>                    0.00%  9.4680us         1  9.4680us  9.4680us  9.4680us  cuMemcpyHtoD<br>                    0.00%  5.9570us         1  5.9570us  5.9570us  5.9570us  cuModuleGetFunction<br>                    0.00%  5.1610us         2  2.5800us  1.1090us  4.0520us  cuModuleGetGlobal<br>                    0.00%  5.1190us         6     853ns     277ns  1.9740us  cuCtxSetCurrent<br>                    0.00%  3.5270us         6     587ns     214ns  1.2310us  cuDeviceGetAttribute<br>                    0.00%  3.4210us         3  1.1400us     465ns  2.4020us  cuDeviceGetCount<br>                    0.00%  3.3210us         2  1.6600us  1.5970us  1.7240us  cuDeviceGet<br>                    0.00%  1.6230us         1  1.6230us  1.6230us  1.6230us  cuFuncGetAttribute<br>                    0.00%  1.1600us         1  1.1600us  1.1600us  1.1600us  cuDevicePrimaryCtxGetState<br>                    0.00%     685ns         1     685ns     685ns     685ns  cuDevicePrimaryCtxSetFlags<br>                    0.00%     346ns         1     346ns     346ns     346ns  cuCtxGetDevice<br></div><div><br></div><div>This shows that my Clang and OpenMP are built properly and target offloading works.</div><div><br></div><div>Next I'm trying to apply any pass to this code, so I convert the code into LLVM-IR and then apply -O1 to it using opt.</div><div>  $ clang++ -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_70 -emit-llvm -S test.cpp</div><div>  $ opt -O1 < test.ll<br>  opt: <stdin>:891:1: error: expected top-level entity<br>  source_filename = "test.cpp" <br>  ^<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><br></div><div>I'm able to use opt for any non-target offloading code. I get this error only when I use OpenMP target offloading.</div><div>Please advise what am I doing wrong here.</div><div><br></div><div>--<br><div>Thank You.</div><div>Regards,</div>Alok<i><br></i></div><div style="text-align:center"><i><font color="#666666">'FOR THE GREATER GOOD'</font></i></div></div></div></div></div></div></div></div>