1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations 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 27 namespace tensorflow { 28 29 // Returns a process-wide ThreadPool for scheduling compute operations 30 // using 'options'. Caller does not take ownership over threadpool. 31 thread::ThreadPool* ComputePool(const SessionOptions& options); 32 33 // Returns the TF_NUM_INTEROP_THREADS environment value, or 0 if not specified. 34 int32 NumInterOpThreadsFromEnvironment(); 35 36 // Returns the TF_NUM_INTRAOP_THREADS environment value, or 0 if not specified. 37 int32 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. 45 int32 NumInterOpThreadsFromSessionOptions(const SessionOptions& options); 46 47 // Creates a thread pool with number of inter op threads. 48 thread::ThreadPool* NewThreadPoolFromSessionOptions( 49 const SessionOptions& options); 50 51 // Schedule "closure" in the default thread queue. 52 void 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. 56 void SchedNonBlockingClosureAfter(int64 micros, std::function<void()> closure); 57 58 } // namespace tensorflow 59 60 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_PROCESS_UTIL_H_ 61