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 #include "tensorflow/core/common_runtime/device.h"
     17 
     18 #include "tensorflow/core/framework/op_segment.h"
     19 #include "tensorflow/core/lib/core/errors.h"
     20 #include "tensorflow/core/lib/random/random.h"
     21 #include "tensorflow/core/platform/logging.h"
     22 #include "tensorflow/core/platform/types.h"
     23 
     24 namespace tensorflow {
     25 
     26 Device::Device(Env* env, const DeviceAttributes& device_attributes)
     27     : DeviceBase(env), device_attributes_(device_attributes) {
     28   CHECK(DeviceNameUtils::ParseFullName(name(), &parsed_name_))
     29       << "Invalid device name: " << name();
     30   rmgr_ = new ResourceMgr(parsed_name_.job);
     31 }
     32 
     33 Device::~Device() {
     34   if (rmgr_ != nullptr) {
     35     DeleteResourceMgr();
     36   }
     37 }
     38 
     39 // static
     40 DeviceAttributes Device::BuildDeviceAttributes(
     41     const string& name, DeviceType device, Bytes memory_limit,
     42     const DeviceLocality& locality, const string& physical_device_desc) {
     43   DeviceAttributes da;
     44   da.set_name(name);
     45   do {
     46     da.set_incarnation(random::New64());
     47   } while (da.incarnation() == 0);  // This proto field must not be zero
     48   da.set_device_type(device.type());
     49   da.set_memory_limit(memory_limit.value());
     50   *da.mutable_locality() = locality;
     51   da.set_physical_device_desc(physical_device_desc);
     52   return da;
     53 }
     54 
     55 }  // namespace tensorflow
     56