Merged in codeplaysoftware/eigen (pull request PR-667)

[SYCL] :

Approved-by: Gael Guennebaud <g.gael@free.fr>
Approved-by: Rasmus Larsen <rmlarsen@google.com>
This commit is contained in:
Gael Guennebaud 2019-07-02 12:45:23 +00:00
commit ef8aca6a89
4 changed files with 21 additions and 33 deletions

View File

@ -16,6 +16,7 @@
#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H
#include <unordered_set> #include <unordered_set>
namespace Eigen { namespace Eigen {
namespace TensorSycl { namespace TensorSycl {
@ -676,21 +677,12 @@ class QueueInterface {
} }
} }
bool sycl_async_handler(cl::sycl::exception_list l) const { bool sycl_async_handler(cl::sycl::exception_list exceptions) const {
bool exception_caught = false; bool exception_caught = false;
for (const auto &e : l) { for (const auto &e : exceptions) {
if (e) { if (e) {
exception_caught = true; exception_caught = true;
#ifdef EIGEN_EXCEPTIONS EIGEN_THROW_X(e);
try {
std::rethrow_exception(e);
} catch (const cl::sycl::exception &e) {
std::cerr << e.what() << std::endl;
}
#else
std::cerr << "Error detected inside Sycl device." << std::endl;
abort();
#endif
} }
} }
return exception_caught; return exception_caught;

View File

@ -67,20 +67,16 @@
#endif #endif
// Define a macro for catching SYCL exceptions if exceptions are enabled // Define a macro for catching SYCL exceptions if exceptions are enabled
#if defined(EIGEN_EXCEPTIONS) #define EIGEN_SYCL_TRY_CATCH(X) \
#define EIGEN_SYCL_TRY_CATCH(X) \
do { \ do { \
try { X; } \ EIGEN_TRY {X;} \
catch(const cl::sycl::exception& e) { \ EIGEN_CATCH(const cl::sycl::exception& e) { \
std::cerr << "SYCL exception at " \ EIGEN_THROW_X(std::runtime_error("SYCL exception at " + \
<< __FILE__ << ":" << __LINE__ << std::endl \ std::string(__FILE__) + ":" + \
<< e.what() << std::endl; \ std::to_string(__LINE__) + "\n" + \
std::rethrow_exception(std::current_exception()); \ e.what())); \
} \ } \
} while (false) } while (false)
#else
#define EIGEN_SYCL_TRY_CATCH(X) X
#endif
// Define a macro if local memory flags are unset or one of them is set // Define a macro if local memory flags are unset or one of them is set
// Setting both flags is the same as unsetting them // Setting both flags is the same as unsetting them

View File

@ -380,7 +380,7 @@ struct TensorEvaluator<const TensorReverseOp<ReverseDimensions, ArgType>, Device
array<IndexDivisor, NumDims> m_fastStrides; array<IndexDivisor, NumDims> m_fastStrides;
TensorEvaluator<ArgType, Device> m_impl; TensorEvaluator<ArgType, Device> m_impl;
ReverseDimensions m_reverse; ReverseDimensions m_reverse;
const Device& m_device; const Device EIGEN_DEVICE_REF m_device;
}; };
// Eval as lvalue // Eval as lvalue

View File

@ -193,7 +193,7 @@ struct lgamma_impl<float> {
#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__) #if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__)
int dummy; int dummy;
return ::lgammaf_r(x, &dummy); return ::lgammaf_r(x, &dummy);
#elif defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #elif defined(SYCL_DEVICE_ONLY)
return cl::sycl::lgamma(x); return cl::sycl::lgamma(x);
#else #else
return ::lgammaf(x); return ::lgammaf(x);
@ -208,7 +208,7 @@ struct lgamma_impl<double> {
#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__) #if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__)
int dummy; int dummy;
return ::lgamma_r(x, &dummy); return ::lgamma_r(x, &dummy);
#elif defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #elif defined(SYCL_DEVICE_ONLY)
return cl::sycl::lgamma(x); return cl::sycl::lgamma(x);
#else #else
return ::lgamma(x); return ::lgamma(x);
@ -428,7 +428,7 @@ template <>
struct erf_impl<float> { struct erf_impl<float> {
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE float run(float x) { static EIGEN_STRONG_INLINE float run(float x) {
#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #if defined(SYCL_DEVICE_ONLY)
return cl::sycl::erf(x); return cl::sycl::erf(x);
#else #else
return ::erff(x); return ::erff(x);
@ -440,7 +440,7 @@ template <>
struct erf_impl<double> { struct erf_impl<double> {
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(double x) { static EIGEN_STRONG_INLINE double run(double x) {
#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #if defined(SYCL_DEVICE_ONLY)
return cl::sycl::erf(x); return cl::sycl::erf(x);
#else #else
return ::erf(x); return ::erf(x);
@ -473,7 +473,7 @@ template <>
struct erfc_impl<float> { struct erfc_impl<float> {
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE float run(const float x) { static EIGEN_STRONG_INLINE float run(const float x) {
#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #if defined(SYCL_DEVICE_ONLY)
return cl::sycl::erfc(x); return cl::sycl::erfc(x);
#else #else
return ::erfcf(x); return ::erfcf(x);
@ -485,7 +485,7 @@ template <>
struct erfc_impl<double> { struct erfc_impl<double> {
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(const double x) { static EIGEN_STRONG_INLINE double run(const double x) {
#if defined(EIGEN_USE_SYCL) && defined(__SYCL_DEVICE_ONLY__) #if defined(SYCL_DEVICE_ONLY)
return cl::sycl::erfc(x); return cl::sycl::erfc(x);
#else #else
return ::erfc(x); return ::erfc(x);