Skip to content

Commit f1b43f1

Browse files
datumboxfacebook-github-bot
authored andcommitted
[fbsync] use bitshifts for int to int in convert_dtype (#6978)
Reviewed By: jdsgomes Differential Revision: D41548197 fbshipit-source-id: 34b1f8638e3832db45d4742b1c89ab18022886f0
1 parent 92bc536 commit f1b43f1

File tree

1 file changed

+1
-9
lines changed
  • torchvision/prototype/transforms/functional

1 file changed

+1
-9
lines changed

torchvision/prototype/transforms/functional/_meta.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,7 @@ def convert_dtype_image_tensor(image: torch.Tensor, dtype: torch.dtype = torch.f
379379
if num_value_bits_input > num_value_bits_output:
380380
return image.bitwise_right_shift(num_value_bits_input - num_value_bits_output).to(dtype)
381381
else:
382-
# The bitshift kernel is not vectorized
383-
# https://github.com/pytorch/pytorch/blob/703c19008df4700b6a522b0ae5c4b6d5ffc0906f/aten/src/ATen/native/cpu/BinaryOpsKernel.cpp#L315-L322
384-
# This results in the multiplication actually being faster.
385-
# TODO: If the bitshift kernel is optimized in core, replace the computation below with
386-
# `image.to(dtype).bitwise_left_shift_(num_value_bits_output - num_value_bits_input)`
387-
max_value_input = float(_FT._max_value(dtype))
388-
max_value_output = float(_FT._max_value(image.dtype))
389-
factor = int((max_value_input + 1) // (max_value_output + 1))
390-
return image.to(dtype).mul_(factor)
382+
return image.to(dtype).bitwise_left_shift_(num_value_bits_output - num_value_bits_input)
391383

392384

393385
# We changed the name to align it with the new naming scheme. Still, `convert_image_dtype` is

0 commit comments

Comments
 (0)