Moving or creating data inside the forward via cuda() might yield errors, if you are using nn.DataParallel or DistributedDataParallel, since the model will be copied to each specified device, while your cuda() call will move the data to the default device.
Of course you could specify the device id by reading it from the attribute of an internal parameter e.g. via x = x.to(self.param.device), but I would generally push the data to the device in the DataLoader loop.
I’m not sure, if you need to result on the CPU, but note that this call will be synchronizing your code.
If you are training and thus need the output for the further loss calculation, I would just leave the output on the device.