1/* Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_PROCESS_UTIL_H_
17#define TENSORFLOW_CORE_COMMON_RUNTIME_PROCESS_UTIL_H_
18
19#include <functional>
20
21#include "tensorflow/core/lib/core/threadpool.h"
22#include "tensorflow/core/public/session_options.h"
23
24// TODO(vrv, mrry): Remove this library: its interface circumvents the
25// callers' Env and calls Env::Default() directly.
26
27namespace tensorflow {
28
29// Returns a process-wide ThreadPool for scheduling compute operations
30// using 'options'. Caller does not take ownership over threadpool.
31thread::ThreadPool* ComputePool(const SessionOptions& options);
32
33// Returns the TF_NUM_INTEROP_THREADS environment value, or 0 if not specified.
34int32 NumInterOpThreadsFromEnvironment();
35
36// Returns the TF_NUM_INTRAOP_THREADS environment value, or 0 if not specified.
37int32 NumIntraOpThreadsFromEnvironment();
38
39// Returns the number of inter op threads specified in `options` or a default.
40// If no value or a negative value is specified in the provided options, then
41// the function returns the value defined in the TF_NUM_INTEROP_THREADS
42// environment variable. If neither a value is specified in the options or in
43// the environment, this function will return a reasonable default value based
44// on the number of schedulable CPUs, and any MKL and OpenMP configurations.
45int32 NumInterOpThreadsFromSessionOptions(const SessionOptions& options);
46
47// Creates a thread pool with number of inter op threads.
48thread::ThreadPool* NewThreadPoolFromSessionOptions(
49 const SessionOptions& options);
50
51// Schedule "closure" in the default thread queue.
52void SchedClosure(std::function<void()> closure);
53
54// Schedule "closure" after the given number of microseconds in the
55// fixed-size ThreadPool used for non-blocking compute tasks.
56void SchedNonBlockingClosureAfter(int64_t micros,
57 std::function<void()> closure);
58
59} // namespace tensorflow
60
61#endif // TENSORFLOW_CORE_COMMON_RUNTIME_PROCESS_UTIL_H_
62