Skip to content

Commit 987c2d7

Browse files
Luke Iwanskibenoitsteiner
authored andcommitted
Workaround for 0 bytes allocation for SYCL device (#42)
1 parent 2fcc3f7 commit 987c2d7

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

tensorflow/core/common_runtime/sycl/sycl_allocator.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ string SYCLAllocator::Name() { return "device:SYCL"; }
2525

2626
void *SYCLAllocator::AllocateRaw(size_t alignment, size_t num_bytes) {
2727
assert(device_);
28+
if(num_bytes == 0) {
29+
return device_->allocate(1);
30+
}
2831
auto p = device_->allocate(num_bytes);
2932
return p;
3033
}

tensorflow/core/kernels/reduction_ops_max.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ REGISTER_KERNEL_BUILDER(
6666
.TypeConstraint<int32>("Tidx") \
6767
.HostMemory("reduction_indices"), \
6868
ReductionOp<SYCLDevice, type, Eigen::internal::MaxReducer<type>>);
69-
REGISTER_SYCL_KERNELS(float);
69+
// REGISTER_SYCL_KERNELS(float);
7070
#undef REGISTER_SYCL_KERNELS
7171

7272
REGISTER_KERNEL_BUILDER(

tensorflow/core/kernels/stage_op.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ REGISTER_KERNEL_BUILDER(Name("Stage").Device(DEVICE_CPU), StageOp);
9999
#if GOOGLE_CUDA
100100
REGISTER_KERNEL_BUILDER(Name("Stage").Device(DEVICE_GPU), StageOp);
101101
#endif
102+
#ifdef TENSORFLOW_USE_SYCL
103+
REGISTER_KERNEL_BUILDER(Name("Stage").Device(DEVICE_SYCL), StageOp);
104+
#endif // TENSORFLOW_USE_SYCL
102105

103106
class UnstageOp : public OpKernel {
104107
public:
@@ -126,5 +129,8 @@ REGISTER_KERNEL_BUILDER(Name("Unstage").Device(DEVICE_CPU), UnstageOp);
126129
#if GOOGLE_CUDA
127130
REGISTER_KERNEL_BUILDER(Name("Unstage").Device(DEVICE_GPU), UnstageOp);
128131
#endif
132+
#ifdef TENSORFLOW_USE_SYCL
133+
REGISTER_KERNEL_BUILDER(Name("Unstage").Device(DEVICE_SYCL), UnstageOp);
134+
#endif // TENSORFLOW_USE_SYCL
129135

130136
} // namespace tensorflow

tensorflow/python/kernel_tests/stage_op_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def testSimple(self):
3131
with ops.device('/cpu:0'):
3232
x = array_ops.placeholder(dtypes.float32)
3333
v = 2. * (array_ops.zeros([1024, 1024]) + x)
34-
with ops.device('/gpu:0'):
34+
with ops.device(test.gpu_device_name()):
3535
stager = data_flow_ops.StagingArea([dtypes.float32])
3636
stage = stager.put([v])
3737
y = stager.get()
@@ -46,7 +46,7 @@ def testMultiple(self):
4646
with ops.device('/cpu:0'):
4747
x = array_ops.placeholder(dtypes.float32)
4848
v = 2. * (array_ops.zeros([128, 128]) + x)
49-
with ops.device('/gpu:0'):
49+
with ops.device(test.gpu_device_name()):
5050
stager = data_flow_ops.StagingArea([dtypes.float32, dtypes.float32])
5151
stage = stager.put([x, v])
5252
z, y = stager.get()
@@ -62,7 +62,7 @@ def testDictionary(self):
6262
with ops.device('/cpu:0'):
6363
x = array_ops.placeholder(dtypes.float32)
6464
v = 2. * (array_ops.zeros([128, 128]) + x)
65-
with ops.device('/gpu:0'):
65+
with ops.device(test.gpu_device_name()):
6666
stager = data_flow_ops.StagingArea(
6767
[dtypes.float32, dtypes.float32],
6868
shapes=[[], [128, 128]],

0 commit comments

Comments
 (0)