code: def test_pointwise_op_tensors_on_different_devices(
      self, device, dtype, op
  ):
      # tensors1: ['cuda', 'cpu]
      # tensors2: ['cuda', 'cpu]
      # tensors3: ['cuda', 'cpu]
      # first tensorlist is zero-size when float32
      _cuda_tensors = list(
          op.sample_inputs(
              device, dtype, num_input_tensors=[3], same_size=True
          )
      )[int(dtype == torch.float32)].input
      _cpu_tensors = next(
          iter(
              op.sample_inputs(
                  "cpu", dtype, num_input_tensors=[3], same_size=True
              )
          )
      ).input
      tensors1, tensors2, tensors3 = list(
          zip(_cuda_tensors, _cpu_tensors)
      )
  
      foreach_op, foreach_op_, native_op = (
          op.method_variant,
          op.inplace_variant,
          op.ref,
      )
      actual = foreach_op(tensors1, tensors2, tensors3)
      expected = [native_op(*_cuda_tensors), native_op(*_cpu_tensors)]
      self.assertEqual(expected, actual)
  
      # note(mkozuki): Limiting dtypes to FP32&FP64, we can safely run inplace ops.
      foreach_op_(tensors1, tensors2, tensors3)
      self.assertEqual(expected, tensors1)
  
imports: from contextlib import nullcontext
  from numbers import Number
  import random
  import re
  import torch
  import unittest
  import itertools
  import weakref
  from torch.testing import make_tensor
  from torch.testing._comparison import default_tolerances
  from torch.testing._internal.common_cuda import TEST_MULTIGPU
  from torch.testing._internal.common_utils import TestCase, run_tests, TEST_WITH_ROCM, skipIfTorchDynamo, parametrize, gradcheck
  from torch.testing._internal.common_device_type import instantiate_device_type_tests, dtypes, onlyCUDA, ops, OpDTypes
  from torch.testing._internal.common_methods_invocations import foreach_unary_op_db, foreach_binary_op_db, foreach_pointwise_op_db, foreach_reduce_op_db, foreach_other_op_db
  from torch.testing._internal.common_dtype import all_types_and_complex_and, floating_types_and, floating_types, integral_types_and
label_desc: Use image node_id 17 for calling the TestForeach obj's underlying member method code with example usage: obj.test_pointwise_op_tensors_on_different_devices(device, dtype, op) without return types