Repository: pytorch
Issue: Clang Compilation Error: more than one constructor applies to convert from "ptrdiff_t" to "c10::Scalar"
Labels: module: build,module: cuda,triaged,module: macos

### 🐛 Describe the bug

I got the following compilation error while compiling pytorch 1.10.0 with CUDA on macOS.
```
cd /Volumes/Data1/library/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda && /usr/local/Cellar/cmake/3.15.2/bin/cmake -E make_directory /Volumes/Data1/library/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/. && /usr/local/Cellar/cmake/3.15.2/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/Volumes/Data1/library/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/./torch_cuda_generated_EmbeddingBag.cu.o -D generated_cubin_file:STRING=/Volumes/Data1/library/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/./torch_cuda_generated_EmbeddingBag.cu.o.cubin.txt -P /Volumes/Data1/library/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/torch_cuda_generated_EmbeddingBag.cu.o.Release.cmake
/Volumes/Data1/library/pytorch/aten/src/ATen/native/cuda/EmbeddingBag.cu(178): error: more than one constructor applies to convert from "ptrdiff_t" to "c10::Scalar":
            function "c10::Scalar::Scalar(uint8_t)"
            function "c10::Scalar::Scalar(int8_t)"
            function "c10::Scalar::Scalar(int16_t)"
            function "c10::Scalar::Scalar(int)"
            function "c10::Scalar::Scalar(int64_t)"
            function "c10::Scalar::Scalar(float)"
            function "c10::Scalar::Scalar(double)"
```
The problem is caused by problematic use of type `ptrdiff_t`, which can be fixed by the following patch.
```
diff --git a/aten/src/ATen/native/cuda/EmbeddingBag.cu b/aten/src/ATen/native/cuda/EmbeddingBag.cu
index 8d1ef8b8fa..a3b3ae15b0 100644
--- a/aten/src/ATen/native/cuda/EmbeddingBag.cu
+++ b/aten/src/ATen/native/cuda/EmbeddingBag.cu
@@ -162,7 +162,7 @@ Tensor embedding_bag_backward_cuda_sum_avg(
 
   cudaStream_t stream = at::cuda::getCurrentCUDAStream();
 
-  ptrdiff_t num_indices = indices.numel();
+  int64_t num_indices = reinterpret_cast<int64_t>(indices.numel());
 
   if (num_indices == 0) {
     // all empty bags
```
Here is a similar issue https://github.com/pytorch/pytorch/issues/48903 that has already been fixed.

Hope that the issue can be fixed in the next release.

### Versions

iMac17:~ tomheaven$ python3 collect_env.py 
Collecting environment information...
PyTorch version: 1.7.0.post2
Is debug build: True
CUDA used to build PyTorch: 10.1
ROCM used to build PyTorch: N/A

OS: macOS 10.13.6 (x86_64)
GCC version: (GCC) 6.2.0
Clang version: Could not collect
CMake version: version 3.15.2
Libc version: N/A

Python version: 3.7.4 (default, Jul  9 2019, 18:15:00)  [Clang 10.0.0 (clang-1000.11.45.5)] (64-bit runtime)
Python platform: Darwin-17.7.0-x86_64-i386-64bit
Is CUDA available: True
CUDA runtime version: 10.1.243
GPU models and configuration: TITAN V
Nvidia driver version: 1.1.0
cuDNN version: Probably one of the following:
/usr/local/cuda/lib/libcudnn.7.dylib
/usr/local/cuda/lib/libcudnn.dylib
/usr/local/cuda/lib/libcudnn_static.a
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.4
[pip3] pytorch-ignite==0.1.2
[pip3] pytorch-nlp==0.4.1
[pip3] torch==1.7.0.post2
[pip3] torchfile==0.1.0
[pip3] torchvision==0.9.0a0+01dfa8e
[conda] Could not collect

cc @malfet @seemethere @ngimel @albanD