Skip to content

Commit

Permalink
Add new property for manual_interop_sync
Browse files Browse the repository at this point in the history
Add a new property for manual interop sync and make a host_task, HostTask specialization
taking a property list.
  • Loading branch information
hdelan committed Feb 23, 2024
1 parent 7def376 commit d50f23b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
10 changes: 10 additions & 0 deletions sycl/include/sycl/detail/cg_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sycl/detail/kernel_desc.hpp> // for kernel_param_kind_t
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_WORK...
#include <sycl/exception.hpp> // for nd_range_error
#include <sycl/ext/codeplay/experimental/host_task_properties.hpp> // for property::host_task::manual_interop_sync
#include <sycl/group.hpp> // for group
#include <sycl/h_item.hpp> // for h_item
#include <sycl/id.hpp> // for id
Expand Down Expand Up @@ -233,14 +234,23 @@ class HostKernelBase {
class HostTask {
std::function<void()> MHostTask;
std::function<void(interop_handle)> MInteropTask;
bool ManualInteropSync = false;

public:
HostTask() : MHostTask([]() {}) {}
HostTask(std::function<void()> &&Func) : MHostTask(Func) {}
HostTask(std::function<void(interop_handle)> &&Func) : MInteropTask(Func) {}
HostTask(std::function<void(interop_handle)> &&Func,
const property_list PropList)
: MInteropTask(Func),
ManualInteropSync{
PropList.has_property<ext::codeplay::experimental::property::
host_task::manual_interop_sync>()} {}

bool isInteropTask() const { return !!MInteropTask; }

bool isManualInteropSync() const { return ManualInteropSync; }

void call(HostProfilingInfo *HPI) {
if (HPI)
HPI->start();
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/sycl/detail/property_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ enum DataLessPropKind {
GraphAssumeDataOutlivesBuffer = 22,
GraphAssumeBufferOutlivesGraph = 23,
GraphDependOnAllLeaves = 24,
HostTaskManualInteropSync = 25,
// Indicates the last known dataless property.
LastKnownDataLessPropKind = 24,
LastKnownDataLessPropKind = 25,
// Exceeding 32 may cause ABI breaking change on some of OSes.
DataLessPropKindSize = 32
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//==-------- host_task_properties.hpp --- SYCL host task properties --------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sycl/context.hpp>
#include <sycl/detail/property_helper.hpp>
#include <sycl/properties/property_traits.hpp>

namespace sycl {
inline namespace _V1 {
namespace ext::codeplay::experimental::property::host_task {

class manual_interop_sync : public ::sycl::detail::DataLessProperty<
::sycl::detail::HostTaskManualInteropSync> {};

} // namespace ext::codeplay::experimental::property::host_task

// Forward declaration
class host_task;

template <>
struct is_property<
ext::codeplay::experimental::property::host_task::manual_interop_sync>
: std::true_type {};

template <>
struct is_property_of<
ext::codeplay::experimental::property::host_task::manual_interop_sync,
host_task> : std::true_type {};

} // namespace _V1
} // namespace sycl
13 changes: 9 additions & 4 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,13 +1765,18 @@ class __SYCL_EXPORT handler {
void()>::value ||
detail::check_fn_signature<std::remove_reference_t<FuncT>,
void(interop_handle)>::value>
host_task_impl(FuncT &&Func) {
host_task_impl(FuncT &&Func, const property_list PropList = {}) {
throwIfActionIsCreated();

MNDRDesc.set(range<1>(1));
MArgs = std::move(MAssociatedAccesors);

MHostTask.reset(new detail::HostTask(std::move(Func)));
if constexpr (detail::check_fn_signature<std::remove_reference_t<FuncT>,
void(interop_handle)>::value)
MHostTask.reset(
new detail::HostTask(std::move(Func), std::move(PropList)));
else
MHostTask.reset(new detail::HostTask(std::move(Func)));

setType(detail::CG::CodeplayHostTask);
}
Expand Down Expand Up @@ -1947,8 +1952,8 @@ class __SYCL_EXPORT handler {
void()>::value ||
detail::check_fn_signature<std::remove_reference_t<FuncT>,
void(interop_handle)>::value>
host_task(FuncT &&Func) {
host_task_impl(Func);
host_task(FuncT &&Func, const property_list PropList = {}) {
host_task_impl(Func, PropList);
}

/// Defines and invokes a SYCL kernel function for the specified range and
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/properties/all_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <sycl/ext/codeplay/experimental/fusion_properties.hpp>
#include <sycl/ext/codeplay/experimental/host_task_properties.hpp>
#include <sycl/properties/accessor_properties.hpp>
#include <sycl/properties/buffer_properties.hpp>
#include <sycl/properties/context_properties.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// REQUIRES: cuda
//
// RUN: %{build} -o %t.out -lcuda
// RUN: %{run} %t.out

#include "host-task-native-events-cuda.hpp"
#include <cuda.h>
#include <sycl/sycl.hpp>

void test_empty_host_task_with_manual_interop_sync_property() {
sycl::queue{}.submit([&](sycl::handler &cgh) {
cgh.host_task([&](sycl::interop_handle ih) {},
{sycl::ext::codeplay::experimental::property::host_task::
manual_interop_sync{}});
});
}

int main() { test_empty_host_task_with_manual_interop_sync_property(); }

0 comments on commit d50f23b

Please sign in to comment.