From 7318daf887c4f06fa62e59e29fa675e48ad168f9 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Fri, 25 Nov 2016 16:19:07 +0000 Subject: Fixing LLVM error on TensorMorphingSycl.h on GPU; fixing int64_t crash for tensor_broadcast_sycl on GPU; adding get_sycl_supported_devices() on syclDevice.h. --- .../Eigen/CXX11/src/Tensor/TensorReductionSycl.h | 48 +++++++++++++--------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h b/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h index 2f7468d56..00f8b70ed 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorReductionSycl.h @@ -25,6 +25,7 @@ namespace Eigen { namespace internal { + template struct syclGenericBufferReducer{ template static void run(BufferTOut& bufOut, BufferTIn& bufI, const Eigen::SyclDevice& dev, size_t length, size_t local){ @@ -180,6 +181,7 @@ struct FullReducer { }; + template struct InnerReducer { @@ -190,42 +192,50 @@ struct InnerReducer { typedef const typename Self::ChildType HostExpr; /// this is the child of reduction typedef typename TensorSycl::internal::createPlaceHolderExpression::Type PlaceHolderExpr; auto functors = TensorSycl::internal::extractFunctors(self.impl()); + typedef decltype(functors) FunctorExpr; typename Self::Index range, GRange, tileSize; - dev.parallel_for_setup(num_coeffs_to_preserve, tileSize, range, GRange); + typedef typename Eigen::internal::remove_all::type Dims; + // getting final out buffer at the moment the created buffer is true because there is no need for assign /// creating the shared memory for calculating reduction. /// This one is used to collect all the reduced value of shared memory as we dont have global barrier on GPU. Once it is saved we can /// recursively apply reduction on it in order to reduce the whole. - typedef typename Eigen::internal::remove_all::type Dims; - Dims dims= self.xprDims(); - Op functor = reducer; + // Dims dims= self.xprDims(); + //Op functor = reducer; + dev.parallel_for_setup(num_coeffs_to_preserve, tileSize, range, GRange); dev.sycl_queue().submit([&](cl::sycl::handler &cgh) { // create a tuple of accessors from Evaluator auto tuple_of_accessors = TensorSycl::internal::createTupleOfAccessors(cgh, self.impl()); + typedef typename Eigen::internal::remove_all::type Tuple_of_Acc; auto output_accessor = dev.template get_sycl_accessor(cgh, output); - cgh.parallel_for( cl::sycl::nd_range<1>(cl::sycl::range<1>(GRange), cl::sycl::range<1>(tileSize)), [=](cl::sycl::nd_item<1> itemID) { - typedef typename TensorSycl::internal::ConvertToDeviceExpression::Type DevExpr; - auto device_expr = TensorSycl::internal::createDeviceExpression(functors, tuple_of_accessors); + cgh.parallel_for( cl::sycl::nd_range<1>(cl::sycl::range<1>(GRange), cl::sycl::range<1>(tileSize)), + TensorSycl::internal::ReductionFunctor + (output_accessor, functors, tuple_of_accessors, self.xprDims(), reducer, range)); + + + // [=](cl::sycl::nd_item<1> itemID) { + // typedef typename TensorSycl::internal::ConvertToDeviceExpression::Type DevExpr; + // auto device_expr = TensorSycl::internal::createDeviceExpression(functors, tuple_of_accessors); /// reduction cannot be captured automatically through our device conversion recursion. The reason is that reduction has two behaviour /// the first behaviour is when it is used as a root to lauch the sub-kernel. The second one is when it is treated as a leafnode to pass the /// calculated result to its parent kernel. While the latter is automatically detected through our device expression generator. The former is created here. - const auto device_self_expr= TensorReductionOp(device_expr.expr, dims, functor); + // const auto device_self_expr= TensorReductionOp(device_expr.expr, dims, functor); /// This is the evaluator for device_self_expr. This is exactly similar to the self which has been passed to run function. The difference is /// the device_evaluator is detectable and recognisable on the device. - typedef Eigen::TensorEvaluator DeviceSelf; - auto device_self_evaluator = Eigen::TensorEvaluator(device_self_expr, Eigen::DefaultDevice()); - auto output_accessor_ptr =ConvertToActualTypeSycl(typename DeviceSelf::CoeffReturnType, output_accessor); + // typedef Eigen::TensorEvaluator DeviceSelf; + // auto device_self_evaluator = Eigen::TensorEvaluator(device_self_expr, Eigen::DefaultDevice()); + // auto output_accessor_ptr =ConvertToActualTypeSycl(typename DeviceSelf::CoeffReturnType, output_accessor); /// const cast added as a naive solution to solve the qualifier drop error - auto globalid=itemID.get_global_linear_id(); - if (globalid< range) { - typename DeviceSelf::CoeffReturnType accum = functor.initialize(); - GenericDimReducer::reduce(device_self_evaluator, device_self_evaluator.firstInput(static_cast(globalid)),const_cast(functor), &accum); - functor.finalize(accum); - output_accessor_ptr[globalid]= accum; - } - }); + // auto globalid=itemID.get_global_linear_id(); + // if (globalid< range) { + // typename DeviceSelf::CoeffReturnType accum = functor.initialize(); + // GenericDimReducer::reduce(device_self_evaluator, device_self_evaluator.firstInput(static_cast(globalid)),const_cast(functor), &accum); + // functor.finalize(accum); + // output_accessor_ptr[globalid]= accum; + // } + // }); }); dev.sycl_queue().throw_asynchronous(); return false; -- cgit v1.2.3