(self)
| 57 | @test_util.run_gpu_only |
| 58 | @reset_eager |
| 59 | def testDevicePolicy(self): |
| 60 | self.assertEqual(context.DEVICE_PLACEMENT_SILENT, |
| 61 | context.context().device_policy) |
| 62 | |
| 63 | # If no op has been executed we should be able to set the device policy as |
| 64 | # well as any init-time configs. |
| 65 | config.set_intra_op_parallelism_threads(1) |
| 66 | config.set_device_policy('silent') |
| 67 | config.set_intra_op_parallelism_threads(2) |
| 68 | |
| 69 | context.ensure_initialized() |
| 70 | |
| 71 | def copy_tensor(dtype=dtypes.int32): |
| 72 | cpu_tensor = constant_op.constant(1, dtype=dtype) |
| 73 | gpu_tensor = cpu_tensor.gpu() |
| 74 | self.assertAllEqual(cpu_tensor + gpu_tensor, 2.0) |
| 75 | |
| 76 | config.set_device_policy('silent') |
| 77 | self.assertEqual(config.get_device_policy(), 'silent') |
| 78 | self.assertEqual(context.DEVICE_PLACEMENT_SILENT, |
| 79 | context.context().device_policy) |
| 80 | copy_tensor() |
| 81 | |
| 82 | config.set_device_policy('silent_for_int32') |
| 83 | self.assertEqual(config.get_device_policy(), 'silent_for_int32') |
| 84 | self.assertEqual(context.DEVICE_PLACEMENT_SILENT_FOR_INT32, |
| 85 | context.context().device_policy) |
| 86 | with self.assertRaisesRegexp(errors.InvalidArgumentError, |
| 87 | 'Tensors on conflicting devices'): |
| 88 | copy_tensor(dtypes.float32) |
| 89 | copy_tensor() |
| 90 | |
| 91 | config.set_device_policy('warn') |
| 92 | self.assertEqual(config.get_device_policy(), 'warn') |
| 93 | self.assertEqual(context.DEVICE_PLACEMENT_WARN, |
| 94 | context.context().device_policy) |
| 95 | copy_tensor() |
| 96 | |
| 97 | config.set_device_policy('explicit') |
| 98 | self.assertEqual(config.get_device_policy(), 'explicit') |
| 99 | self.assertEqual(context.DEVICE_PLACEMENT_EXPLICIT, |
| 100 | context.context().device_policy) |
| 101 | with self.assertRaisesRegexp(errors.InvalidArgumentError, |
| 102 | 'Tensors on conflicting devices'): |
| 103 | copy_tensor() |
| 104 | |
| 105 | config.set_device_policy(None) |
| 106 | self.assertEqual(config.get_device_policy(), 'silent') |
| 107 | |
| 108 | @reset_eager |
| 109 | def testExecutionMode(self): |
nothing calls this directly
no test coverage detected