cpu_kernel Class — pytorch Architecture
Architecture documentation for the cpu_kernel class in Loops.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/cpu/Loops.h lines 304–319
template <typename func_t>
void cpu_kernel(TensorIteratorBase& iter, func_t&& op, int64_t grain_size = at::internal::GRAIN_SIZE) {
using traits = function_traits<func_t>;
// this could be extended to work with void return types
TORCH_INTERNAL_ASSERT(iter.ninputs() == traits::arity);
TORCH_INTERNAL_ASSERT(iter.noutputs() == 1);
// dynamic casting not currently supported on CPU
TORCH_INTERNAL_ASSERT(!needs_dynamic_casting<func_t>::check(iter));
iter.for_each([&](char** data, const int64_t* strides, int64_t n) {
// basic loop can handle 1d slices with arbitrary strides, and 1d slices is all that
// iter.for_each is ever sending to the loop lambda
basic_loop(data, strides, 0, n, op);
}, grain_size);
iter.cast_outputs();
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free