Skip to content

Commit fa0abcf

Browse files
Luke Iwanskibenoitsteiner
authored andcommitted
Registered More Ops for SYCL device
1 parent bc923f6 commit fa0abcf

9 files changed

Lines changed: 88 additions & 6 deletions

File tree

‎tensorflow/core/kernels/bcast_ops.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,14 @@ REGISTER_KERNEL_BUILDER(Name("BroadcastGradientArgs")
9090
.HostMemory("r1"),
9191
BCastGradArgsOp);
9292

93+
#if TENSORFLOW_USE_SYCL
94+
REGISTER_KERNEL_BUILDER(Name("BroadcastGradientArgs")
95+
.Device(DEVICE_SYCL)
96+
.TypeConstraint<int32>("T")
97+
.HostMemory("s0")
98+
.HostMemory("s1")
99+
.HostMemory("r0")
100+
.HostMemory("r1"),
101+
BCastGradArgsOp);
102+
#endif
93103
} // end namespace tensorflow

‎tensorflow/core/kernels/cwise_op_floor_div.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ limitations under the License.
1818
namespace tensorflow {
1919
REGISTER5(BinaryOp, CPU, "FloorDiv", functor::safe_floor_div, uint8, uint16,
2020
int16, int32, int64);
21+
#if TENSORFLOW_USE_SYCL
22+
#define REGISTER_SYCL_KERNEL(TYPE) \
23+
REGISTER_KERNEL_BUILDER( \
24+
Name("FloorDiv") \
25+
.Device(DEVICE_SYCL) \
26+
.TypeConstraint<TYPE>("T"), \
27+
BinaryOp<SYCLDevice, functor::floor_div<TYPE>>);
28+
TF_CALL_INTEGRAL_TYPES(REGISTER_SYCL_KERNEL);
29+
#undef REGISTER_SYCL_KERNEL
30+
#endif // TENSORFLOW_USE_SYCL
2131
#if GOOGLE_CUDA
2232
REGISTER4(BinaryOp, GPU, "FloorDiv", functor::floor_div, uint8, uint16, int16,
2333
int64);

‎tensorflow/core/kernels/cwise_op_isfinite.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ limitations under the License.
1818
namespace tensorflow {
1919
REGISTER3(UnaryOp, CPU, "IsFinite", functor::isfinite, float, Eigen::half,
2020
double);
21+
#if TENSORFLOW_USE_SYCL
22+
#define REGISTER_SYCL_KERNEL(TYPE) \
23+
REGISTER_KERNEL_BUILDER( \
24+
Name("IsFinite") \
25+
.Device(DEVICE_SYCL) \
26+
.TypeConstraint<TYPE>("T"), \
27+
UnaryOp<SYCLDevice, functor::isfinite<TYPE>>);
28+
TF_CALL_REAL_NUMBER_TYPES(REGISTER_SYCL_KERNEL);
29+
#undef REGISTER_SYCL_KERNEL
30+
#endif // TENSORFLOW_USE_SYCL
2131
#if GOOGLE_CUDA
2232
REGISTER3(UnaryOp, GPU, "IsFinite", functor::isfinite, float, Eigen::half,
2333
double);

‎tensorflow/core/kernels/cwise_op_isinf.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ limitations under the License.
1717

1818
namespace tensorflow {
1919
REGISTER3(UnaryOp, CPU, "IsInf", functor::isinf, float, Eigen::half, double);
20+
#if TENSORFLOW_USE_SYCL
21+
#define REGISTER_SYCL_KERNEL(TYPE) \
22+
REGISTER_KERNEL_BUILDER( \
23+
Name("IsInf") \
24+
.Device(DEVICE_SYCL) \
25+
.TypeConstraint<TYPE>("T"), \
26+
UnaryOp<SYCLDevice, functor::isinf<TYPE>>);
27+
TF_CALL_REAL_NUMBER_TYPES(REGISTER_SYCL_KERNEL);
28+
#undef REGISTER_SYCL_KERNEL
29+
#endif // TENSORFLOW_USE_SYCL
2030
#if GOOGLE_CUDA
2131
REGISTER3(UnaryOp, GPU, "IsInf", functor::isinf, float, Eigen::half, double);
2232
#endif

‎tensorflow/core/kernels/cwise_op_isnan.cc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ limitations under the License.
1717

1818
namespace tensorflow {
1919
REGISTER3(UnaryOp, CPU, "IsNan", functor::isnan, float, Eigen::half, double);
20+
#if TENSORFLOW_USE_SYCL
21+
#define REGISTER_SYCL_KERNEL(TYPE) \
22+
REGISTER_KERNEL_BUILDER( \
23+
Name("IsNan") \
24+
.Device(DEVICE_SYCL) \
25+
.TypeConstraint<TYPE>("T"), \
26+
UnaryOp<SYCLDevice, functor::isnan<TYPE>>);
27+
TF_CALL_REAL_NUMBER_TYPES(REGISTER_SYCL_KERNEL);
28+
#undef REGISTER_SYCL_KERNEL
29+
#endif // TENSORFLOW_USE_SYCL
2030
#if GOOGLE_CUDA
2131
REGISTER3(UnaryOp, GPU, "IsNan", functor::isnan, float, Eigen::half, double);
2232
#endif

‎tensorflow/core/kernels/cwise_ops_sycl_common.h‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ template <typename Functor>
4444
struct UnaryFunctor<SYCLDevice, Functor> {
4545
void operator()(const SYCLDevice& d, typename Functor::tout_type out,
4646
typename Functor::tin_type in) {
47-
LOG(FATAL) << "UnaryFunctor::operator() NOT IMPLEMENTED ! ";
47+
To32Bit(out).device(d) = To32Bit(in).unaryExpr(typename Functor::func());
4848
}
4949
};
5050

@@ -54,19 +54,21 @@ struct BinaryFunctor<SYCLDevice, Functor, NDIMS, has_errors> {
5454
void operator()(const SYCLDevice& d, typename Functor::tout_type out,
5555
typename Functor::tin_type in0,
5656
typename Functor::tin_type in1, bool* error) {
57-
Assign(d, out, in0.binaryExpr(in1, typename Functor::func()));
57+
To32Bit(out).device(d) = To32Bit(in0).binaryExpr(in1, typename Functor::func());
5858
}
5959

6060
void Left(const SYCLDevice& d, typename Functor::tout_type out,
6161
typename Functor::tscalar_type scalar,
6262
typename Functor::tin_type in, bool* error) {
63-
LOG(FATAL) << "BinaryFunctor::Left NOT IMPLEMENTED ! ";
63+
typedef typename Functor::func Binary;
64+
To32Bit(out).device(d) = To32Bit(in).binaryExpr(typename Functor::tin_type(scalar.data(),in.dimensions()), Binary());
6465
}
6566

6667
void Right(const SYCLDevice& d, typename Functor::tout_type out,
6768
typename Functor::tin_type in,
6869
typename Functor::tscalar_type scalar, bool* error) {
69-
LOG(FATAL) << "BinaryFunctor::Right NOT IMPLEMENTED ! ";
70+
typedef typename Functor::func Binary;
71+
To32Bit(out).device(d) = To32Bit(in).binaryExpr(typename Functor::tin_type(scalar.data(),in.dimensions()), Binary());
7072
}
7173

7274
void BCast(const SYCLDevice& d,
@@ -76,7 +78,25 @@ struct BinaryFunctor<SYCLDevice, Functor, NDIMS, has_errors> {
7678
typename TTypes<typename Functor::in_type, NDIMS>::ConstTensor in1,
7779
typename Eigen::array<Eigen::DenseIndex, NDIMS> bcast1,
7880
bool* error) {
79-
LOG(FATAL) << "BinaryFunctor::BCast NOT IMPLEMENTED ";
81+
typedef typename Functor::in_type T;
82+
typename Functor::func func;
83+
if ((NDIMS == 2) && Functor::use_bcast_optimization &&
84+
use_bcast_optimization<T>::value) {
85+
const bool bcast0_all_one = AllOne<NDIMS>(bcast0);
86+
const bool bcast1_all_one = AllOne<NDIMS>(bcast1);
87+
if (bcast0_all_one && !bcast1_all_one) {
88+
To32Bit(out).device(d) =
89+
To32Bit(in0).binaryExpr(To32Bit(in1).broadcast(bcast1), func);
90+
return;
91+
}
92+
if (!bcast0_all_one && bcast1_all_one) {
93+
To32Bit(out).device(d) =
94+
To32Bit(in0).broadcast(bcast0).binaryExpr(To32Bit(in1), func);
95+
return;
96+
}
97+
}
98+
To32Bit(out).device(d) = To32Bit(in0).broadcast(bcast0).binaryExpr(
99+
To32Bit(in1).broadcast(bcast1), func);
80100
}
81101
};
82102

‎tensorflow/core/kernels/sendrecv_ops.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ REGISTER_KERNEL_BUILDER(Name("_Send").Device(DEVICE_GPU), SendOp);
8080

8181
#if TENSORFLOW_USE_SYCL
8282
REGISTER_KERNEL_BUILDER(Name("_Send").Device(DEVICE_SYCL), SendOp);
83+
REGISTER_KERNEL_BUILDER(
84+
Name("_HostSend").Device(DEVICE_SYCL).HostMemory("tensor"), SendOp);
8385
#endif
8486

8587
REGISTER_KERNEL_BUILDER(Name("_HostSend").Device(DEVICE_CPU), SendOp);

‎tensorflow/python/kernel_tests/basic_gpu_test.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import math
2323
import numpy as np
2424
from tensorflow.python.ops import gen_math_ops
25+
from tensorflow.python.ops.gen_array_ops import _broadcast_gradient_args
2526

2627
class GPUBinaryOpsTest(tf.test.TestCase):
2728
def _compareGPU(self, x, y, np_func, tf_func):
@@ -46,6 +47,15 @@ def testFloatBasic(self):
4647
self._compareGPU(x, y, np.subtract, tf.sub)
4748
self._compareGPU(x, y, np.multiply, tf.mul)
4849
self._compareGPU(x, y + 0.1, np.true_divide, tf.truediv)
50+
51+
def _GetGradientArgs(self, xs, ys):
52+
with self.test_session(use_gpu=True) as sess:
53+
return sess.run(_broadcast_gradient_args(xs, ys))
54+
55+
def testBroadcast(self):
56+
r0, r1 = self._GetGradientArgs([2, 3, 5], [1])
57+
self.assertAllEqual(r0, [])
58+
self.assertAllEqual(r1, [0, 1, 2])
4959

5060
if __name__ == "__main__":
5161
tf.test.main()

‎third_party/sycl/crosstool/computecpp.tpl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def main():
5050

5151
x = subprocess.call([COMPUTECPP_DRIVER] +computecpp_compiler_flags )
5252
if(x == 0):
53-
host_compiler_flags = ['-DTENSORFLOW_USE_SYCL', '-Wno-unused-variable', '-I', COMPUTECPP_INCLUDE, "--include",bc_out] + host_compiler_flags
53+
host_compiler_flags = ['-D_GLIBCXX_USE_CXX11_ABI=0', '-DTENSORFLOW_USE_SYCL', '-Wno-unused-variable', '-I', COMPUTECPP_INCLUDE, "--include",bc_out] + host_compiler_flags
5454
return subprocess.call([CPU_CXX_COMPILER] +host_compiler_flags )
5555
return x
5656
else:

0 commit comments

Comments
 (0)