tf.test.experimental.sync_devices
Stay organized with collections
Save and categorize content based on your preferences.
Synchronizes all devices.
tf.test.experimental.sync_devices()
By default, GPUs run asynchronously. This means that when you run an op on the
GPU, like tf.linalg.matmul
, the op may still be running on the GPU when the
function returns. Non-GPU devices can also be made to run asynchronously by
calling tf.config.experimental.set_synchronous_execution(False)
. Calling
sync_devices()
blocks until pending ops have finished executing. This is
primarily useful for measuring performance during a benchmark.
For example, here is how you can measure how long tf.linalg.matmul
runs:
import time
x = tf.random.normal((4096, 4096))
tf.linalg.matmul(x, x) # Warmup.
tf.test.experimental.sync_devices() # Block until warmup has completed.
start = time.time()
y = tf.linalg.matmul(x, x)
tf.test.experimental.sync_devices() # Block until matmul has completed.
end = time.time()
print(f'Time taken: {end - start}')
If the call to sync_devices()
was omitted, the time printed could be too
small. This is because the op could still be running asynchronously when
the line end = time.time()
is executed.
Raises |
RuntimeError
|
If run outside Eager mode. This must be called in Eager mode,
outside any tf.function s.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-01-23 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-01-23 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-23 UTC."],[],[]]