I have defined a customed conv2d function and the forward function is as follows : which consists a tensor slice and tensor copy process,
def forward(self, input):
	self.output.index_copy_(1, self.k_out_mask, F.conv2d(torch.index_select(input, 1, self.k_in_mask), self.weight)
	
	return self.output

I tested the runing time of this forward process,  it cost about 40ms,
but when I tested another forward function as follows,
def forward(self, input):

	return F.conv2d(input, self.weight)

This function does.t have the tensor slice and copy operation, but the conv2d input and weight size are same as the above function, it cost about 14ms.
Why does the tensor slice and tensor copy operation brings so much time cost ?
Can anyone help me to accelerate the tensor slice and tensor copy operation ?
Thanks so much !