I have encountered a problem about the forward propagation, the full code is as follows:
I want to accurately record the runing time of nn.conv2d function, where time1 is about
0.00009901s, but time2 is about 0.00011235s. As can be seen in the code, the convolution flops is identical,  I don’t know what cause the time difference with time1 and time2.
import os
os.environ["CUDA_VISIBLE_DEVICES"] = '7'

import torch
import torch.nn as nn
from torch.autograd import Variable

import time
import numpy as np
import random

def main():
    
    test_input1 = Variable(torch.rand(1,36,56,56)).cuda()
    test_input2 = Variable(torch.rand(1,64,56,56)).cuda()
    m1 = torch.nn.Conv2d(36, 36, kernel_size=3, stride=1, padding=1).cuda()

    time1_list = []
    for i in range(10000):
        torch.cuda.synchronize()
        t1 =time.time()
        temp_out = m1(test_input1)
        torch.cuda.synchronize()
        t2=time.time()
        time1_list.append(t2-t1)
    print('time1:%.8f' %(sum(time1_list[50:])/len(time1_list[50:])))



    output = Variable(torch.zeros(1, 64, 56, 56)).cuda()
    k_in_mask = torch.from_numpy(np.array(random.sample(range(0,64), 36))).cuda()
    k_out_mask = torch.from_numpy(np.array(random.sample(range(0,64), 36))).cuda()
    
    time2_list = []
    for i in range(10000):
        temp_in = torch.index_select(test_input2, 1, Variable(k_in_mask))
       
        torch.cuda.synchronize()
        t1=time.time()
        temp_out = m1(temp_in)
        torch.cuda.synchronize()
        t2=time.time()
        time2_list.append(t2-t1)
        
        output.index_copy(1, Variable(k_out_mask), temp_out)
    print('time2:%.8f' %(sum(time2_list[50:])/len(time2_list[50:])))

if __name__=='__main__':
    main()