diff options
author | Ivan Shapovalov <intelfx@intelfx.name> | 2016-10-22 05:14:19 +0300 |
---|---|---|
committer | Ivan Shapovalov <intelfx@intelfx.name> | 2016-10-22 08:45:25 +0300 |
commit | b98af44fcf89b9946e1de438b1f5527e6bf28905 (patch) | |
tree | fbd5ec2ab1e418830b88e5de42279845911ea0da /src/routines/level2/xtpmv.cpp | |
parent | 5d03d48f7aaf38d3b28bad612638d2d9db8ebee0 (diff) |
treewide: use C++ exceptions properly
Since the codebase is designed around proper C++ idioms such as RAII, it
makes sense to only use C++ exceptions internally instead of mixing
exceptions and error codes. The exceptions are now caught at top level
to preserve compatibility with the existing error code-based API.
Note that we deliberately do not catch C++ runtime errors (such as
`std::bad_alloc`) nor logic errors (aka failed assertions) because no
actual handling can ever happen for such errors.
However, in the C interface we do catch _all_ exceptions (...) and
convert them into a wild-card error code.
Diffstat (limited to 'src/routines/level2/xtpmv.cpp')
-rw-r--r-- | src/routines/level2/xtpmv.cpp | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/routines/level2/xtpmv.cpp b/src/routines/level2/xtpmv.cpp index 46811089..c0d26699 100644 --- a/src/routines/level2/xtpmv.cpp +++ b/src/routines/level2/xtpmv.cpp @@ -29,17 +29,15 @@ Xtpmv<T>::Xtpmv(Queue &queue, EventPointer event, const std::string &name): // The main routine template <typename T> -StatusCode Xtpmv<T>::DoTpmv(const Layout layout, const Triangle triangle, - const Transpose a_transpose, const Diagonal diagonal, - const size_t n, - const Buffer<T> &ap_buffer, const size_t ap_offset, - const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc) { +void Xtpmv<T>::DoTpmv(const Layout layout, const Triangle triangle, + const Transpose a_transpose, const Diagonal diagonal, + const size_t n, + const Buffer<T> &ap_buffer, const size_t ap_offset, + const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc) { // Creates a copy of X: a temporary scratch buffer auto scratch_buffer = Buffer<T>(context_, n*x_inc + x_offset); - try { - x_buffer.CopyTo(queue_, n*x_inc + x_offset, scratch_buffer); - } catch (...) { } // Continues: error-code is returned in MatVec + x_buffer.CopyTo(queue_, n*x_inc + x_offset, scratch_buffer); // The data is either in the upper or lower triangle size_t is_upper = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) || @@ -52,20 +50,22 @@ StatusCode Xtpmv<T>::DoTpmv(const Layout layout, const Triangle triangle, // The specific triangular packed matrix-accesses are implemented in the kernel guarded by the // ROUTINE_TPMV define. auto fast_kernels = false; - auto status = MatVec(layout, a_transpose, - n, n, static_cast<T>(1), - ap_buffer, ap_offset, n, - scratch_buffer, x_offset, x_inc, static_cast<T>(0), - x_buffer, x_offset, x_inc, - fast_kernels, fast_kernels, - parameter, true, 0, 0); - - // Returns the proper error code (renames vector Y to X) - switch(status) { - case StatusCode::kInvalidVectorY: return StatusCode::kInvalidVectorX; - case StatusCode::kInvalidIncrementY: return StatusCode::kInvalidIncrementX; - case StatusCode::kInsufficientMemoryY: return StatusCode::kInsufficientMemoryX; - default: return status; + try { + MatVec(layout, a_transpose, + n, n, static_cast<T>(1), + ap_buffer, ap_offset, n, + scratch_buffer, x_offset, x_inc, static_cast<T>(0), + x_buffer, x_offset, x_inc, + fast_kernels, fast_kernels, + parameter, true, 0, 0); + } catch (BLASError &e) { + // Returns the proper error code (renames vector Y to X) + switch (e.status()) { + case StatusCode::kInvalidVectorY: throw BLASError(StatusCode::kInvalidVectorX, e.details()); + case StatusCode::kInvalidIncrementY: throw BLASError(StatusCode::kInvalidIncrementX, e.details()); + case StatusCode::kInsufficientMemoryY: throw BLASError(StatusCode::kInsufficientMemoryX, e.details()); + default: throw; + } } } |