From 76c0fc1f955eda3d243db8960cb6fee9a5305112 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Mon, 22 May 2017 16:49:32 +0100 Subject: Fixing SYCL alignment issue required by TensorFlow. --- .../Eigen/CXX11/src/Tensor/TensorDeviceSycl.h | 23 ++++++++++++++++++++-- 1 file 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 struct CheckAlignStatically{ + static const bool Val= (((Align&(Align-1))==0) && (Align >= sizeof(void *))); +}; +template +struct Conditional_Allocate{ + +EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){ + return aligned_alloc(Align, elements); +} +}; +template +struct Conditional_Allocate{ +EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){ + return malloc(elements); +} +}; template > struct SyclAllocator { typedef Scalar value_type; @@ -22,7 +38,10 @@ struct SyclAllocator { typedef typename std::allocator_traits::size_type size_type; SyclAllocator( ){}; - Scalar* allocate(std::size_t elements) { return static_cast(aligned_alloc(Align, elements)); } + Scalar* allocate(std::size_t elements) { + return static_cast(Conditional_Allocate::Val, Align>::conditional_allocate(elements)); + // return static_cast(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 -- cgit v1.2.3 From e3f964ed55a96d0c94814d07ab88d8805e0c2eec Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Thu, 25 May 2017 11:17:26 +0100 Subject: Applying Benoit's comment;removing dead code. --- unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h index 627c0ab19..27c10a0cf 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h @@ -40,7 +40,6 @@ struct SyclAllocator { SyclAllocator( ){}; Scalar* allocate(std::size_t elements) { return static_cast(Conditional_Allocate::Val, Align>::conditional_allocate(elements)); - // return static_cast(aligned_alloc(Align, elements)); } void deallocate(Scalar * p, std::size_t size) { EIGEN_UNUSED_VARIABLE(size); free(p); } }; -- cgit v1.2.3 From 0370d3576e1df4f898b9030fbc269ec0488d3969 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Fri, 26 May 2017 16:01:48 +0100 Subject: Applying Ronnan's comments. --- .../Eigen/CXX11/src/Tensor/TensorDeviceSycl.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h index 27c10a0cf..09c96317e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h @@ -14,22 +14,22 @@ #if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H) #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H -template struct CheckAlignStatically{ +template struct CheckAlignStatically { static const bool Val= (((Align&(Align-1))==0) && (Align >= sizeof(void *))); }; template -struct Conditional_Allocate{ +struct Conditional_Allocate { -EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){ - return aligned_alloc(Align, elements); -} + EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements) { + return aligned_alloc(Align, elements); + } }; template -struct Conditional_Allocate{ +struct Conditional_Allocate { -EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){ - return malloc(elements); -} + EIGEN_ALWAYS_INLINE static void* conditional_allocate(std::size_t elements){ + return malloc(elements); + } }; template > struct SyclAllocator { @@ -551,4 +551,4 @@ struct SyclKernelDevice:DefaultDevice{}; } // end namespace Eigen -#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H \ No newline at end of file +#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H -- cgit v1.2.3