Home | History | Annotate | Download | only in common_runtime
      1 /* Copyright 2015 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 // Register a factory that provides CPU devices.
     17 #include "tensorflow/core/common_runtime/threadpool_device.h"
     18 
     19 #include <vector>
     20 #include "tensorflow/core/common_runtime/device_factory.h"
     21 #include "tensorflow/core/framework/allocator.h"
     22 #include "tensorflow/core/public/session_options.h"
     23 
     24 namespace tensorflow {
     25 
     26 // TODO(zhifengc/tucker): Figure out the bytes of available RAM.
     27 class ThreadPoolDeviceFactory : public DeviceFactory {
     28  public:
     29   Status CreateDevices(const SessionOptions& options, const string& name_prefix,
     30                        std::vector<Device*>* devices) override {
     31     // TODO(zhifengc/tucker): Figure out the number of available CPUs
     32     // and/or NUMA configuration.
     33     int n = 1;
     34     auto iter = options.config.device_count().find("CPU");
     35     if (iter != options.config.device_count().end()) {
     36       n = iter->second;
     37     }
     38     for (int i = 0; i < n; i++) {
     39       string name = strings::StrCat(name_prefix, "/device:CPU:", i);
     40       devices->push_back(new ThreadPoolDevice(
     41           options, name, Bytes(256 << 20), DeviceLocality(), cpu_allocator()));
     42     }
     43 
     44     return Status::OK();
     45   }
     46 };
     47 
     48 REGISTER_LOCAL_DEVICE_FACTORY("CPU", ThreadPoolDeviceFactory, 60);
     49 
     50 }  // namespace tensorflow
     51