FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[SYCL] Prepare for async execution · codeplaysoftware/tensorflow@849383c · GitHub

Repository navigation

Commit 849383c

Browse files
committed
[SYCL] Prepare for async execution
1 parent 1c4ca50 commit 849383c

19 files changed

Lines changed: 239 additions & 336 deletions

‎tensorflow/core/BUILD‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,14 +2996,14 @@ cc_library(
29962996
srcs = if_not_windows([
29972997
"common_runtime/sycl/sycl_allocator.cc",
29982998
"common_runtime/sycl/sycl_device.cc",
2999-
"common_runtime/sycl/sycl_device_context.cc",
30002999
"common_runtime/sycl/sycl_device_factory.cc",
3000+
"common_runtime/sycl/sycl_util.cc",
30013001
]),
30023002
hdrs = if_not_windows([
30033003
"common_runtime/sycl/sycl_allocator.h",
30043004
"common_runtime/sycl/sycl_device.h",
3005-
"common_runtime/sycl/sycl_util.h",
30063005
"common_runtime/sycl/sycl_device_context.h",
3006+
"common_runtime/sycl/sycl_util.h",
30073007
]),
30083008
copts = tf_copts(),
30093009
linkstatic = 0,

‎tensorflow/core/common_runtime/sycl/sycl_device.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,13 @@ Status SYCLDevice::MakeTensorFromProto(const TensorProto& tensor_proto,
158158
" and type ", DataTypeString(parsed.dtype()));
159159
}
160160

161+
Notification n;
161162
device_context_->CopyCPUTensorToDevice(
162-
&parsed, this, &copy, [&status](const Status& s) { status = s; });
163+
&parsed, this, &copy, [&status, &n](const Status& s) {
164+
status = s;
165+
n.Notify();
166+
});
167+
n.WaitForNotification();
163168
*tensor = copy;
164169
}
165170
return status;

‎tensorflow/core/common_runtime/sycl/sycl_device_context.cc‎

Lines changed: 0 additions & 211 deletions
This file was deleted.

‎tensorflow/core/common_runtime/sycl/sycl_device_context.h‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ limitations under the License.
2121
#define TENSORFLOW_COMMON_RUNTIME_SYCL_SYCL_DEVICE_CONTEXT_H_
2222

2323
#include "tensorflow/core/common_runtime/device.h"
24+
#include "tensorflow/core/common_runtime/sycl/sycl_util.h"
2425
#include "tensorflow/core/framework/device_base.h"
2526

2627
namespace tensorflow {
@@ -31,13 +32,18 @@ class SYCLDeviceContext : public DeviceContext {
3132

3233
~SYCLDeviceContext() override {}
3334

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+
}
4147
};
4248

4349
} // namespace tensorflow
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL