How can i enable GPU in those lines?

i need to enable fast computations using single GPU.

def load_points_cacl_distance(self, path):
    points = pd.read_csv(path, sep='\t', usecols=[0, 1])      
    max_id = len(points)
    device = torch.device("cuda")
    d = pd.DataFrame(np.zeros((max_id, max_id)))  
    tensor1 = torch.from_numpy(d.values)
    dis = sch.distance.pdist(points, 'euclidean') 
    tensor2 = torch.from_numpy(dis)
    n = 0
    for i in range(max_id):
        for j in range(i + 1, max_id):    
  [i, j] = tensor2[n].to(device)
  [j, i] = tensor1[i, j].to(device)
            n += 1

but the output is still slow


In the following situations you should put .cuda() our .to(device).
Situation 1: tensors creation
Situation 2: model definition (in case of neural networks models)

Since you define a device with device = torch.device("cuda") you should put in all the tensors you create.