| 294 | |
| 295 | @test_util.run_gpu_only |
| 296 | def testSoftPlacement(self): |
| 297 | # Temporarily replace the context |
| 298 | # pylint: disable=protected-access |
| 299 | old_context = context.context() |
| 300 | context._set_context(context.Context()) |
| 301 | try: |
| 302 | config.set_device_policy('silent') |
| 303 | config.set_soft_device_placement(True) |
| 304 | cpu_tensor = constant_op.constant(1.0) |
| 305 | result = cpu_tensor + cpu_tensor |
| 306 | self.assertEqual(result.device, |
| 307 | '/job:localhost/replica:0/task:0/device:GPU:0') |
| 308 | finally: |
| 309 | context._set_context(old_context) |
| 310 | # pylint: enable=protected-access |
| 311 | |
| 312 | def testRandomUniform(self): |
| 313 | scalar_shape = constant_op.constant([], dtype=dtypes.int32) |