Yuanfeng Peng via llvm-dev
2017-Jun-10  14:22 UTC
[llvm-dev] [CUDA] Error when compiling CUDA kernel with new/delete
Hi, 
I was compiling some CUDA code, which builds fine with nvcc, but I got the
following error when using clang:
 
/home/acg/llvm/build/bin/clang++ -lcudart -std=c++11 axpy.cu
--cuda-gpu-arch=sm_35 -I/usr/local/cuda/samples/common/inc
 
ptxas fatal   : Unresolved extern function '_Znam'
 
clang-4.0: error: ptxas command failed with exit code 255 (use -v to see
invocation)
The kernel code is as follows: 
 
__global__ void axpy(float a, float* x, float* y) {
 
  int * _z = new int[16];
 
  _z[ threadIdx.x] = x[threadIdx.x];
 
  y[threadIdx.x] = a * x[threadIdx.x];
 
  __syncthreads();
 
  delete[] _z;
 
}
new/delete seems to be causing the failure, as the error goes away if we remove
the new/delete statements.
Any ideas on how to resolve this?
Thanks!
Yuanfeng Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20170610/27b36c1a/attachment.html>