random_kernel Class — pytorch Architecture
Architecture documentation for the random_kernel class in DistributionTemplates.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/cuda/DistributionTemplates.h lines 388–416
template<typename RNG>
void random_kernel(TensorIteratorBase& iter, RNG gen) {
AT_DISPATCH_ALL_TYPES_AND3(at::ScalarType::Half, at::ScalarType::BFloat16, at::ScalarType::Bool, iter.dtype(), "random_kernel_cuda", [&] {
if (std::is_same_v<scalar_t, double> || std::is_same_v<scalar_t, int64_t>) {
auto random_func = [] __device__ (uint64_t rand) {
return transformation::uniform_int<scalar_t>(rand);
};
distribution_nullary_kernel<scalar_t, uint64_t, ulonglong2>(iter, gen,
[] __device__ (curandStatePhilox4_32_10_t* state) -> ulonglong2 {
ulonglong2 ret;
uint4 rand_val = curand4(state);
ret.x = (static_cast<uint64_t>(rand_val.x) << 32) | rand_val.y;
ret.y = (static_cast<uint64_t>(rand_val.z) << 32) | rand_val.w;
return ret;
},
random_func);
} else {
auto random_func = [] __device__ (uint32_t rand) {
return transformation::uniform_int<scalar_t>(rand);
};
distribution_nullary_kernel<scalar_t, uint32_t, uint4>(iter,
gen,
[] __device__ (curandStatePhilox4_32_10_t* state) -> uint4 {
return curand4(state);
},
random_func);
}
});
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free