}
}
-void TF_InitializeTPU(TF_Session* session, TF_Status* status) {
- VLOG(1) << "Initializing TPU";
- TF_Operation* config_op =
- TF_GraphOperationByName(session->graph, "ConfigureDistributedTPU");
- if (config_op == nullptr) {
- status->status = tensorflow::errors::Internal(
- "Unable to find node ConfigureDistributedTPU in the TF graph.");
- return;
- }
-
- TF_Output config_node{config_op, 0};
-
- TF_Tensor* dummy_output;
- TF_SessionRun(session, /*run_options*/ nullptr,
- // input related parameters
- /*inputs*/ nullptr, /*input_values*/ nullptr, /*ninputs*/ 0,
- // output related parameters
- /*outputs*/ &config_node, /*output_values*/ &dummy_output,
- /*noutputs*/ 1,
- /*targets*/ nullptr, /*ntargets*/ 0,
- /*run_metadata*/ nullptr, status);
- if (status->status.ok()) {
- TF_DeleteTensor(dummy_output);
- }
-}
-
-void TF_ShutdownTPU(TF_Session* session, TF_Status* status) {
- {
- tensorflow::mutex_lock c(session->graph->mu);
- VLOG(1) << "Shutting down TPU, with input graph: "
- << session->graph->graph.ToGraphDefDebug().DebugString();
- }
-
- TF_Operation* shutdown_op =
- TF_GraphOperationByName(session->graph, "ShutdownDistributedTPU");
- if (shutdown_op == nullptr) {
- status->status = tensorflow::errors::Internal(
- "Unable to find node ShutdownDistributedTPU in the TF graph.");
- return;
- }
-
- TF_SessionRun(session, /*run_options*/ nullptr,
- // input related parameters
- /*inputs*/ nullptr, /*input_values*/ nullptr, /*ninputs*/ 0,
- // output related parameters
- /*outputs*/ nullptr, /*output_values*/ nullptr,
- /*noutputs*/ 0,
- /*targets*/ &shutdown_op, /*ntargets*/ 1,
- /*run_metadata*/ nullptr, status);
-}
-
const char* TF_GraphDebugString(TF_Graph* graph, size_t* len) {
tensorflow::mutex_lock c(graph->mu);
const auto& debug_str = graph->graph.ToGraphDefDebug().DebugString();
TF_CAPI_EXPORT extern void TF_EnableXLACompilation(TF_SessionOptions* options,
unsigned char enable);
-// Initializes TPU system. Must be called exactly once before TF_SessionRun() is
-// called on a TPU graph.
-//
-// The session graph must contain a node named ConfigureDistributedTPU.
-// TODO(b/74774824): Improve the API on initializing TPU system.
-TF_CAPI_EXPORT extern void TF_InitializeTPU(TF_Session* session,
- TF_Status* status);
-
-// Shuts down TPU system. For any `session` where TF_InitializeTPU() has
-// been successfully called, this call must be made exactly once before the
-// session is closed.
-// The session graph must contain a node named ShutdownDistributedTPU.
-TF_CAPI_EXPORT extern void TF_ShutdownTPU(TF_Session* session,
- TF_Status* status);
-
-// Returns the graph content in a human-readable format, with length set in
-// `len`. The format is subject to change in the future.
-// The returned string is heap-allocated, and caller should call free() on it.
-TF_CAPI_EXPORT extern const char* TF_GraphDebugString(TF_Graph* graph,
- size_t* len);
-
// Returns the graph content in a human-readable format, with length set in
// `len`. The format is subject to change in the future.
// The returned string is heap-allocated, and caller should call free() on it.