Home | History | Annotate | Download | only in sycl
      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 #if TENSORFLOW_USE_SYCL
     17 
     18 #include "tensorflow/core/common_runtime/device_factory.h"
     19 #include "tensorflow/core/common_runtime/sycl/sycl_device.h"
     20 
     21 #include "tensorflow/core/common_runtime/sycl/sycl_util.h"
     22 
     23 namespace tensorflow {
     24 
     25 class SYCLDeviceFactory : public DeviceFactory {
     26  public:
     27   Status CreateDevices(const SessionOptions &options, const string &name_prefix,
     28                        std::vector<Device *> *devices) override {
     29     auto syclInterface = GSYCLInterface::instance();
     30 
     31     size_t n = 1;
     32     auto iter = options.config.device_count().find("SYCL");
     33     if (iter != options.config.device_count().end()) {
     34       n = iter->second;
     35     }
     36 
     37     for (int i = 0; i < n; i++) {
     38       string name = strings::StrCat(name_prefix, "/device:SYCL:", i);
     39       devices->push_back(new SYCLDevice(
     40           options, name, Bytes(256 << 20), DeviceLocality(),
     41           syclInterface->GetShortDeviceDescription(i),
     42           syclInterface->GetSYCLAllocator(i), syclInterface->GetCPUAllocator(i),
     43           syclInterface->GetSYCLContext(i)));
     44     }
     45 
     46     return Status::OK();
     47   }
     48 };
     49 
     50 REGISTER_LOCAL_DEVICE_FACTORY("SYCL", SYCLDeviceFactory, 200);
     51 }  // namespace tensorflow
     52 
     53 #endif  // TENSORFLOW_USE_SYCL
     54