MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / testCpuMultiple

Method testCpuMultiple

tensorflow/python/framework/config_test.py:351–394  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

349
350 @reset_eager
351 def testCpuMultiple(self):
352 cpus = config.list_physical_devices('CPU')
353 self.assertEqual(len(cpus), 1)
354
355 config.set_virtual_device_configuration(cpus[0], [
356 context.VirtualDeviceConfiguration(),
357 context.VirtualDeviceConfiguration()
358 ])
359
360 context.ensure_initialized()
361
362 vcpus = config.list_logical_devices('CPU')
363 self.assertEqual(len(vcpus), 2)
364
365 with ops.device('/device:CPU:0'):
366 a = constant_op.constant(1.0)
367 self.evaluate(a)
368 with ops.device('/device:CPU:1'):
369 b = constant_op.constant(1.0)
370 self.evaluate(b)
371 with self.assertRaisesRegexp(RuntimeError, 'unknown device'):
372 with ops.device('/device:CPU:2'):
373 c = constant_op.constant(1.0)
374 self.evaluate(c)
375
376 # Ensure we can place ops on each of the device names
377 for vcpu in vcpus:
378 with ops.device(vcpu.name):
379 d = constant_op.constant(1.0)
380 self.evaluate(d)
381
382 # Modifying the CPU configuration is not supported
383 with self.assertRaisesRegexp(RuntimeError, 'cannot be modified'):
384 config.set_virtual_device_configuration(cpus[0], [
385 context.VirtualDeviceConfiguration(),
386 context.VirtualDeviceConfiguration(),
387 context.VirtualDeviceConfiguration()
388 ])
389
390 # Setting the same CPU configuration is fine
391 config.set_virtual_device_configuration(cpus[0], [
392 context.VirtualDeviceConfiguration(),
393 context.VirtualDeviceConfiguration()
394 ])
395
396 @test_util.run_gpu_only
397 @reset_eager

Callers

nothing calls this directly

Calls 7

list_physical_devicesMethod · 0.80
ensure_initializedMethod · 0.80
list_logical_devicesMethod · 0.80
deviceMethod · 0.45
constantMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected