cpu_masked_select_serial_kernel Class — pytorch Architecture
Architecture documentation for the cpu_masked_select_serial_kernel class in IndexKernel.cpp from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/cpu/IndexKernel.cpp lines 398–418
template <typename scalar_t, typename mask_t, typename func_t>
void cpu_masked_select_serial_kernel(TensorIterator& iter, const func_t& f) {
int64_t offset = 0;
auto loop = [&](char** data, const int64_t* strides, int64_t n) {
char* dst = data[0];
char* src = data[1];
char* mask = data[2];
for (const auto i : c10::irange(n)) {
mask_t mask_value = c10::load((mask_t*)(mask + strides[2] * i));
if constexpr (!std::is_same_v<mask_t, bool>) {
TORCH_CHECK(mask_value == 0 || mask_value == 1, "Mask tensor can take 0 and 1 values only");
}
if (mask_value) {
int64_t offset_bytes = offset * sizeof(scalar_t);
f(dst, src + strides[1] * i, offset_bytes);
offset++;
}
}
};
iter.serial_for_each(loop, {0, iter.numel()});
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free