Hi, <div><br></div><div>I was compiling some CUDA code, which builds fine with nvcc, but I got the following error when using clang:</div><div><br></div><div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #c33720}
</style>
<p class="p1"><span class="s1">/home/acg/llvm/build/bin/clang++ -lcudart -std=c++11 axpy.cu --cuda-gpu-arch=sm_35 -I/usr/local/cuda/samples/common/inc</span></p><p class="p1"><span class="s1"><br></span></p>
<p class="p1"><span class="s1">ptxas fatal : Unresolved extern function '_Znam'</span></p>
<p class="p1"><span class="s1">clang-4.0: </span><span class="s2"><b>error: </b></span><span class="s1">ptxas command failed with exit code 255 (use -v to see invocation)</span></p><p class="p1"><span class="s1"><br></span></p><p class="p1"><font color="#000000">The kernel code is as follows: </font></p><p class="p1"><br></p></div><div>
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #34bc26; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}
span.s2 {font-variant-ligatures: no-common-ligatures; color: #000000}
span.s3 {font-variant-ligatures: no-common-ligatures; color: #34bc26}
span.s4 {font-variant-ligatures: no-common-ligatures; color: #c33720}
span.s5 {font-variant-ligatures: no-common-ligatures; color: #33bbc8}
</style>
<p class="p1"><span class="s1">__global__</span><span class="s2"> </span><span class="s1">void</span><span class="s2"> axpy(</span><span class="s1">float</span><span class="s2"> a, </span><span class="s1">float</span><span class="s2">* x, </span><span class="s1">float</span><span class="s2">* y) {</span></p>
<p class="p2"><span class="s1"> </span><span class="s3">int</span><span class="s1"> * _z = new </span><span class="s3">int</span><span class="s1">[</span><span class="s4">16</span><span class="s1">];</span></p>
<p class="p2"><span class="s1"> _z[ </span><span class="s5">threadIdx</span><span class="s1">.x] = x[</span><span class="s5">threadIdx</span><span class="s1">.x];</span></p>
<p class="p2"><span class="s1"> y[</span><span class="s5">threadIdx</span><span class="s1">.x] = a * x[</span><span class="s5">threadIdx</span><span class="s1">.x];</span></p>
<p class="p2"><span class="s1"> __syncthreads();</span></p>
<p class="p2"><span class="s1"> delete[] _z;</span></p>
<p class="p2"><span class="s1">}</span></p><p class="p2"><span class="s1"><br></span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;">new/delete seems to be causing the failure, as the error goes away if we remove the new/delete statements. </span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;"><br></span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;">Any ideas on how to resolve this?</span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;"><br></span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;">Thanks!</span></p><p class="p2"><span style="font-variant-ligatures: no-common-ligatures;">Yuanfeng Peng</span></p></div>