From e2a6c6d9910fce48c82f24e2b6645a6696c3ede7 Mon Sep 17 00:00:00 2001 From: Anton <100830759+antonwolfy@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:07:21 +0200 Subject: [PATCH] Replace sycl::free with `sycl_free_noexcept` (#2058) (#2060) * Replace sycl::free with sycl_free_noexcept * Update changelog --- CHANGELOG.md | 1 + .../elementwise_functions.hpp | 10 +++++++--- .../extensions/lapack/common_helpers.hpp | 7 +++++-- dpnp/backend/extensions/lapack/geqrf.cpp | 7 +++++-- dpnp/backend/extensions/lapack/geqrf_batch.cpp | 7 +++++-- dpnp/backend/extensions/lapack/gesv.cpp | 12 +++++++----- dpnp/backend/extensions/lapack/gesv_batch.cpp | 18 ++++++++++-------- .../extensions/lapack/gesv_common_utils.hpp | 7 +++++-- dpnp/backend/extensions/lapack/gesvd.cpp | 6 ++++-- dpnp/backend/extensions/lapack/gesvd_batch.cpp | 6 ++++-- dpnp/backend/extensions/lapack/getrf.cpp | 7 +++++-- dpnp/backend/extensions/lapack/getrf_batch.cpp | 7 +++++-- dpnp/backend/extensions/lapack/getri_batch.cpp | 7 +++++-- dpnp/backend/extensions/lapack/getrs.cpp | 10 +++++++--- dpnp/backend/extensions/lapack/heevd.cpp | 6 ++++-- dpnp/backend/extensions/lapack/heevd_batch.cpp | 6 ++++-- dpnp/backend/extensions/lapack/orgqr.cpp | 7 +++++-- dpnp/backend/extensions/lapack/orgqr_batch.cpp | 7 +++++-- dpnp/backend/extensions/lapack/potrf.cpp | 9 ++++++--- dpnp/backend/extensions/lapack/potrf_batch.cpp | 9 ++++++--- dpnp/backend/extensions/lapack/syevd.cpp | 6 ++++-- dpnp/backend/extensions/lapack/syevd_batch.cpp | 6 ++++-- dpnp/backend/extensions/lapack/ungqr.cpp | 7 +++++-- dpnp/backend/extensions/lapack/ungqr_batch.cpp | 7 +++++-- 24 files changed, 123 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 577692da3d4..4343f59df32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ In addition, this release completes implementation of `dpnp.fft` module and adds * Updated `Array Manipulation Routines` page in documentation to add missing functions and to remove duplicate entries [#2033](https://github.com/IntelPython/dpnp/pull/2033) * `dpnp` uses pybind11 2.13.6 [#2041](https://github.com/IntelPython/dpnp/pull/2041) * Updated `dpnp.fft` backend to depend on `INTEL_MKL_VERSION` flag to ensures that the appropriate code segment is executed based on the version of OneMKL [#2035](https://github.com/IntelPython/dpnp/pull/2035) +* Use `dpctl::tensor::alloc_utils::sycl_free_noexcept` instead of `sycl::free` in `host_task` tasks associated with life-time management of temporary USM allocations [#2058](https://github.com/IntelPython/dpnp/pull/2058) ### Fixed diff --git a/dpnp/backend/extensions/elementwise_functions/elementwise_functions.hpp b/dpnp/backend/extensions/elementwise_functions/elementwise_functions.hpp index 3a62b8aff2e..cfebca7381b 100644 --- a/dpnp/backend/extensions/elementwise_functions/elementwise_functions.hpp +++ b/dpnp/backend/extensions/elementwise_functions/elementwise_functions.hpp @@ -41,6 +41,7 @@ #include "utils/memory_overlap.hpp" #include "utils/offset_utils.hpp" #include "utils/output_validation.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_dispatch.hpp" namespace py = pybind11; @@ -232,8 +233,9 @@ std::pair auto ctx = q.get_context(); sycl::event tmp_cleanup_ev = q.submit([&](sycl::handler &cgh) { cgh.depends_on(strided_fn_ev); + using dpctl::tensor::alloc_utils::sycl_free_noexcept; cgh.host_task( - [ctx, shape_strides]() { sycl::free(shape_strides, ctx); }); + [ctx, shape_strides]() { sycl_free_noexcept(shape_strides, ctx); }); }); host_tasks.push_back(tmp_cleanup_ev); @@ -558,8 +560,9 @@ std::pair py_binary_ufunc( sycl::event tmp_cleanup_ev = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(strided_fn_ev); + using dpctl::tensor::alloc_utils::sycl_free_noexcept; cgh.host_task( - [ctx, shape_strides]() { sycl::free(shape_strides, ctx); }); + [ctx, shape_strides]() { sycl_free_noexcept(shape_strides, ctx); }); }); host_tasks.push_back(tmp_cleanup_ev); @@ -810,8 +813,9 @@ std::pair sycl::event tmp_cleanup_ev = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(strided_fn_ev); + using dpctl::tensor::alloc_utils::sycl_free_noexcept; cgh.host_task( - [ctx, shape_strides]() { sycl::free(shape_strides, ctx); }); + [ctx, shape_strides]() { sycl_free_noexcept(shape_strides, ctx); }); }); host_tasks.push_back(tmp_cleanup_ev); diff --git a/dpnp/backend/extensions/lapack/common_helpers.hpp b/dpnp/backend/extensions/lapack/common_helpers.hpp index 88e791256dc..d8a09a77181 100644 --- a/dpnp/backend/extensions/lapack/common_helpers.hpp +++ b/dpnp/backend/extensions/lapack/common_helpers.hpp @@ -31,6 +31,9 @@ #include #include +// dpctl tensor headers +#include "utils/sycl_alloc_utils.hpp" + namespace dpnp::extensions::lapack::helper { namespace py = pybind11; @@ -78,7 +81,7 @@ inline std::int64_t *alloc_ipiv(const std::int64_t n, sycl::queue &exec_q) } } catch (sycl::exception const &e) { if (ipiv != nullptr) - sycl::free(ipiv, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(ipiv, exec_q); throw std::runtime_error( std::string( "Unexpected SYCL exception caught during ipiv allocation: ") + @@ -122,7 +125,7 @@ inline T *alloc_scratchpad(std::int64_t scratchpad_size, sycl::queue &exec_q) } } catch (sycl::exception const &e) { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(std::string("Unexpected SYCL exception caught " "during scratchpad allocation: ") + diff --git a/dpnp/backend/extensions/lapack/geqrf.cpp b/dpnp/backend/extensions/lapack/geqrf.cpp index b523140832a..fbc47157f1f 100644 --- a/dpnp/backend/extensions/lapack/geqrf.cpp +++ b/dpnp/backend/extensions/lapack/geqrf.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "geqrf.hpp" @@ -117,7 +118,7 @@ static sycl::event geqrf_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -125,7 +126,9 @@ static sycl::event geqrf_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(geqrf_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); diff --git a/dpnp/backend/extensions/lapack/geqrf_batch.cpp b/dpnp/backend/extensions/lapack/geqrf_batch.cpp index 2bcdc795e09..22766c57581 100644 --- a/dpnp/backend/extensions/lapack/geqrf_batch.cpp +++ b/dpnp/backend/extensions/lapack/geqrf_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "geqrf.hpp" @@ -138,7 +139,7 @@ static sycl::event geqrf_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -147,7 +148,9 @@ static sycl::event geqrf_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(geqrf_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return geqrf_batch_event; diff --git a/dpnp/backend/extensions/lapack/gesv.cpp b/dpnp/backend/extensions/lapack/gesv.cpp index 5472319e023..545a9cbb2bf 100644 --- a/dpnp/backend/extensions/lapack/gesv.cpp +++ b/dpnp/backend/extensions/lapack/gesv.cpp @@ -39,6 +39,8 @@ namespace mkl_lapack = oneapi::mkl::lapack; namespace py = pybind11; namespace type_utils = dpctl::tensor::type_utils; +using dpctl::tensor::alloc_utils::sycl_free_noexcept; + typedef sycl::event (*gesv_impl_fn_ptr_t)(sycl::queue &, const std::int64_t, const std::int64_t, @@ -93,7 +95,7 @@ static sycl::event gesv_impl(sycl::queue &exec_q, ipiv = helper::alloc_ipiv(n, exec_q); } catch (const std::exception &e) { if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); throw; } @@ -178,9 +180,9 @@ static sycl::event gesv_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); if (ipiv != nullptr) - sycl::free(ipiv, exec_q); + sycl_free_noexcept(ipiv, exec_q); throw std::runtime_error(error_msg.str()); } @@ -188,8 +190,8 @@ static sycl::event gesv_impl(sycl::queue &exec_q, cgh.depends_on(comp_event); auto ctx = exec_q.get_context(); cgh.host_task([ctx, scratchpad, ipiv]() { - sycl::free(scratchpad, ctx); - sycl::free(ipiv, ctx); + sycl_free_noexcept(scratchpad, ctx); + sycl_free_noexcept(ipiv, ctx); }); }); diff --git a/dpnp/backend/extensions/lapack/gesv_batch.cpp b/dpnp/backend/extensions/lapack/gesv_batch.cpp index f6c073f2cc0..d5b4a880519 100644 --- a/dpnp/backend/extensions/lapack/gesv_batch.cpp +++ b/dpnp/backend/extensions/lapack/gesv_batch.cpp @@ -39,6 +39,8 @@ namespace mkl_lapack = oneapi::mkl::lapack; namespace py = pybind11; namespace type_utils = dpctl::tensor::type_utils; +using dpctl::tensor::alloc_utils::sycl_free_noexcept; + typedef sycl::event (*gesv_batch_impl_fn_ptr_t)( sycl::queue &, const std::int64_t, @@ -106,7 +108,7 @@ static sycl::event gesv_batch_impl(sycl::queue &exec_q, ipiv = helper::alloc_ipiv(batch_size * n, exec_q); } catch (const std::exception &e) { if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); throw; } @@ -172,9 +174,9 @@ static sycl::event gesv_batch_impl(sycl::queue &exec_q, error_msg << "."; if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); if (ipiv != nullptr) - sycl::free(ipiv, exec_q); + sycl_free_noexcept(ipiv, exec_q); throw LinAlgError(error_msg.str().c_str()); } catch (mkl_lapack::exception const &e) { @@ -218,7 +220,7 @@ static sycl::event gesv_batch_impl(sycl::queue &exec_q, ipiv = helper::alloc_ipiv_batch(n, n_linear_streams, exec_q); } catch (const std::exception &e) { if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); throw; } @@ -281,9 +283,9 @@ static sycl::event gesv_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); if (ipiv != nullptr) - sycl::free(ipiv, exec_q); + sycl_free_noexcept(ipiv, exec_q); throw std::runtime_error(error_msg.str()); } @@ -297,8 +299,8 @@ static sycl::event gesv_batch_impl(sycl::queue &exec_q, #endif // USE_ONEMKL_INTERFACES auto ctx = exec_q.get_context(); cgh.host_task([ctx, scratchpad, ipiv]() { - sycl::free(scratchpad, ctx); - sycl::free(ipiv, ctx); + sycl_free_noexcept(scratchpad, ctx); + sycl_free_noexcept(ipiv, ctx); }); }); diff --git a/dpnp/backend/extensions/lapack/gesv_common_utils.hpp b/dpnp/backend/extensions/lapack/gesv_common_utils.hpp index b8020abec13..b0dd7d911e7 100644 --- a/dpnp/backend/extensions/lapack/gesv_common_utils.hpp +++ b/dpnp/backend/extensions/lapack/gesv_common_utils.hpp @@ -30,6 +30,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" #include "utils/output_validation.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_dispatch.hpp" #include "common_helpers.hpp" @@ -159,10 +160,12 @@ inline void handle_lapack_exc(sycl::queue &exec_q, const auto threshold = std::numeric_limits::epsilon() * 100; if (std::abs(host_U) < threshold) { + using dpctl::tensor::alloc_utils::sycl_free_noexcept; + if (scratchpad != nullptr) - sycl::free(scratchpad, exec_q); + sycl_free_noexcept(scratchpad, exec_q); if (ipiv != nullptr) - sycl::free(ipiv, exec_q); + sycl_free_noexcept(ipiv, exec_q); throw LinAlgError("The input coefficient matrix is singular."); } else { diff --git a/dpnp/backend/extensions/lapack/gesvd.cpp b/dpnp/backend/extensions/lapack/gesvd.cpp index 833e55e98a8..94ad5ccf182 100644 --- a/dpnp/backend/extensions/lapack/gesvd.cpp +++ b/dpnp/backend/extensions/lapack/gesvd.cpp @@ -125,7 +125,7 @@ static sycl::event gesvd_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -133,7 +133,9 @@ static sycl::event gesvd_impl(sycl::queue &exec_q, sycl::event ht_ev = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(gesvd_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/gesvd_batch.cpp b/dpnp/backend/extensions/lapack/gesvd_batch.cpp index a8c6077467c..1a9f967526c 100644 --- a/dpnp/backend/extensions/lapack/gesvd_batch.cpp +++ b/dpnp/backend/extensions/lapack/gesvd_batch.cpp @@ -189,7 +189,7 @@ static sycl::event gesvd_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -199,7 +199,9 @@ static sycl::event gesvd_batch_impl(sycl::queue &exec_q, cgh.depends_on(ev); } auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/getrf.cpp b/dpnp/backend/extensions/lapack/getrf.cpp index 67e8c8ec318..150b256620d 100644 --- a/dpnp/backend/extensions/lapack/getrf.cpp +++ b/dpnp/backend/extensions/lapack/getrf.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "getrf.hpp" @@ -126,7 +127,7 @@ static sycl::event getrf_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -135,7 +136,9 @@ static sycl::event getrf_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(getrf_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return getrf_event; diff --git a/dpnp/backend/extensions/lapack/getrf_batch.cpp b/dpnp/backend/extensions/lapack/getrf_batch.cpp index bdc6cd48c5c..a3d5cba4929 100644 --- a/dpnp/backend/extensions/lapack/getrf_batch.cpp +++ b/dpnp/backend/extensions/lapack/getrf_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "getrf.hpp" @@ -152,7 +153,7 @@ static sycl::event getrf_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -161,7 +162,9 @@ static sycl::event getrf_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(getrf_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return getrf_batch_event; diff --git a/dpnp/backend/extensions/lapack/getri_batch.cpp b/dpnp/backend/extensions/lapack/getri_batch.cpp index 3fe04b4097a..b931a145d7b 100644 --- a/dpnp/backend/extensions/lapack/getri_batch.cpp +++ b/dpnp/backend/extensions/lapack/getri_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "getri.hpp" @@ -150,7 +151,7 @@ static sycl::event getri_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -159,7 +160,9 @@ static sycl::event getri_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(getri_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return getri_batch_event; diff --git a/dpnp/backend/extensions/lapack/getrs.cpp b/dpnp/backend/extensions/lapack/getrs.cpp index a60cccf1ece..2f6f3fd17f2 100644 --- a/dpnp/backend/extensions/lapack/getrs.cpp +++ b/dpnp/backend/extensions/lapack/getrs.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "getrs.hpp" @@ -122,7 +123,8 @@ static sycl::event getrs_impl(sycl::queue &exec_q, else if (info > 0) { is_exception_caught = false; if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, + exec_q); } throw LinAlgError("The solve could not be completed."); } @@ -140,7 +142,7 @@ static sycl::event getrs_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -149,7 +151,9 @@ static sycl::event getrs_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(getrs_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return getrs_event; diff --git a/dpnp/backend/extensions/lapack/heevd.cpp b/dpnp/backend/extensions/lapack/heevd.cpp index bf9ad300c8f..cd6a118a22e 100644 --- a/dpnp/backend/extensions/lapack/heevd.cpp +++ b/dpnp/backend/extensions/lapack/heevd.cpp @@ -93,7 +93,7 @@ static sycl::event heevd_impl(sycl::queue &exec_q, if (info != 0) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -101,7 +101,9 @@ static sycl::event heevd_impl(sycl::queue &exec_q, sycl::event ht_ev = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(heevd_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/heevd_batch.cpp b/dpnp/backend/extensions/lapack/heevd_batch.cpp index 1015a6d865e..6d86dc62ca1 100644 --- a/dpnp/backend/extensions/lapack/heevd_batch.cpp +++ b/dpnp/backend/extensions/lapack/heevd_batch.cpp @@ -128,7 +128,7 @@ static sycl::event heevd_batch_impl(sycl::queue &exec_q, if (info != 0) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -138,7 +138,9 @@ static sycl::event heevd_batch_impl(sycl::queue &exec_q, cgh.depends_on(ev); } auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/orgqr.cpp b/dpnp/backend/extensions/lapack/orgqr.cpp index a77a71b167f..45515e7391e 100644 --- a/dpnp/backend/extensions/lapack/orgqr.cpp +++ b/dpnp/backend/extensions/lapack/orgqr.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "orgqr.hpp" @@ -121,7 +122,7 @@ static sycl::event orgqr_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -129,7 +130,9 @@ static sycl::event orgqr_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(orgqr_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); diff --git a/dpnp/backend/extensions/lapack/orgqr_batch.cpp b/dpnp/backend/extensions/lapack/orgqr_batch.cpp index 5f60845a69b..631adefb169 100644 --- a/dpnp/backend/extensions/lapack/orgqr_batch.cpp +++ b/dpnp/backend/extensions/lapack/orgqr_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "orgqr.hpp" @@ -142,7 +143,7 @@ static sycl::event orgqr_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -151,7 +152,9 @@ static sycl::event orgqr_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(orgqr_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return orgqr_batch_event; diff --git a/dpnp/backend/extensions/lapack/potrf.cpp b/dpnp/backend/extensions/lapack/potrf.cpp index 2815f015692..46ff77193cc 100644 --- a/dpnp/backend/extensions/lapack/potrf.cpp +++ b/dpnp/backend/extensions/lapack/potrf.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "linalg_exceptions.hpp" @@ -101,7 +102,7 @@ static sycl::event potrf_impl(sycl::queue &exec_q, << e.detail(); } else if (info > 0 && e.detail() == 0) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); throw LinAlgError("Matrix is not positive definite."); } else { @@ -118,7 +119,7 @@ static sycl::event potrf_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -126,7 +127,9 @@ static sycl::event potrf_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(potrf_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return potrf_event; diff --git a/dpnp/backend/extensions/lapack/potrf_batch.cpp b/dpnp/backend/extensions/lapack/potrf_batch.cpp index b4a19150305..7f1d4c428c7 100644 --- a/dpnp/backend/extensions/lapack/potrf_batch.cpp +++ b/dpnp/backend/extensions/lapack/potrf_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "linalg_exceptions.hpp" @@ -113,7 +114,7 @@ static sycl::event potrf_batch_impl(sycl::queue &exec_q, } error_msg << "."; - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); throw LinAlgError(error_msg.str().c_str()); } catch (mkl_lapack::exception const &e) { is_exception_caught = true; @@ -148,7 +149,7 @@ static sycl::event potrf_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -156,7 +157,9 @@ static sycl::event potrf_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(potrf_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return potrf_batch_event; diff --git a/dpnp/backend/extensions/lapack/syevd.cpp b/dpnp/backend/extensions/lapack/syevd.cpp index 9ffc1e0ce9f..4877a43ebf6 100644 --- a/dpnp/backend/extensions/lapack/syevd.cpp +++ b/dpnp/backend/extensions/lapack/syevd.cpp @@ -93,7 +93,7 @@ static sycl::event syevd_impl(sycl::queue &exec_q, if (info != 0) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -101,7 +101,9 @@ static sycl::event syevd_impl(sycl::queue &exec_q, sycl::event ht_ev = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(syevd_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/syevd_batch.cpp b/dpnp/backend/extensions/lapack/syevd_batch.cpp index 019f550affe..683519748ee 100644 --- a/dpnp/backend/extensions/lapack/syevd_batch.cpp +++ b/dpnp/backend/extensions/lapack/syevd_batch.cpp @@ -128,7 +128,7 @@ static sycl::event syevd_batch_impl(sycl::queue &exec_q, if (info != 0) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -138,7 +138,9 @@ static sycl::event syevd_batch_impl(sycl::queue &exec_q, cgh.depends_on(ev); } auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); return ht_ev; diff --git a/dpnp/backend/extensions/lapack/ungqr.cpp b/dpnp/backend/extensions/lapack/ungqr.cpp index a82e09e599e..3f543c4f91d 100644 --- a/dpnp/backend/extensions/lapack/ungqr.cpp +++ b/dpnp/backend/extensions/lapack/ungqr.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "types_matrix.hpp" @@ -121,7 +122,7 @@ static sycl::event ungqr_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); } @@ -129,7 +130,9 @@ static sycl::event ungqr_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(ungqr_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); diff --git a/dpnp/backend/extensions/lapack/ungqr_batch.cpp b/dpnp/backend/extensions/lapack/ungqr_batch.cpp index 3e9329adf36..44e54367a5c 100644 --- a/dpnp/backend/extensions/lapack/ungqr_batch.cpp +++ b/dpnp/backend/extensions/lapack/ungqr_batch.cpp @@ -27,6 +27,7 @@ // dpctl tensor headers #include "utils/memory_overlap.hpp" +#include "utils/sycl_alloc_utils.hpp" #include "utils/type_utils.hpp" #include "types_matrix.hpp" @@ -142,7 +143,7 @@ static sycl::event ungqr_batch_impl(sycl::queue &exec_q, if (is_exception_caught) // an unexpected error occurs { if (scratchpad != nullptr) { - sycl::free(scratchpad, exec_q); + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, exec_q); } throw std::runtime_error(error_msg.str()); @@ -151,7 +152,9 @@ static sycl::event ungqr_batch_impl(sycl::queue &exec_q, sycl::event clean_up_event = exec_q.submit([&](sycl::handler &cgh) { cgh.depends_on(ungqr_batch_event); auto ctx = exec_q.get_context(); - cgh.host_task([ctx, scratchpad]() { sycl::free(scratchpad, ctx); }); + cgh.host_task([ctx, scratchpad]() { + dpctl::tensor::alloc_utils::sycl_free_noexcept(scratchpad, ctx); + }); }); host_task_events.push_back(clean_up_event); return ungqr_batch_event;