【问题标题】:Tensorflow c api trace dataTensorflow c api 跟踪数据
【发布时间】:2018-07-29 12:38:06
【问题描述】:

我想知道如何使用 C API Tensorflow 从 Session 运行中获取 FULL_TRACE 数据。 我的问题是我找到了 python 示例,但我不知道如何使用 C API 实现它。

python 示例:

使用完整跟踪选项运行图表

with tf.Session() as sess:
    run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    run_metadata = tf.RunMetadata()
    sess.run(res, options=run_options, run_metadata=run_metadata)

    # Create the Timeline object, and write it to a json
    tl = timeline.Timeline(run_metadata.step_stats)
    ctf = tl.generate_chrome_trace_format()
    with open('timeline.json', 'w') as f:
        f.write(ctf)

C API 函数。

TF_CAPI_EXPORT 外部无效 TF_SessionRun(

TF_Session* session,
// RunOptions
const TF_Buffer* run_options,
// Input tensors
const TF_Output* inputs, TF_Tensor* const* input_values, int ninputs,
// Output tensors
const TF_Output* outputs, TF_Tensor** output_values, int noutputs,
// Target operations
const TF_Operation* const* target_opers, int ntargets,
// RunMetadata
TF_Buffer* run_metadata,
// Output status
TF_Status*);

感谢您的帮助。

【问题讨论】:

    标签: tensorflow profiler c-api


    【解决方案1】:

    如果您问,如何将选项放入您的 TF_SessionRun。 这是从 Python 中提取它们并在 C-API 中使用它们的解决方法。

    Python

    runOptions = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
    runConfig = tf.ConfigProto(run_options=runOptions) # run_options?
    runConfSer = [int(i) for in in runConfig.SerializeToString()] # -> <runConfSer>
    

    C-API

    TF_SessionOptions* sess_opts = TF_NewSessionOptions();
    uint8_t configProto[] = { <runConfSer> }; // <= <runConfSer>
    size_t configProtoLen = sizeof(configProto) / sizeof(uint8_t);
    TF_SetConfig(sess_opts, configProto, configProtoLen, status);
    assert(TF_GetCode(status) == TF_OK);
    TF_Session* session = TF_NewSession(graph, sess_opts, status);
    assert(TF_GetCode(status) == TF_OK);
    TF_SessionRun(session, nullptr,
                    &inputs[0], &input_values[0], inputs.size(),
                    &outputs[0], &output_values[0], outputs.size(),
                    nullptr, 0, nullptr, status);
    

    【讨论】:

    • 如果答案有帮助,请不要犹豫,点赞; ) (或者你以前是否这样做过 - 然后忽略这个)
    • 我之前想通了。使用 FULL_TRACE 导致 android 性能不佳。
    猜你喜欢
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多