aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mehdi Goli <mehdi.goli@codeplay.com>2017-05-22 16:49:32 +0100
committerGravatar Mehdi Goli <mehdi.goli@codeplay.com>2017-05-22 16:49:32 +0100
commit76c0fc1f955eda3d243db8960cb6fee9a5305112 (patch)
tree76ce81fd151bfa088ceb3acba3c310cc80f47804
parent0d08165a7f7a95c35dead32ec2d567e9a4b609b0 (diff)
Fixing SYCL alignment issue required by TensorFlow.
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h
index c5142b7c9..627c0ab19 100644
--- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h
+++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h
@@ -14,7 +14,23 @@
#if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H)
#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H
+template<size_t Align> struct CheckAlignStatically{
+ static const bool Val= (((Align&(Align-1))==0) && (Align >= sizeof(void *)));
+};
+template <bool IsAligned, size_t Align>
+struct Conditional_Allocate{
+
+EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){
+ return aligned_alloc(Align, elements);
+}
+};
+template <size_t Align>
+struct Conditional_Allocate<false, Align>{
+EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){
+ return malloc(elements);
+}
+};
template <typename Scalar, size_t Align = EIGEN_MAX_ALIGN_BYTES, class Allocator = std::allocator<Scalar>>
struct SyclAllocator {
typedef Scalar value_type;
@@ -22,7 +38,10 @@ struct SyclAllocator {
typedef typename std::allocator_traits<Allocator>::size_type size_type;
SyclAllocator( ){};
- Scalar* allocate(std::size_t elements) { return static_cast<Scalar*>(aligned_alloc(Align, elements)); }
+ Scalar* allocate(std::size_t elements) {
+ return static_cast<Scalar*>(Conditional_Allocate<CheckAlignStatically<Align>::Val, Align>::conditional_allocate(elements));
+ // return static_cast<Scalar*>(aligned_alloc(Align, elements));
+ }
void deallocate(Scalar * p, std::size_t size) { EIGEN_UNUSED_VARIABLE(size); free(p); }
};
@@ -533,4 +552,4 @@ struct SyclKernelDevice:DefaultDevice{};
} // end namespace Eigen
-#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H
+#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H \ No newline at end of file