[inductor][cpp_wrapper] Support rand fallback
Labels: triaged, oncall: pt2

### Edited/minified issue

```python
import torch
import torch._dynamo

import torch._inductor.config

torch._inductor.config.fallback_random = True
torch._inductor.config.cpp_wrapper = True

def fn(x):
    y = torch.randint(0, 10, (4, 4), dtype=torch.int32)
    return y + x

opt_fn = torch._dynamo.optimize("inductor")(fn)

x = torch.rand((4, 4))

torch.manual_seed(42)
ref = fn(x)
torch.manual_seed(42)
res = opt_fn(x)
print(torch.max(torch.abs(res-ref)))
```

Error:

~~~
  File "/scratch/anijain/work/pytorch/torch/_dynamo/utils.py", line 180, in time_wrapper
    r = func(*args, **kwargs)
  File "/scratch/anijain/work/pytorch/torch/_inductor/scheduler.py", line 1379, in codegen
    self.codegen_extern_call(node)
  File "/scratch/anijain/work/pytorch/torch/_inductor/scheduler.py", line 1300, in codegen_extern_call
    node.codegen(V.graph.wrapper_code)
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 3314, in codegen
    super().codegen(wrapper)
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 3002, in codegen
    args = [*self.codegen_args(), *self.codegen_kwargs()]
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 2875, in codegen_kwargs
    assert (
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
AssertionError: ordered_kwargs_for_cpp_kernel has to be provided
~~~

There are a few issues here:
1. self.ordered_kwargs_for_cpp_kernel doesn't exist when we try to codegen.
2. We can't always get the schema because the `kernel` passed into the FallbackKernel IR node is sometimes an OpOverload and sometimes an OpOverloadPacket
3. if we add it, self.kwargs != self.ordered_kwargs_for_cpp_kernel. AFAIK, this is fine because the missing self.kwargs (specifically, `layout`) are optional.
4. The codegen-ed code doesn't match the CPP args: the dtype, layout, etc. are expected to be provided as a single TensorOptions() object but the codegen provides it as a list of individual options.

### 🐛 Original bug below

~~~

import torch
from torch import tensor, device
import torch.fx as fx
from torch._dynamo.testing import rand_strided
from math import inf
import torch._inductor.inductor_prims

import torch._dynamo.config
import torch._inductor.config
import torch._functorch.config

torch._inductor.config.fallback_random = True
torch._inductor.config.triton.autotune_cublasLt = False
torch._inductor.config.triton.unique_kernel_names = True
torch._inductor.config.triton.store_cubin = True
torch._inductor.config.cpp_wrapper = True



isolate_fails_code_str = None



# torch version: 2.1.0a0+gita5cdb9a
# torch cuda version: 11.8
# torch git version: a5cdb9a9a4de0b8cd92d850588a1d7e40958189b


# CUDA Info: 
# nvcc: NVIDIA (R) Cuda compiler driver 
# Copyright (c) 2005-2022 NVIDIA Corporation 
# Built on Wed_Sep_21_10:33:58_PDT_2022 
# Cuda compilation tools, release 11.8, V11.8.89 
# Build cuda_11.8.r11.8/compiler.31833905_0 

# GPU Hardware Info: 
# NVIDIA A100-SXM4-40GB : 1 


from torch.nn import *
class Repro(torch.nn.Module):
    def __init__(self):
        super().__init__()

    
    
    def forward(self, arg0_1):
        full = torch.ops.aten.full.default([209982], 1, dtype = torch.float32, layout = torch.strided, device = device(type='cuda', index=0), pin_memory = False)
        select = torch.ops.aten.select.int(arg0_1, 0, 0)
        select_1 = torch.ops.aten.select.int(arg0_1, 0, 1);  arg0_1 = None
        view = torch.ops.aten.view.default(select_1, [-1])
        expand = torch.ops.aten.expand.default(view, [209982]);  view = None
        full_1 = torch.ops.aten.full.default([10000], 0, dtype = torch.float32, layout = torch.strided, device = device(type='cuda', index=0), pin_memory = False)
        scatter_add = torch.ops.aten.scatter_add.default(full_1, 0, expand, full);  full_1 = expand = None
        pow_1 = torch.ops.aten.pow.Tensor_Scalar(scatter_add, -0.5);  scatter_add = None
        eq = torch.ops.aten.eq.Scalar(pow_1, inf)
        scalar_tensor = torch.ops.aten.scalar_tensor.default(0.0, dtype = torch.float32, layout = torch.strided, device = device(type='cuda', index=0))
        where = torch.ops.aten.where.self(eq, scalar_tensor, pow_1);  eq = scalar_tensor = pow_1 = None
        index = torch.ops.aten.index.Tensor(where, [select]);  select = None
        mul = torch.ops.aten.mul.Tensor(index, full);  index = full = None
        index_1 = torch.ops.aten.index.Tensor(where, [select_1]);  where = select_1 = None
        mul_1 = torch.ops.aten.mul.Tensor(mul, index_1);  mul = index_1 = None
        return (mul_1,)
        
def load_args(reader):
    buf0 = reader.storage(None, 3359712, device=device(type='cuda', index=0), dtype_hint=torch.int64)
    reader.tensor(buf0, (2, 209982), dtype=torch.int64, is_leaf=True)  # arg0_1
load_args._version = 0
mod = Repro()
if __name__ == '__main__':
    from torch._dynamo.repro.after_aot import run_repro
    run_repro(mod, load_args, accuracy=False, command='minify', save_dir='/scratch/anijain/work/pytorch/torch_compile_debug/run_2023_06_12_06_49_04_662047-pid_1028077/minifier/checkpoints', tracing_mode='real')

~~~~

~~~
  File "/scratch/anijain/work/pytorch/torch/_dynamo/utils.py", line 180, in time_wrapper
    r = func(*args, **kwargs)
  File "/scratch/anijain/work/pytorch/torch/_inductor/scheduler.py", line 1379, in codegen
    self.codegen_extern_call(node)
  File "/scratch/anijain/work/pytorch/torch/_inductor/scheduler.py", line 1300, in codegen_extern_call
    node.codegen(V.graph.wrapper_code)
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 3314, in codegen
    super().codegen(wrapper)
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 3002, in codegen
    args = [*self.codegen_args(), *self.codegen_kwargs()]
  File "/scratch/anijain/work/pytorch/torch/_inductor/ir.py", line 2875, in codegen_kwargs
    assert (
torch._dynamo.exc.BackendCompilerFailed: backend='inductor' raised:
AssertionError: ordered_kwargs_for_cpp_kernel has to be provided
~~~

### Versions

N/A

cc @ezyang @msaroufim @wconstab @bdhirsh