I have found its source code.
CPU:

  
      github.com
  
  
    pytorch/pytorch/blob/10c60b601a63710b17e2d14e8384c7c9bb51f9ff/aten/src/TH/generic/THTensorEvenMoreMath.cpp#L203-L207 15

void THTensor_(indexSelect)(THTensor *tensor, THTensor *src, int dim, THLongTensor *index)
{
  ptrdiff_t i, numel;
  THTensor *tSlice, *sSlice;
  int64_t *index_data;



  
  
    
    
  
  


CUDA:

  
      github.com
  
  
    pytorch/pytorch/blob/2e37ab85afa1b3b7b05f1ebe24c220809a05de9b/aten/src/THC/generic/THCTensorIndex.cu#L395-L400 7

void THCTensor_(indexSelect)(THCState *state, THCTensor *dst, THCTensor *src, int dim, THCudaLongTensor *indices)
{
  THCAssertSameGPU(THCTensor_(checkGPU)(state, 3, dst, src, indices));


  int dims = THCTensor_(nDimensionLegacyNoScalars)(state, dst);
  THArgCheck(dims <= MAX_CUTORCH_DIMS, 2, CUTORCH_DIM_WARNING);