Take a look here:

  
      github.com
  
  
    pytorch/pytorch/blob/4404762d7dd955383acee92e6f06b48144a0742e/aten/src/ATen/native/cuda/TensorFactories.cu#L74-L111 30

Tensor& randperm_out_cuda(Tensor& result, int64_t n, Generator* generator) {
AT_CHECK(n >= 0, "n must be non-negative, got", n);
AT_CHECK(at::scalar_tensor(n, result.options()).defined(),
"n is too large for result tensor type: '", result.type().toString(), "'");


result.resize_({n});


if (result.type().scalarType() == at::ScalarType::Half) {
  auto result_float = at::empty({n}, initialTensorOptions().device(Device(DeviceType::CUDA)));
  result.copy_(randperm_out_cuda(result_float, n, generator));
} else {
  if (n < 30000) {  // For small inputs, we offload it to CPU instead.
    auto result_cpu = at::empty({n}, result.options().device(kCPU));
    randperm_out(result_cpu, n, generator);
    result.copy_(result_cpu);
  } else {
    // Generate random values for the keys array
    AT_DISPATCH_ALL_TYPES(
      result.type(), "randperm_out_cuda", [&] {
        auto keys = at::empty(result.sizes(), result.options()).random_(generator);


  This file has been truncated. show original