Skip to content

Added submit_keep_args_alive #1395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ cdef extern from "syclinterface/dpctl_sycl_queue_interface.h":
void *Dest,
const void *Src,
size_t Count)
cdef DPCTLSyclEventRef DPCTLQueue_MemcpyWithEvents(
const DPCTLSyclQueueRef Q,
void *Dest,
const void *Src,
size_t Count,
const DPCTLSyclEventRef *depEvents,
size_t depEventsCount)
cdef DPCTLSyclEventRef DPCTLQueue_Memset(
const DPCTLSyclQueueRef Q,
void *Dest,
Expand Down
48 changes: 30 additions & 18 deletions dpctl/_host_task_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2022 Intel Corporation
// Copyright 2020-2023 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -29,30 +29,30 @@
///
//===----------------------------------------------------------------------===//

#pragma once
#include "Python.h"
#include "syclinterface/dpctl_data_types.h"
#include "syclinterface/dpctl_sycl_type_casters.hpp"
#include <CL/sycl.hpp>

int async_dec_ref(DPCTLSyclQueueRef QRef,
PyObject **obj_array,
size_t obj_array_size,
DPCTLSyclEventRef *ERefs,
size_t nERefs)
DPCTLSyclEventRef async_dec_ref(DPCTLSyclQueueRef QRef,
PyObject **obj_array,
size_t obj_array_size,
DPCTLSyclEventRef *depERefs,
size_t nDepERefs,
int *status)
{
using dpctl::syclinterface::unwrap;
using dpctl::syclinterface::wrap;

sycl::queue *q = reinterpret_cast<sycl::queue *>(QRef);
sycl::queue *q = unwrap<sycl::queue>(QRef);

std::vector<PyObject *> obj_vec;
obj_vec.reserve(obj_array_size);
for (size_t obj_id = 0; obj_id < obj_array_size; ++obj_id) {
obj_vec.push_back(obj_array[obj_id]);
}
std::vector<PyObject *> obj_vec(obj_array, obj_array + obj_array_size);

try {
q->submit([&](sycl::handler &cgh) {
for (size_t ev_id = 0; ev_id < nERefs; ++ev_id) {
cgh.depends_on(
*(reinterpret_cast<sycl::event *>(ERefs[ev_id])));
sycl::event ht_ev = q->submit([&](sycl::handler &cgh) {
for (size_t ev_id = 0; ev_id < nDepERefs; ++ev_id) {
cgh.depends_on(*(unwrap<sycl::event>(depERefs[ev_id])));
}
cgh.host_task([obj_array_size, obj_vec]() {
// if the main thread has not finilized the interpreter yet
Expand All @@ -66,9 +66,21 @@ int async_dec_ref(DPCTLSyclQueueRef QRef,
}
});
});

constexpr int result_ok = 0;

*status = result_ok;
auto e_ptr = new sycl::event(ht_ev);
return wrap<sycl::event>(e_ptr);
} catch (const std::exception &e) {
return 1;
constexpr int result_std_exception = 1;

*status = result_std_exception;
return nullptr;
}

return 0;
constexpr int result_other_abnormal = 2;

*status = result_other_abnormal;
return nullptr;
}
14 changes: 14 additions & 0 deletions dpctl/_sycl_queue.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ cdef public api class SyclQueue (_SyclQueue) [
cpdef SyclContext get_sycl_context(self)
cpdef SyclDevice get_sycl_device(self)
cdef DPCTLSyclQueueRef get_queue_ref(self)
cpdef SyclEvent _submit_keep_args_alive(
self,
object args,
list dEvents
)
cpdef SyclEvent submit_async(
self,
SyclKernel kernel,
list args,
list gS,
list lS=*,
list dEvents=*
)
cpdef SyclEvent submit(
self,
SyclKernel kernel,
Expand All @@ -81,6 +94,7 @@ cdef public api class SyclQueue (_SyclQueue) [
cpdef void wait(self)
cdef DPCTLSyclQueueRef get_queue_ref(self)
cpdef memcpy(self, dest, src, size_t count)
cpdef SyclEvent memcpy_async(self, dest, src, size_t count, list dEvents=*)
cpdef prefetch(self, ptr, size_t count=*)
cpdef mem_advise(self, ptr, size_t count, int mem)
cpdef SyclEvent submit_barrier(self, dependent_events=*)
Loading