Repository: pytorch
Issue: error: reference to __host__ function 'parallel_for<thrust::cuda_cub::for_each_f...' in __host__ __device__ function
Labels: module: build,module: cuda,triaged

I try to use clang10 with cuda10.2 to compile pytorch v1.6.0 instead of nvcc, when compiling 'pytorch/caffe2/operators/piecewise_linear_transform_op.cu'
`/usr/bin/clang++ -D__CUDACC__ -MD -MF /home/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/torch_cuda_generated_piecewise_linear_transform_op.cu.o.NVCC-depend --cuda-path=/usr/local/cuda --cuda-gpu-arch=sm_61 -x cuda -std=c++14 -Xcompiler -fPIC -DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ -I/usr/local/cuda/include -I/home/pytorch/build/aten/src -I/home/pytorch/aten/src -I/home/pytorch/build -I/home/pytorch -I/home/pytorch/third_party/protobuf/src -I/usr/include -I/home/pytorch/cmake/../third_party/eigen -I/usr/include/python3.6m -I/usr/local/lib/python3.6/dist-packages/numpy/core/include -I/home/pytorch/cmake/../third_party/pybind11/include -I/home/pytorch/cmake/../third_party/cub -I/home/pytorch/build/caffe2/contrib/aten -I/home/pytorch/third_party/onnx -I/home/pytorch/build/third_party/onnx -I/home/pytorch/third_party/foxi -I/home/pytorch/build/third_party/foxi -I/home/pytorch/build/caffe2/aten/src/TH -I/home/pytorch/aten/src/TH -I/home/pytorch/build/caffe2/aten/src/THC -I/home/pytorch/aten/src/THC -I/home/pytorch/aten/src/THCUNN -I/home/pytorch/aten/src/ATen/cuda -I/home/pytorch/build/caffe2/aten/src -I/home/pytorch/aten/../third_party/catch/single_include -I/home/pytorch/aten/src/ATen/.. -I/home/pytorch/build/caffe2/aten/src/ATen -I/home/pytorch/c10/cuda/../.. -I/home/pytorch/c10/../ -I/home/pytorch/caffe2/../torch/csrc/api -I/home/pytorch/caffe2/../torch/csrc/api/include /home/pytorch/caffe2/operators/piecewise_linear_transform_op.cu -c -o /home/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/operators/./torch_cuda_generated_piecewise_linear_transform_op.cu.ooperators/./torch_cuda_generated_piecewise_linear_transform_op.cu.o`

error occured as follows:

`In file included from /home/pytorch/caffe2/operators/piecewise_linear_transform_op.cu:4:
In file included from /usr/local/cuda/include/thrust/binary_search.h:1901:
In file included from /usr/local/cuda/include/thrust/detail/binary_search.inl:26:
In file included from /usr/local/cuda/include/thrust/system/detail/generic/binary_search.h:173:
In file included from /usr/local/cuda/include/thrust/system/detail/generic/binary_search.inl:31:
In file included from /usr/local/cuda/include/thrust/for_each.h:279:
In file included from /usr/local/cuda/include/thrust/detail/for_each.inl:27:
In file included from /usr/local/cuda/include/thrust/system/detail/adl/for_each.h:42:
In file included from /usr/local/cuda/include/thrust/system/cuda/detail/for_each.h:35:
/usr/local/cuda/include/thrust/system/cuda/detail/parallel_for.h:164:43: error: reference to __host__ function 'parallel_for<thrust::cuda_cub::for_each_f<thrust::zip_iterator<thrust::tuple<thrust::detail::normal_iterator<thrust::pointer<float, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::detail::normal_iterator<thrust::pointer<long, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type> >, thrust::detail::wrapped_function<thrust::system::detail::generic::detail::binary_search_functor<const float *, thrust::system::detail::generic::detail::binary_search_less, thrust::system::detail::generic::detail::lbf>, void> >, long>' in __host__ __device__ function
    cudaError_t  status = __parallel_for::parallel_for(count, f, stream);
                                          ^
/usr/local/cuda/include/thrust/system/cuda/detail/for_each.h:79:15: note: in instantiation of function template specialization 'thrust::cuda_cub::parallel_for<thrust::cuda_cub::par_t, thrust::cuda_cub::for_each_f<thrust::zip_iterator<thrust::tuple<thrust::detail::normal_iterator<thrust::pointer<float, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::detail::normal_iterator<thrust::pointer<long, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type> >, thrust::detail::wrapped_function<thrust::system::detail::generic::detail::binary_search_functor<const float *, thrust::system::detail::generic::detail::binary_search_less, thrust::system::detail::generic::detail::lbf>, void> >, long>' requested here
    cuda_cub::parallel_for(policy,
              ^
/usr/local/cuda/include/thrust/system/cuda/detail/for_each.h:103:22: note: in instantiation of function template specialization 'thrust::cuda_cub::for_each_n<thrust::cuda_cub::par_t, thrust::zip_iterator<thrust::tuple<thrust::detail::normal_iterator<thrust::pointer<float, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::detail::normal_iterator<thrust::pointer<long, thrust::cuda_cub::par_t, thrust::use_default, thrust::use_default> >, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type> >, long, thrust::system::detail::generic::detail::binary_search_functor<const float *, thrust::system::detail::generic::detail::binary_search_less, thrust::system::detail::generic::detail::lbf> >' requested here
    return cuda_cub::for_each_n(policy, first,  count, op);`

while nvcc is works.

cc @malfet @seemethere @walterddr @ngimel