Repository: pytorch
Issue: `torch.gather` backward performance extremely low on `torch.bfloat16`
Labels: module: performance,module: cuda,triaged,module: bfloat16,module: scatter & gather ops

### 🐛 Describe the bug

```python
import torch

inp = torch.randn(8, 4096, device=torch.cuda.current_device(), requires_grad=True)
bf16_inp = inp.detach().clone().to(torch.bfloat16).requires_grad_(True)
indice = torch.randint(0, 8, (8192,)).view(-1, 1).expand(-1, 4096).to(torch.cuda.current_device())
rand_out_grad = torch.randn(8192, 4096, device=torch.cuda.current_device())
bf16_rand_out_grad = rand_out_grad.detach().clone().to(torch.bfloat16)

with torch.profiler.profiler.profile(
    activities=[
            torch.profiler.ProfilerActivity.CPU,
            torch.profiler.ProfilerActivity.CUDA,
        ],
        on_trace_ready=lambda p: p.export_chrome_trace("test_gather.json")
) as p:
    out = torch.gather(inp, 0, indice)
    out.backward(rand_out_grad)
    bf16_out = torch.gather(bf16_inp, 0, indice)
    bf16_out.backward(bf16_rand_out_grad)
```
fp32 `torch.gather` fw takes 0.259 ms, bw takes 0.266 ms. But bf16 `torch.gather` fw takes 0.224ms, bw takes 8.724 ms.
<img width="1047" alt="image" src="https://github.com/pytorch/pytorch/assets/35216808/054e5de9-db52-464f-8d93-ca19b1ccecdd">


### Versions

```
Collecting environment information...
PyTorch version: 2.2.1+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS:  Linux Server 7.2 (Paladin) (x86_64)
GCC version: (GCC) 9.2.1 20200522
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.30

Python version: 3.8.18 (default, Sep 11 2023, 13:40:15)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.9.151-015.ali3000.alios7.x86_64-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA A100-SXM4-80GB
GPU 1: NVIDIA A100-SXM4-80GB
GPU 2: NVIDIA A100-SXM4-80GB
GPU 3: NVIDIA A100-SXM4-80GB
GPU 4: NVIDIA A100-SXM4-80GB
GPU 5: NVIDIA A100-SXM4-80GB
GPU 6: NVIDIA A100-SXM4-80GB
GPU 7: NVIDIA A100-SXM4-80GB

Nvidia driver version: 470.82.01
cuDNN version: Probably one of the following:
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.9.3
/usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.9.3
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                128
On-line CPU(s) list:   0-127
Thread(s) per core:    2
Core(s) per socket:    32
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 106
Model name:            Intel(R) Xeon(R) Platinum 8369B CPU @ 2.90GHz
Stepping:              6
CPU MHz:               3499.859
CPU max MHz:           3500.0000
CPU min MHz:           800.0000
BogoMIPS:              5800.00
Virtualization:        VT-x
L1d cache:             48K
L1i cache:             32K
L2 cache:              1280K
L3 cache:              49152K
NUMA node0 CPU(s):     0-31,64-95
NUMA node1 CPU(s):     32-63,96-127
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb invpcid_single ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq pconfig flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8==6.1.0
[pip3] numpy==1.23.5
[pip3] torch==2.2.1
[pip3] torchaudio==2.1.0+cu121
[pip3] torchpippy==0.1.1+cecc4fc
[pip3] torchvision==0.16.0+cu121
[pip3] triton==2.2.0
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] torch                     2.2.1                    pypi_0    pypi
[conda] torchaudio                2.1.0+cu121              pypi_0    pypi
[conda] torchpippy                0.1.1+cecc4fc            pypi_0    pypi
[conda] torchvision               0.16.0+cu121             pypi_0    pypi
[conda] triton                    2.2.0                    pypi_0    pypi
```

cc @ptrblck