|
| 1 | +// SPDX-FileCopyrightText: 2023 Intel Corporation |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +#include "nrt_reserve_meminfo.h" |
| 6 | + |
| 7 | +#include "_dbg_printer.h" |
| 8 | +#include "syclinterface/dpctl_sycl_type_casters.hpp" |
| 9 | +#include <CL/sycl.hpp> |
| 10 | + |
| 11 | +extern "C" |
| 12 | +{ |
| 13 | + DPCTLSyclEventRef |
| 14 | + DPEXRT_nrt_acquire_meminfo_and_schedule_release(NRT_api_functions *nrt, |
| 15 | + DPCTLSyclQueueRef QRef, |
| 16 | + NRT_MemInfo **meminfo_array, |
| 17 | + size_t meminfo_array_size, |
| 18 | + DPCTLSyclEventRef *depERefs, |
| 19 | + size_t nDepERefs, |
| 20 | + int *status) |
| 21 | + { |
| 22 | + DPEXRT_DEBUG(drt_debug_print( |
| 23 | + "DPEXRT-DEBUG: scheduling nrt meminfo release.\n");); |
| 24 | + |
| 25 | + using dpctl::syclinterface::unwrap; |
| 26 | + using dpctl::syclinterface::wrap; |
| 27 | + |
| 28 | + sycl::queue *q = unwrap<sycl::queue>(QRef); |
| 29 | + |
| 30 | + std::vector<NRT_MemInfo *> meminfo_vec( |
| 31 | + meminfo_array, meminfo_array + meminfo_array_size); |
| 32 | + |
| 33 | + for (size_t i = 0; i < meminfo_array_size; ++i) { |
| 34 | + nrt->acquire(meminfo_vec[i]); |
| 35 | + } |
| 36 | + |
| 37 | + DPEXRT_DEBUG(drt_debug_print("DPEXRT-DEBUG: acquired meminfo.\n");); |
| 38 | + |
| 39 | + try { |
| 40 | + sycl::event ht_ev = q->submit([&](sycl::handler &cgh) { |
| 41 | + for (size_t ev_id = 0; ev_id < nDepERefs; ++ev_id) { |
| 42 | + cgh.depends_on(*(unwrap<sycl::event>(depERefs[ev_id]))); |
| 43 | + } |
| 44 | + cgh.host_task([meminfo_array_size, meminfo_vec, nrt]() { |
| 45 | + for (size_t i = 0; i < meminfo_array_size; ++i) { |
| 46 | + nrt->release(meminfo_vec[i]); |
| 47 | + DPEXRT_DEBUG( |
| 48 | + drt_debug_print("DPEXRT-DEBUG: released meminfo " |
| 49 | + "from host_task.\n");); |
| 50 | + } |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + constexpr int result_ok = 0; |
| 55 | + |
| 56 | + *status = result_ok; |
| 57 | + auto e_ptr = new sycl::event(ht_ev); |
| 58 | + return wrap<sycl::event>(e_ptr); |
| 59 | + } catch (const std::exception &e) { |
| 60 | + constexpr int result_std_exception = 1; |
| 61 | + |
| 62 | + *status = result_std_exception; |
| 63 | + return nullptr; |
| 64 | + } |
| 65 | + |
| 66 | + constexpr int result_other_abnormal = 2; |
| 67 | + |
| 68 | + *status = result_other_abnormal; |
| 69 | + return nullptr; |
| 70 | + } |
| 71 | +} |
0 commit comments