| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2996,14 +2996,14 @@ cc_library( | |||
| 2996 | 2996 | srcs = if_not_windows([ | |
| 2997 | 2997 | "common_runtime/sycl/sycl_allocator.cc", | |
| 2998 | 2998 | "common_runtime/sycl/sycl_device.cc", | |
| 2999 | - "common_runtime/sycl/sycl_device_context.cc", | ||
| 3000 | 2999 | "common_runtime/sycl/sycl_device_factory.cc", | |
| 3000 | + "common_runtime/sycl/sycl_util.cc", | ||
| 3001 | 3001 | ]), | |
| 3002 | 3002 | hdrs = if_not_windows([ | |
| 3003 | 3003 | "common_runtime/sycl/sycl_allocator.h", | |
| 3004 | 3004 | "common_runtime/sycl/sycl_device.h", | |
| 3005 | - "common_runtime/sycl/sycl_util.h", | ||
| 3006 | 3005 | "common_runtime/sycl/sycl_device_context.h", | |
| 3006 | + "common_runtime/sycl/sycl_util.h", | ||
| 3007 | 3007 | ]), | |
| 3008 | 3008 | copts = tf_copts(), | |
| 3009 | 3009 | linkstatic = 0, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,8 +158,13 @@ Status SYCLDevice::MakeTensorFromProto(const TensorProto& tensor_proto, | |||
| 158 | 158 | " and type ", DataTypeString(parsed.dtype())); | |
| 159 | 159 | } | |
| 160 | 160 | ||
| 161 | + Notification n; | ||
| 161 | 162 | device_context_->CopyCPUTensorToDevice( | |
| 162 | - &parsed, this, ©, [&status](const Status& s) { status = s; }); | ||
| 163 | + &parsed, this, ©, [&status, &n](const Status& s) { | ||
| 164 | + status = s; | ||
| 165 | + n.Notify(); | ||
| 166 | + }); | ||
| 167 | + n.WaitForNotification(); | ||
| 163 | 168 | *tensor = copy; | |
| 164 | 169 | } | |
| 165 | 170 | return status; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ limitations under the License. | |||
| 21 | 21 | #define TENSORFLOW_COMMON_RUNTIME_SYCL_SYCL_DEVICE_CONTEXT_H_ | |
| 22 | 22 | ||
| 23 | 23 | #include "tensorflow/core/common_runtime/device.h" | |
| 24 | + #include "tensorflow/core/common_runtime/sycl/sycl_util.h" | ||
| 24 | 25 | #include "tensorflow/core/framework/device_base.h" | |
| 25 | 26 | ||
| 26 | 27 | namespace tensorflow { | |
@@ -31,13 +32,18 @@ class SYCLDeviceContext : public DeviceContext { | |||
| 31 | 32 | ||
| 32 | 33 | ~SYCLDeviceContext() override {} | |
| 33 | 34 | ||
| 34 | - void CopyCPUTensorToDevice(const Tensor *cpu_tensor, Device *device, | ||
| 35 | - Tensor *device_tensor, | ||
| 36 | - StatusCallback done) const override; | ||
| 37 | - | ||
| 38 | - void CopyDeviceTensorToCPU(const Tensor *device_tensor, StringPiece edge_name, | ||
| 39 | - Device *device, Tensor *cpu_tensor, | ||
| 40 | - StatusCallback done) override; | ||
| 35 | + inline void CopyCPUTensorToDevice(const Tensor *cpu_tensor, Device *device, | ||
| 36 | + Tensor *device_tensor, | ||
| 37 | + StatusCallback done) const override { | ||
| 38 | + SYCLUtil::copyCPUTensorToDevice(device, *cpu_tensor, *device_tensor, done); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + inline void CopyDeviceTensorToCPU(const Tensor *device_tensor, | ||
| 42 | + StringPiece, | ||
| 43 | + Device *device, Tensor *cpu_tensor, | ||
| 44 | + StatusCallback done) override { | ||
| 45 | + SYCLUtil::copyDeviceTensorToCPU(device, *device_tensor, *cpu_tensor, done); | ||
| 46 | + } | ||
| 41 | 47 | }; | |
| 42 | 48 | ||
| 43 | 49 | } // namespace tensorflow | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,64 @@ | |||
| 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 | + #ifdef TENSORFLOW_USE_SYCL | ||
| 17 | + | ||
| 18 | + #include "tensorflow/core/common_runtime/sycl/sycl_util.h" | ||
| 19 | + #include "tensorflow/core/framework/tensor_reference.h" | ||
| 20 | + #include "tensorflow/core/lib/core/refcount.h" | ||
| 21 | + | ||
| 22 | + namespace tensorflow { | ||
| 23 | + | ||
| 24 | + void SYCLUtil::copyCPUTensorToDevice(const Eigen::SyclDevice& sycl_device, | ||
| 25 | + const Tensor& cpu_tensor, | ||
| 26 | + Tensor& device_tensor, | ||
| 27 | + StatusCallback done) { | ||
| 28 | + const int64 total_bytes = cpu_tensor.TotalBytes(); | ||
| 29 | + const void *src_ptr = GetBase(&cpu_tensor); | ||
| 30 | + void *dst_ptr = GetBase(&device_tensor); | ||
| 31 | + TensorReference input_ref(cpu_tensor); | ||
| 32 | + sycl_device.memcpyHostToDevice(dst_ptr, src_ptr, total_bytes, | ||
| 33 | + [done, input_ref]() { | ||
| 34 | + input_ref.Unref(); | ||
| 35 | + done(Status::OK()); | ||
| 36 | + }); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + void SYCLUtil::copyDeviceTensorToCPU(const Eigen::SyclDevice& sycl_device, | ||
| 40 | + const Tensor& device_tensor, | ||
| 41 | + Tensor& cpu_tensor, | ||
| 42 | + StatusCallback done) { | ||
| 43 | + const int64 total_bytes = device_tensor.TotalBytes(); | ||
| 44 | + const void *src_ptr = GetBase(&device_tensor); | ||
| 45 | + void *dst_ptr = GetBase(&cpu_tensor); | ||
| 46 | + TensorReference input_ref(device_tensor); | ||
| 47 | + sycl_device.memcpyDeviceToHost(dst_ptr, src_ptr, total_bytes, | ||
| 48 | + [done, input_ref]() { | ||
| 49 | + input_ref.Unref(); | ||
| 50 | + done(Status::OK()); | ||
| 51 | + }); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + void SYCLUtil::copyDeviceTensorToDevice(const Eigen::SyclDevice& sycl_device, | ||
| 55 | + const Tensor& src_tensor, | ||
| 56 | + Tensor& dst_tensor) { | ||
| 57 | + const int64 total_bytes = src_tensor.TotalBytes(); | ||
| 58 | + const void* src_ptr = GetBase(&src_tensor); | ||
| 59 | + void* dst_ptr = GetBase(&dst_tensor); | ||
| 60 | + sycl_device.memcpy(dst_ptr, src_ptr, total_bytes); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + } // namespace tensorflow | ||
| 64 | + #endif // TENSORFLOW_USE_SYCL | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments