Added a way to detect errors generated by the opencl device from the host

This commit is contained in:
Benoit Steiner 2016-11-17 21:51:48 -08:00
parent 72a45d32e9
commit 553f50b246
2 changed files with 15 additions and 9 deletions

View File

@ -12,12 +12,15 @@
// Public License v. 2.0. If a copy of the MPL was not distributed // Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <iostream>
#if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H) #if defined(EIGEN_USE_SYCL) && !defined(EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H)
#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_SYCL_H
namespace Eigen { namespace Eigen {
struct SyclDevice { struct SyclDevice {
/// class members: /// class members:
bool exception_caught_ = false;
/// sycl queue /// sycl queue
mutable cl::sycl::queue m_queue; mutable cl::sycl::queue m_queue;
@ -34,6 +37,7 @@ struct SyclDevice {
for (const auto& e : l) { for (const auto& e : l) {
try { try {
if (e) { if (e) {
exception_caught_ = true;
std::rethrow_exception(e); std::rethrow_exception(e);
} }
} catch (const cl::sycl::exception& e) { } catch (const cl::sycl::exception& e) {
@ -231,6 +235,12 @@ struct SyclDevice {
EIGEN_STRONG_INLINE void synchronize() const { EIGEN_STRONG_INLINE void synchronize() const {
m_queue.wait_and_throw(); m_queue.wait_and_throw();
} }
// This function checks if the runtime recorded an error for the
// underlying stream device.
EIGEN_STRONG_INLINE bool ok() const {
return !exception_caught_;
}
}; };
} // end namespace Eigen } // end namespace Eigen

View File

@ -42,17 +42,13 @@ void test_device_memory(const Eigen::SyclDevice &sycl_device) {
void test_device_exceptions(const Eigen::SyclDevice &sycl_device) { void test_device_exceptions(const Eigen::SyclDevice &sycl_device) {
bool threw_exception = false; VERIFY(sycl_device.ok());
array<int, 1> tensorDims = {{100}}; array<int, 1> tensorDims = {{100}};
int* gpu_data = static_cast<int*>(sycl_device.allocate(100*sizeof(int))); int* gpu_data = static_cast<int*>(sycl_device.allocate(100*sizeof(int)));
TensorMap<Tensor<int, 1>> in(gpu_data, tensorDims); TensorMap<Tensor<int, 1>> in(gpu_data, tensorDims);
TensorMap<Tensor<int, 1>> out(gpu_data, tensorDims); TensorMap<Tensor<int, 1>> out(gpu_data, tensorDims);
try {
out.device(sycl_device) = in / in.constant(0); out.device(sycl_device) = in / in.constant(0);
} catch(...) { VERIFY(!sycl_device.ok());
threw_exception = true;
}
VERIFY(threw_exception);
sycl_device.deallocate(gpu_data); sycl_device.deallocate(gpu_data);
} }
@ -62,5 +58,5 @@ void test_cxx11_tensor_device_sycl() {
Eigen::SyclDevice sycl_device(s); Eigen::SyclDevice sycl_device(s);
CALL_SUBTEST(test_device_memory(sycl_device)); CALL_SUBTEST(test_device_memory(sycl_device));
// This deadlocks // This deadlocks
// CALL_SUBTEST(test_device_exceptions(sycl_device)); //CALL_SUBTEST(test_device_exceptions(sycl_device));
} }