Skip to content

[SYCL] Add missing constructors and propety methods #2368

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
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
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include(AddSYCLExecutable)
set(SYCL_MAJOR_VERSION 3)
set(SYCL_MINOR_VERSION 0)
set(SYCL_PATCH_VERSION 0)
set(SYCL_DEV_ABI_VERSION 1)
set(SYCL_DEV_ABI_VERSION 2)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
6 changes: 1 addition & 5 deletions sycl/include/CL/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@
#include <CL/sycl/platform.hpp>
#include <CL/sycl/pointers.hpp>
#include <CL/sycl/program.hpp>
#include <CL/sycl/properties/accessor_properties.hpp>
#include <CL/sycl/properties/buffer_properties.hpp>
#include <CL/sycl/properties/context_properties.hpp>
#include <CL/sycl/properties/image_properties.hpp>
#include <CL/sycl/properties/queue_properties.hpp>
#include <CL/sycl/properties/all_properties.hpp>
#include <CL/sycl/queue.hpp>
#include <CL/sycl/range.hpp>
#include <CL/sycl/sampler.hpp>
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
//===----------------------------------------------------------------------===//

#pragma once

#include <CL/sycl/detail/buffer_impl.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/stl_type_traits.hpp>
#include <CL/sycl/exception.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/stl.hpp>

// TODO: 4.3.4 Properties

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {

class handler;
class queue;
template <int dimensions> class range;
Expand Down
97 changes: 80 additions & 17 deletions sycl/include/CL/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/exception_list.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/stl.hpp>

#include <type_traits>
Expand All @@ -33,46 +34,94 @@ class context_impl;
/// \ingroup sycl_api
class __SYCL_EXPORT context {
public:
/// Constructs a SYCL context instance using an instance of default_selector.
///
/// The instance of default_selector is used to select the associated platform
/// and device(s).
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param PropList is an instance of property_list.
explicit context(const property_list &PropList = {});

/// Constructs a SYCL context instance using an instance of default_selector.
///
/// The instance of default_selector is used to select the associated platform
/// and device(s).
/// The constructed SYCL context will use the AsyncHandler parameter to handle
/// exceptions.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param AsyncHandler is an instance of async_handler.
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
/// primary context in the CUDA backend.
explicit context(const async_handler &AsyncHandler = {},
bool UseCUDAPrimaryContext = false);
/// \param PropList is an instance of property_list.
explicit context(const async_handler &AsyncHandler,
const property_list &PropList = {});

/// Constructs a SYCL context instance using the provided device.
///
/// Newly created context is associated with the Device and the SYCL platform
/// that is associated with the Device.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param Device is an instance of SYCL device.
/// \param PropList is an instance of property_list.
explicit context(const device &Device, const property_list &PropList = {});

/// Constructs a SYCL context instance using the provided device.
///
/// Newly created context is associated with the Device and the SYCL platform
/// that is associated with the Device.
/// The constructed SYCL context will use the AsyncHandler parameter to handle
/// exceptions.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param Device is an instance of SYCL device.
/// \param AsyncHandler is an instance of async_handler.
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
/// primary context in the CUDA backend.
explicit context(const device &Device, async_handler AsyncHandler = {},
bool UseCUDAPrimaryContext = false);
/// \param PropList is an instance of property_list.
explicit context(const device &Device, async_handler AsyncHandler,
const property_list &PropList = {});

/// Constructs a SYCL context instance using the provided platform.
///
/// Newly created context is associated with the Platform and with each
/// SYCL device that is associated with the Platform.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param Platform is an instance of SYCL platform.
/// \param PropList is an instance of property_list.
explicit context(const platform &Platform,
const property_list &PropList = {});

/// Constructs a SYCL context instance using the provided platform.
///
/// Newly created context is associated with the Platform and with each
/// SYCL device that is associated with the Platform.
/// The constructed SYCL context will use the AsyncHandler parameter to handle
/// exceptions.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param Platform is an instance of SYCL platform.
/// \param AsyncHandler is an instance of async_handler.
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
/// primary context in the CUDA backend.
explicit context(const platform &Platform, async_handler AsyncHandler = {},
bool UseCUDAPrimaryContext = false);
/// \param PropList is an instance of property_list.
explicit context(const platform &Platform, async_handler AsyncHandler,
const property_list &PropList = {});

/// Constructs a SYCL context instance using list of devices.
///
/// Newly created context will be associated with each SYCL device in the
/// DeviceList. This requires that all SYCL devices in the list have the same
/// associated SYCL platform.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param DeviceList is a list of SYCL device instances.
/// \param PropList is an instance of property_list.
explicit context(const vector_class<device> &DeviceList,
const property_list &PropList = {});

/// Constructs a SYCL context instance using list of devices.
///
Expand All @@ -81,14 +130,15 @@ class __SYCL_EXPORT context {
/// associated SYCL platform.
/// The constructed SYCL context will use the AsyncHandler parameter to handle
/// exceptions.
/// SYCL properties are passed to the constructed SYCL context through
/// PropList.
///
/// \param DeviceList is a list of SYCL device instances.
/// \param AsyncHandler is an instance of async_handler.
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
/// primary context in the CUDA backend.
/// \param PropList is an instance of property_list.
explicit context(const vector_class<device> &DeviceList,
async_handler AsyncHandler = {},
bool UseCUDAPrimaryContext = false);
async_handler AsyncHandler,
const property_list &PropList = {});

/// Constructs a SYCL context instance from OpenCL cl_context.
///
Expand Down Expand Up @@ -119,6 +169,19 @@ class __SYCL_EXPORT context {

bool operator!=(const context &rhs) const { return !(*this == rhs); }

/// Checks if this context has a property of type propertyT.
///
/// \return true if this context has a property of type propertyT.
template <typename propertyT> bool has_property() const;

/// Gets the specified property of this context.
///
/// Throws invalid_object_error if this context does not have a property
/// of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;

/// Gets OpenCL interoperability context.
///
/// The OpenCL cl_context handle is retained on return.
Expand Down
10 changes: 10 additions & 0 deletions sycl/include/CL/sycl/detail/properties_traits.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PARAM_TRAITS_SPEC(sycl::property::buffer::use_host_ptr)
PARAM_TRAITS_SPEC(sycl::property::buffer::use_mutex)
PARAM_TRAITS_SPEC(sycl::property::buffer::context_bound)
PARAM_TRAITS_SPEC(sycl::property::image::use_host_ptr)
PARAM_TRAITS_SPEC(sycl::property::image::use_mutex)
PARAM_TRAITS_SPEC(sycl::property::image::context_bound)
PARAM_TRAITS_SPEC(sycl::ext::oneapi::property::buffer::use_pinned_host_memory)
PARAM_TRAITS_SPEC(sycl::property::noinit)
PARAM_TRAITS_SPEC(sycl::property::context::cuda::use_primary_context)
PARAM_TRAITS_SPEC(sycl::property::queue::in_order)
40 changes: 37 additions & 3 deletions sycl/include/CL/sycl/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <CL/sycl/detail/os_util.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/kernel.hpp>
#include <CL/sycl/property_list.hpp>
#include <CL/sycl/stl.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
Expand Down Expand Up @@ -46,7 +47,8 @@ class __SYCL_EXPORT program {
/// associated with the context.
///
/// \param Context is an instance of SYCL context.
explicit program(const context &Context);
/// \param PropList is an instance of property_list.
explicit program(const context &Context, const property_list &PropList = {});

/// Constructs an instance of SYCL program for the provided DeviceList.
///
Expand All @@ -56,7 +58,24 @@ class __SYCL_EXPORT program {
///
/// \param Context is an instance of SYCL context.
/// \param DeviceList is a list of SYCL devices.
program(const context &Context, vector_class<device> DeviceList);
/// \param PropList is an instance of property_list.
program(const context &Context, vector_class<device> DeviceList,
const property_list &PropList = {});

/// Constructs an instance of SYCL program by linking together each SYCL
/// program instance in ProgramList.
///
/// Each SYCL program in ProgramList must be in the program_state::compiled
/// state and must be associated with the same SYCL context. Otherwise an
/// invalid_object_error SYCL exception will be thrown. A
/// feature_not_supported exception will be thrown if any device that the
/// program is to be linked for returns false for the device information query
/// info::device::is_linker_available.
///
/// \param ProgramList is a list of SYCL program instances.
/// \param PropList is an instance of property_list.
program(vector_class<program> ProgramList,
const property_list &PropList = {});

/// Constructs an instance of SYCL program by linking together each SYCL
/// program instance in ProgramList.
Expand All @@ -70,7 +89,9 @@ class __SYCL_EXPORT program {
///
/// \param ProgramList is a list of SYCL program instances.
/// \param LinkOptions is a string containing valid OpenCL link options.
program(vector_class<program> ProgramList, string_class LinkOptions = "");
/// \param PropList is an instance of property_list.
program(vector_class<program> ProgramList, string_class LinkOptions,
const property_list &PropList = {});

/// Constructs a SYCL program instance from an OpenCL cl_program.
///
Expand All @@ -97,6 +118,19 @@ class __SYCL_EXPORT program {

bool operator!=(const program &rhs) const { return impl != rhs.impl; }

/// Checks if this program has a property of type propertyT.
///
/// \return true if this context has a property of type propertyT.
template <typename propertyT> bool has_property() const;

/// Gets the specified property of this program.
///
/// Throws invalid_object_error if this program does not have a property
/// of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;

/// Returns a valid cl_program instance.
///
/// The instance of cl_program will be retained before returning.
Expand Down
5 changes: 5 additions & 0 deletions sycl/include/CL/sycl/properties/all_properties.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <CL/sycl/properties/accessor_properties.hpp>
#include <CL/sycl/properties/buffer_properties.hpp>
#include <CL/sycl/properties/context_properties.hpp>
#include <CL/sycl/properties/image_properties.hpp>
#include <CL/sycl/properties/queue_properties.hpp>
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/properties/buffer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class context_bound
public:
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}

context get_context() const { return MCtx; }
sycl::context get_context() const { return MCtx; }

private:
sycl::context MCtx;
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/properties/image_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class context_bound
public:
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}

context get_context() const { return MCtx; }
sycl::context get_context() const { return MCtx; }

private:
sycl::context MCtx;
Expand Down
17 changes: 16 additions & 1 deletion sycl/include/CL/sycl/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <CL/sycl/access/access.hpp>
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/property_list.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
Expand Down Expand Up @@ -64,7 +65,8 @@ class sampler_impl;
class __SYCL_EXPORT sampler {
public:
sampler(coordinate_normalization_mode normalizationMode,
addressing_mode addressingMode, filtering_mode filteringMode);
addressing_mode addressingMode, filtering_mode filteringMode,
const property_list &propList = {});

sampler(cl_sampler clSampler, const context &syclContext);

Expand All @@ -80,6 +82,19 @@ class __SYCL_EXPORT sampler {

bool operator!=(const sampler &rhs) const;

/// Checks if this sampler has a property of type propertyT.
///
/// \return true if this sampler has a property of type propertyT.
template <typename propertyT> bool has_property() const;

/// Gets the specified property of this sampler.
///
/// Throws invalid_object_error if this sampler does not have a property
/// of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;

addressing_mode get_addressing_mode() const;

filtering_mode get_filtering_mode() const;
Expand Down
Loading