Skip to content

Commit 30b8acc

Browse files
authored
[SYCL] Add missing constructors and propety methods (#2368)
Add missing constructors and propety methods for context, program and sampler.
1 parent 7b9ba26 commit 30b8acc

25 files changed

+512
-104
lines changed

sycl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ include(AddSYCLExecutable)
1515
set(SYCL_MAJOR_VERSION 3)
1616
set(SYCL_MINOR_VERSION 0)
1717
set(SYCL_PATCH_VERSION 0)
18-
set(SYCL_DEV_ABI_VERSION 1)
18+
set(SYCL_DEV_ABI_VERSION 2)
1919
if (SYCL_ADD_DEV_VERSION_POSTFIX)
2020
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
2121
endif()

sycl/include/CL/sycl.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
#include <CL/sycl/platform.hpp>
3939
#include <CL/sycl/pointers.hpp>
4040
#include <CL/sycl/program.hpp>
41-
#include <CL/sycl/properties/accessor_properties.hpp>
42-
#include <CL/sycl/properties/buffer_properties.hpp>
43-
#include <CL/sycl/properties/context_properties.hpp>
44-
#include <CL/sycl/properties/image_properties.hpp>
45-
#include <CL/sycl/properties/queue_properties.hpp>
41+
#include <CL/sycl/properties/all_properties.hpp>
4642
#include <CL/sycl/queue.hpp>
4743
#include <CL/sycl/range.hpp>
4844
#include <CL/sycl/sampler.hpp>

sycl/include/CL/sycl/buffer.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
//===----------------------------------------------------------------------===//
88

99
#pragma once
10+
1011
#include <CL/sycl/detail/buffer_impl.hpp>
1112
#include <CL/sycl/detail/common.hpp>
13+
#include <CL/sycl/detail/stl_type_traits.hpp>
1214
#include <CL/sycl/exception.hpp>
15+
#include <CL/sycl/property_list.hpp>
1316
#include <CL/sycl/stl.hpp>
1417

15-
// TODO: 4.3.4 Properties
16-
1718
__SYCL_INLINE_NAMESPACE(cl) {
1819
namespace sycl {
20+
1921
class handler;
2022
class queue;
2123
template <int dimensions> class range;

sycl/include/CL/sycl/context.hpp

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <CL/sycl/detail/export.hpp>
1414
#include <CL/sycl/exception_list.hpp>
1515
#include <CL/sycl/info/info_desc.hpp>
16+
#include <CL/sycl/property_list.hpp>
1617
#include <CL/sycl/stl.hpp>
1718

1819
#include <type_traits>
@@ -33,46 +34,94 @@ class context_impl;
3334
/// \ingroup sycl_api
3435
class __SYCL_EXPORT context {
3536
public:
37+
/// Constructs a SYCL context instance using an instance of default_selector.
38+
///
39+
/// The instance of default_selector is used to select the associated platform
40+
/// and device(s).
41+
/// SYCL properties are passed to the constructed SYCL context through
42+
/// PropList.
43+
///
44+
/// \param PropList is an instance of property_list.
45+
explicit context(const property_list &PropList = {});
46+
3647
/// Constructs a SYCL context instance using an instance of default_selector.
3748
///
3849
/// The instance of default_selector is used to select the associated platform
3950
/// and device(s).
4051
/// The constructed SYCL context will use the AsyncHandler parameter to handle
4152
/// exceptions.
53+
/// SYCL properties are passed to the constructed SYCL context through
54+
/// PropList.
4255
///
4356
/// \param AsyncHandler is an instance of async_handler.
44-
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
45-
/// primary context in the CUDA backend.
46-
explicit context(const async_handler &AsyncHandler = {},
47-
bool UseCUDAPrimaryContext = false);
57+
/// \param PropList is an instance of property_list.
58+
explicit context(const async_handler &AsyncHandler,
59+
const property_list &PropList = {});
60+
61+
/// Constructs a SYCL context instance using the provided device.
62+
///
63+
/// Newly created context is associated with the Device and the SYCL platform
64+
/// that is associated with the Device.
65+
/// SYCL properties are passed to the constructed SYCL context through
66+
/// PropList.
67+
///
68+
/// \param Device is an instance of SYCL device.
69+
/// \param PropList is an instance of property_list.
70+
explicit context(const device &Device, const property_list &PropList = {});
4871

4972
/// Constructs a SYCL context instance using the provided device.
5073
///
5174
/// Newly created context is associated with the Device and the SYCL platform
5275
/// that is associated with the Device.
5376
/// The constructed SYCL context will use the AsyncHandler parameter to handle
5477
/// exceptions.
78+
/// SYCL properties are passed to the constructed SYCL context through
79+
/// PropList.
5580
///
5681
/// \param Device is an instance of SYCL device.
5782
/// \param AsyncHandler is an instance of async_handler.
58-
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
59-
/// primary context in the CUDA backend.
60-
explicit context(const device &Device, async_handler AsyncHandler = {},
61-
bool UseCUDAPrimaryContext = false);
83+
/// \param PropList is an instance of property_list.
84+
explicit context(const device &Device, async_handler AsyncHandler,
85+
const property_list &PropList = {});
86+
87+
/// Constructs a SYCL context instance using the provided platform.
88+
///
89+
/// Newly created context is associated with the Platform and with each
90+
/// SYCL device that is associated with the Platform.
91+
/// SYCL properties are passed to the constructed SYCL context through
92+
/// PropList.
93+
///
94+
/// \param Platform is an instance of SYCL platform.
95+
/// \param PropList is an instance of property_list.
96+
explicit context(const platform &Platform,
97+
const property_list &PropList = {});
6298

6399
/// Constructs a SYCL context instance using the provided platform.
64100
///
65101
/// Newly created context is associated with the Platform and with each
66102
/// SYCL device that is associated with the Platform.
67103
/// The constructed SYCL context will use the AsyncHandler parameter to handle
68104
/// exceptions.
105+
/// SYCL properties are passed to the constructed SYCL context through
106+
/// PropList.
69107
///
70108
/// \param Platform is an instance of SYCL platform.
71-
/// \param AsyncHandler is an instance of async_handler.
72-
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
73-
/// primary context in the CUDA backend.
74-
explicit context(const platform &Platform, async_handler AsyncHandler = {},
75-
bool UseCUDAPrimaryContext = false);
109+
/// \param PropList is an instance of property_list.
110+
explicit context(const platform &Platform, async_handler AsyncHandler,
111+
const property_list &PropList = {});
112+
113+
/// Constructs a SYCL context instance using list of devices.
114+
///
115+
/// Newly created context will be associated with each SYCL device in the
116+
/// DeviceList. This requires that all SYCL devices in the list have the same
117+
/// associated SYCL platform.
118+
/// SYCL properties are passed to the constructed SYCL context through
119+
/// PropList.
120+
///
121+
/// \param DeviceList is a list of SYCL device instances.
122+
/// \param PropList is an instance of property_list.
123+
explicit context(const vector_class<device> &DeviceList,
124+
const property_list &PropList = {});
76125

77126
/// Constructs a SYCL context instance using list of devices.
78127
///
@@ -81,14 +130,15 @@ class __SYCL_EXPORT context {
81130
/// associated SYCL platform.
82131
/// The constructed SYCL context will use the AsyncHandler parameter to handle
83132
/// exceptions.
133+
/// SYCL properties are passed to the constructed SYCL context through
134+
/// PropList.
84135
///
85136
/// \param DeviceList is a list of SYCL device instances.
86137
/// \param AsyncHandler is an instance of async_handler.
87-
/// \param UseCUDAPrimaryContext is a bool determining whether to use the
88-
/// primary context in the CUDA backend.
138+
/// \param PropList is an instance of property_list.
89139
explicit context(const vector_class<device> &DeviceList,
90-
async_handler AsyncHandler = {},
91-
bool UseCUDAPrimaryContext = false);
140+
async_handler AsyncHandler,
141+
const property_list &PropList = {});
92142

93143
/// Constructs a SYCL context instance from OpenCL cl_context.
94144
///
@@ -119,6 +169,19 @@ class __SYCL_EXPORT context {
119169

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

172+
/// Checks if this context has a property of type propertyT.
173+
///
174+
/// \return true if this context has a property of type propertyT.
175+
template <typename propertyT> bool has_property() const;
176+
177+
/// Gets the specified property of this context.
178+
///
179+
/// Throws invalid_object_error if this context does not have a property
180+
/// of type propertyT.
181+
///
182+
/// \return a copy of the property of type propertyT.
183+
template <typename propertyT> propertyT get_property() const;
184+
122185
/// Gets OpenCL interoperability context.
123186
///
124187
/// The OpenCL cl_context handle is retained on return.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PARAM_TRAITS_SPEC(sycl::property::buffer::use_host_ptr)
2+
PARAM_TRAITS_SPEC(sycl::property::buffer::use_mutex)
3+
PARAM_TRAITS_SPEC(sycl::property::buffer::context_bound)
4+
PARAM_TRAITS_SPEC(sycl::property::image::use_host_ptr)
5+
PARAM_TRAITS_SPEC(sycl::property::image::use_mutex)
6+
PARAM_TRAITS_SPEC(sycl::property::image::context_bound)
7+
PARAM_TRAITS_SPEC(sycl::ext::oneapi::property::buffer::use_pinned_host_memory)
8+
PARAM_TRAITS_SPEC(sycl::property::noinit)
9+
PARAM_TRAITS_SPEC(sycl::property::context::cuda::use_primary_context)
10+
PARAM_TRAITS_SPEC(sycl::property::queue::in_order)

sycl/include/CL/sycl/program.hpp

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <CL/sycl/detail/os_util.hpp>
1616
#include <CL/sycl/info/info_desc.hpp>
1717
#include <CL/sycl/kernel.hpp>
18+
#include <CL/sycl/property_list.hpp>
1819
#include <CL/sycl/stl.hpp>
1920

2021
__SYCL_INLINE_NAMESPACE(cl) {
@@ -46,7 +47,8 @@ class __SYCL_EXPORT program {
4647
/// associated with the context.
4748
///
4849
/// \param Context is an instance of SYCL context.
49-
explicit program(const context &Context);
50+
/// \param PropList is an instance of property_list.
51+
explicit program(const context &Context, const property_list &PropList = {});
5052

5153
/// Constructs an instance of SYCL program for the provided DeviceList.
5254
///
@@ -56,7 +58,24 @@ class __SYCL_EXPORT program {
5658
///
5759
/// \param Context is an instance of SYCL context.
5860
/// \param DeviceList is a list of SYCL devices.
59-
program(const context &Context, vector_class<device> DeviceList);
61+
/// \param PropList is an instance of property_list.
62+
program(const context &Context, vector_class<device> DeviceList,
63+
const property_list &PropList = {});
64+
65+
/// Constructs an instance of SYCL program by linking together each SYCL
66+
/// program instance in ProgramList.
67+
///
68+
/// Each SYCL program in ProgramList must be in the program_state::compiled
69+
/// state and must be associated with the same SYCL context. Otherwise an
70+
/// invalid_object_error SYCL exception will be thrown. A
71+
/// feature_not_supported exception will be thrown if any device that the
72+
/// program is to be linked for returns false for the device information query
73+
/// info::device::is_linker_available.
74+
///
75+
/// \param ProgramList is a list of SYCL program instances.
76+
/// \param PropList is an instance of property_list.
77+
program(vector_class<program> ProgramList,
78+
const property_list &PropList = {});
6079

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

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

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

121+
/// Checks if this program has a property of type propertyT.
122+
///
123+
/// \return true if this context has a property of type propertyT.
124+
template <typename propertyT> bool has_property() const;
125+
126+
/// Gets the specified property of this program.
127+
///
128+
/// Throws invalid_object_error if this program does not have a property
129+
/// of type propertyT.
130+
///
131+
/// \return a copy of the property of type propertyT.
132+
template <typename propertyT> propertyT get_property() const;
133+
100134
/// Returns a valid cl_program instance.
101135
///
102136
/// The instance of cl_program will be retained before returning.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <CL/sycl/properties/accessor_properties.hpp>
2+
#include <CL/sycl/properties/buffer_properties.hpp>
3+
#include <CL/sycl/properties/context_properties.hpp>
4+
#include <CL/sycl/properties/image_properties.hpp>
5+
#include <CL/sycl/properties/queue_properties.hpp>

sycl/include/CL/sycl/properties/buffer_properties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class context_bound
3434
public:
3535
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}
3636

37-
context get_context() const { return MCtx; }
37+
sycl::context get_context() const { return MCtx; }
3838

3939
private:
4040
sycl::context MCtx;

sycl/include/CL/sycl/properties/image_properties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class context_bound
3333
public:
3434
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}
3535

36-
context get_context() const { return MCtx; }
36+
sycl::context get_context() const { return MCtx; }
3737

3838
private:
3939
sycl::context MCtx;

sycl/include/CL/sycl/sampler.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <CL/sycl/access/access.hpp>
1313
#include <CL/sycl/detail/common.hpp>
1414
#include <CL/sycl/detail/export.hpp>
15+
#include <CL/sycl/property_list.hpp>
1516

1617
__SYCL_INLINE_NAMESPACE(cl) {
1718
namespace sycl {
@@ -64,7 +65,8 @@ class sampler_impl;
6465
class __SYCL_EXPORT sampler {
6566
public:
6667
sampler(coordinate_normalization_mode normalizationMode,
67-
addressing_mode addressingMode, filtering_mode filteringMode);
68+
addressing_mode addressingMode, filtering_mode filteringMode,
69+
const property_list &propList = {});
6870

6971
sampler(cl_sampler clSampler, const context &syclContext);
7072

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

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

85+
/// Checks if this sampler has a property of type propertyT.
86+
///
87+
/// \return true if this sampler has a property of type propertyT.
88+
template <typename propertyT> bool has_property() const;
89+
90+
/// Gets the specified property of this sampler.
91+
///
92+
/// Throws invalid_object_error if this sampler does not have a property
93+
/// of type propertyT.
94+
///
95+
/// \return a copy of the property of type propertyT.
96+
template <typename propertyT> propertyT get_property() const;
97+
8398
addressing_mode get_addressing_mode() const;
8499

85100
filtering_mode get_filtering_mode() const;

0 commit comments

Comments
 (0)