Dynamic Function Selection Process in PyTorch Compilation for torch_cpu.so”

During the compilation of torch_cpu.so in PyTorch, the source code files are categorized into avx_srcs, avx2_srcs, avx512_srcs, and common_srcs. Each category of files is then compiled into a separate static library. Finally, these static libraries are linked together to create libtorch_cpu.so. At runtime, the process of dynamically selecting which function to call is a crucial step. I would like to know how this dynamic selection process works and where in the codebase it is implemented.could u plz show where the code is?



When users utilize libtorch_cpu.so, how do they decide which function to use? Taking the example of caffe2/perfkernels/embedding_lookup_idx_avx2.cc, where is the decision made to call either EmbeddingLookupIdx_int32_t_float_float_true__avx2_fma or EmbeddingLookupGenericSlowIdx function?