2017-11-07 19:17:28 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//
|
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
|
|
|
// the U.S. Government retains certain rights in this software.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
|
|
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
|
|
|
// this software.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/ErrorBadAllocation.h>
|
|
|
|
#include <vtkm/cont/ErrorBadType.h>
|
|
|
|
#include <vtkm/cont/ErrorBadValue.h>
|
2018-04-03 18:34:16 +00:00
|
|
|
#include <vtkm/cont/ErrorFilterExecution.h>
|
2017-11-07 19:17:28 +00:00
|
|
|
#include <vtkm/cont/TryExecute.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
|
2018-07-25 14:33:55 +00:00
|
|
|
void HandleTryExecuteException(vtkm::cont::DeviceAdapterId deviceId,
|
2018-08-30 17:29:36 +00:00
|
|
|
vtkm::cont::RuntimeDeviceTracker& tracker,
|
|
|
|
const std::string& functorName)
|
2017-11-07 19:17:28 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
//re-throw the last exception
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch (vtkm::cont::ErrorBadAllocation& e)
|
|
|
|
{
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_DISABLE("Bad allocation (" << e.GetMessage() << ")", functorName, deviceId);
|
2017-11-07 19:17:28 +00:00
|
|
|
//currently we only consider OOM errors worth disabling a device for
|
|
|
|
//than we fallback to another device
|
2018-08-29 20:47:51 +00:00
|
|
|
tracker.ReportAllocationFailure(deviceId, e);
|
2017-11-07 19:17:28 +00:00
|
|
|
}
|
2017-12-22 15:01:09 +00:00
|
|
|
catch (vtkm::cont::ErrorBadDevice& e)
|
|
|
|
{
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_DISABLE("Bad device (" << e.GetMessage() << ")", functorName, deviceId);
|
2018-08-29 20:47:51 +00:00
|
|
|
tracker.ReportBadDeviceFailure(deviceId, e);
|
2017-12-22 15:01:09 +00:00
|
|
|
}
|
2017-11-07 19:17:28 +00:00
|
|
|
catch (vtkm::cont::ErrorBadType& e)
|
|
|
|
{
|
|
|
|
//should bad type errors should stop the execution, instead of
|
|
|
|
//deferring to another device adapter?
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_FAIL("ErrorBadType (" << e.GetMessage() << ")", functorName, deviceId);
|
2017-11-07 19:17:28 +00:00
|
|
|
}
|
2018-08-30 17:29:36 +00:00
|
|
|
catch (vtkm::cont::ErrorBadValue& e)
|
2017-11-07 19:17:28 +00:00
|
|
|
{
|
2018-08-28 20:36:50 +00:00
|
|
|
// Should bad values be deferred to another device? Seems unlikely they will succeed.
|
|
|
|
// Re-throw instead.
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_FAIL("ErrorBadValue (" << e.GetMessage() << ")", functorName, deviceId);
|
2018-08-28 20:36:50 +00:00
|
|
|
throw;
|
2017-11-07 19:17:28 +00:00
|
|
|
}
|
|
|
|
catch (vtkm::cont::Error& e)
|
|
|
|
{
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_FAIL(e.GetMessage(), functorName, deviceId);
|
2018-04-03 18:34:16 +00:00
|
|
|
if (e.GetIsDeviceIndependent())
|
|
|
|
{
|
|
|
|
// re-throw the exception as it's a device-independent exception.
|
|
|
|
throw;
|
|
|
|
}
|
2017-11-07 19:17:28 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_FAIL(e.what(), functorName, deviceId);
|
2017-11-07 19:17:28 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2018-08-30 17:29:36 +00:00
|
|
|
VTKM_LOG_TRYEXECUTE_FAIL("Unknown exception", functorName, deviceId);
|
2017-11-07 19:17:28 +00:00
|
|
|
std::cerr << "unknown exception caught" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|