Profiler Constructor
Description
Constructor of the Profiler class, which is used to enable the profiling function locally. For example, you can collect the profile data of a local subgraph on the TensorFlow network or a specified step.
Prototype
def __init__(
self,
*,
level: str = "L0",
aic_metrics: str = "",
output_path: str = ""
)
Options
Returns
None
Restrictions
- The Profiler class needs to be called using the with statement, and the profile data collection function takes effect in the corresponding scope.
- The Profiler class can be invoked only in session mode.
- The Profiler class cannot be nested.
The following is an incorrect invoking example:
1 2 3
with profiler.Profiler(level="L1", aic_metrics="ArithmeticUtilization", output_path = "./"): with profiler.Profiler(level="L1", aic_metrics="ArithmeticUtilization", output_path = "./"): sess.run(add)
- The Profiler class cannot be used together with options profiling_mode and profiling_options in Session Configuration, options enable_profiling and profiling_options in NPURunConfig Configuration, and environment variables PROFILING_MODE and PROFILING_OPTIONS. For details about the environment variables, see Environment Variables.
- The Profiler class does not support multi-thread calling.
Example
1 2 3 4 5 6 7 8 9 10 11 | import tensorflow as tf from npu_bridge.npu_init import * ...... a = tf.placeholder(tf.int32, (None,None)) b = tf.constant([[1,2],[2,3]], dtype=tf.int32, shape=(2,2)) add = tf.add(a, b) with tf.Session(config=session_config, graph=g) as sess: with profiler.Profiler(level="L1", aic_metrics=str("ArithmeticUtilization"), output_path = "./"): result=sess.run(add, feed_dict={a: [[-20, 2],[1,3]],c: [[1],[-21]]}) |
Parent topic: npu_bridge.profiler.profiler