Skip to content

AT_DISPATCH_FLOATING_TYPES_AND2 fails with ScalarType::Byte #34826

Closed
@r-zenine

Description

@r-zenine

🐛 Bug

Using AT_DISPATCH_FLOATING_TYPES_AND2, in cuda code is causing a compilation error:

I am trying to enable support for uint8 for nearest Neighbor upsampling.
Therefore, I tried to replace AT_DISPATCH_FLOATING_TYPES_AND_HALF with AT_DISPATCH_FLOATING_TYPES_AND2(at::ScalarType::Half, at::ScalarType::Byte, ...
Which caused a compilation. On the other hand, using AT_DISPATCH_ALL_TYPES_AND(at::ScalarType::Half ... works fine.

To Reproduce

Steps to reproduce the behavior:

  1. Checkout to bdd7dbfd4b
  2. Change /home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest3d.cu(176) to use AT_DISPATCH_FLOATING_TYPES_AND2
  3. compile
[1/3] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/torch_cuda_generated_UpSampleNearest3d.cu.o
FAILED: caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/torch_cuda_generated_UpSampleNearest3d.cu.o 
cd /home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda && /home/ryad/miniconda3/envs/pytorch-dev/bin/cmake -E make_directory /home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/. && /home/ryad/miniconda3/envs/pytorch-dev/bin/cmake -D verbose:BOOL=OFF -D build_configuration:STRING=Release -D generated_file:STRING=/home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/./torch_cuda_generated_UpSampleNearest3d.cu.o -D generated_cubin_file:STRING=/home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/./torch_cuda_generated_UpSampleNearest3d.cu.o.cubin.txt -P /home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/torch_cuda_generated_UpSampleNearest3d.cu.o.Release.cmake
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest3d.cu(176): error: incomplete type is not allowed

/home/ryad/workspace/pytorch/aten/src/ATen/AccumulateType.h(48): error: class "at::AccumulateType<<error-type>, true>" has no member "type"
          detected during instantiation of type "at::acc_type<<error-type>, true>" 
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest3d.cu(176): here

/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest3d.cu(269): error: incomplete type is not allowed

3 errors detected in the compilation of "/tmp/tmpxft_00007f4c_00000000-6_UpSampleNearest3d.cpp1.ii".
CMake Error at torch_cuda_generated_UpSampleNearest3d.cu.o.Release.cmake:281 (message):
  Error generating file
  /home/ryad/workspace/pytorch/build/caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/./torch_cuda_generated_UpSampleNearest3d.cu.o


[2/3] Building NVCC (Device) object caffe2/CMakeFiles/torch_cuda.dir/__/aten/src/ATen/native/cuda/torch_cuda_generated_UpSampleNearest2d.cu.o
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu: In function ‘at::Tensor at::native::upsample_nearest2d_cuda(const at::Tensor&, c10::IntArrayRef, c10::optional<double>, c10::optional<double>)’:
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu:305:44: warning: ‘c10::MemoryFormat c10::get_contiguous_memory_format()’ is deprecated [-Wdeprecated-declarations]
   Tensor output = at::empty_like(input, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ryad/workspace/pytorch/c10/core/MemoryFormat.h:34:36: note: declared here
 C10_DEPRECATED inline MemoryFormat get_contiguous_memory_format() {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu:305:73: warning: ‘c10::MemoryFormat c10::get_contiguous_memory_format()’ is deprecated [-Wdeprecated-declarations]
   Tensor output = at::empty_like(input, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
                                                                         ^
/home/ryad/workspace/pytorch/c10/core/MemoryFormat.h:34:36: note: declared here
 C10_DEPRECATED inline MemoryFormat get_contiguous_memory_format() {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu: In function ‘at::Tensor at::native::upsample_nearest2d_backward_cuda(const at::Tensor&, c10::IntArrayRef, c10::IntArrayRef, c10::optional<double>, c10::optional<double>)’:
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu:328:54: warning: ‘c10::MemoryFormat c10::get_contiguous_memory_format()’ is deprecated [-Wdeprecated-declarations]
   Tensor grad_input = at::empty_like(grad_output, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ryad/workspace/pytorch/c10/core/MemoryFormat.h:34:36: note: declared here
 C10_DEPRECATED inline MemoryFormat get_contiguous_memory_format() {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/ryad/workspace/pytorch/aten/src/ATen/native/cuda/UpSampleNearest2d.cu:328:83: warning: ‘c10::MemoryFormat c10::get_contiguous_memory_format()’ is deprecated [-Wdeprecated-declarations]
   Tensor grad_input = at::empty_like(grad_output, LEGACY_CONTIGUOUS_MEMORY_FORMAT);
                                                                                   ^
/home/ryad/workspace/pytorch/c10/core/MemoryFormat.h:34:36: note: declared here
 C10_DEPRECATED inline MemoryFormat get_contiguous_memory_format() {
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ninja: build stopped: subcommand failed.

Expected behavior

My understanding is that the code should compile since using AT_ALL_TYPES_AND is compiling.

cc @yf225

Metadata

Metadata

Assignees

Labels

module: cpp-extensionsRelated to torch.utils.cpp_extensionmodule: dispatchDispatchStub, Type, void pointer table, c10 dispatchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions