Skip to content

Commit 4b39793

Browse files
[SYCL] Add property list to stream (#4898)
These changes add a constructor to the SYCL 2020 stream class taking a property list argument. Additionally it adds the common property interface to the stream class. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 9eb27d3 commit 4b39793

File tree

6 files changed

+120
-3
lines changed

6 files changed

+120
-3
lines changed

sycl/include/CL/sycl/stream.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS stream {
750750
// Throws exception in case of invalid input parameters
751751
stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH);
752752

753+
// Property-list constructor variant.
754+
// TODO: Merge with other stream constructor and give PropList default value.
755+
stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH,
756+
const property_list &PropList);
757+
753758
size_t get_size() const;
754759

755760
size_t get_max_statement_size() const;
@@ -764,6 +769,10 @@ class __SYCL_EXPORT __SYCL_SPECIAL_CLASS stream {
764769

765770
bool operator!=(const stream &LHS) const;
766771

772+
template <typename propertyT> bool has_property() const noexcept;
773+
774+
template <typename propertyT> propertyT get_property() const;
775+
767776
private:
768777
#ifdef __SYCL_DEVICE_ONLY__
769778
char padding[sizeof(std::shared_ptr<detail::stream_impl>)];

sycl/source/detail/stream_impl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ namespace detail {
1818

1919
stream_impl::stream_impl(size_t BufferSize, size_t MaxStatementSize,
2020
handler &CGH)
21-
: BufferSize_(BufferSize), MaxStatementSize_(MaxStatementSize) {
21+
: stream_impl(BufferSize, MaxStatementSize, {}) {
2222
(void)CGH;
23+
}
24+
25+
stream_impl::stream_impl(size_t BufferSize, size_t MaxStatementSize,
26+
const property_list &PropList)
27+
: BufferSize_(BufferSize), MaxStatementSize_(MaxStatementSize),
28+
PropList_(PropList) {
2329
// We need to store stream buffers in the scheduler because they need to be
2430
// alive after submitting the kernel. They cannot be stored in the stream
2531
// object because it causes loop dependency between objects and results in

sycl/source/detail/stream_impl.hpp

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

@@ -23,10 +24,13 @@ namespace detail {
2324

2425
class __SYCL_EXPORT stream_impl {
2526
public:
26-
// TODO: Handler argument is not used in constructor.
27+
// TODO: This constructor is unused.
2728
// To be removed when API/ABI changes are allowed.
2829
stream_impl(size_t BufferSize, size_t MaxStatementSize, handler &CGH);
2930

31+
stream_impl(size_t BufferSize, size_t MaxStatementSize,
32+
const property_list &PropList);
33+
3034
// Method to provide an access to the global stream buffer
3135
GlobalBufAccessorT accessGlobalBuf(handler &CGH);
3236

@@ -44,6 +48,14 @@ class __SYCL_EXPORT stream_impl {
4448

4549
size_t get_max_statement_size() const;
4650

51+
template <typename propertyT> bool has_property() const noexcept {
52+
return PropList_.has_property<propertyT>();
53+
}
54+
55+
template <typename propertyT> propertyT get_property() const {
56+
return PropList_.get_property<propertyT>();
57+
}
58+
4759
private:
4860
// Size of the stream buffer
4961
size_t BufferSize_;
@@ -52,6 +64,9 @@ class __SYCL_EXPORT stream_impl {
5264
// statement till the semicolon
5365
unsigned MaxStatementSize_;
5466

67+
// Property list
68+
property_list PropList_;
69+
5570
// Additinonal memory is allocated in the beginning of the stream buffer for
5671
// 2 variables: offset in the stream buffer and offset in the flush buffer.
5772
static const size_t OffsetSize = 2 * sizeof(unsigned);

sycl/source/stream.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <CL/sycl/properties/all_properties.hpp>
910
#include <CL/sycl/stream.hpp>
1011
#include <detail/queue_impl.hpp>
1112
#include <detail/stream_impl.hpp>
@@ -32,8 +33,12 @@ static size_t CheckMaxStatementSize(const size_t &MaxStatementSize) {
3233
}
3334

3435
stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH)
36+
: stream(BufferSize, MaxStatementSize, CGH, {}) {}
37+
38+
stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH,
39+
const property_list &PropList)
3540
: impl(std::make_shared<detail::stream_impl>(
36-
BufferSize, CheckMaxStatementSize(MaxStatementSize), CGH)),
41+
BufferSize, CheckMaxStatementSize(MaxStatementSize), PropList)),
3742
GlobalBuf(impl->accessGlobalBuf(CGH)),
3843
GlobalOffset(impl->accessGlobalOffset(CGH)),
3944
// Allocate the flush buffer, which contains space for each work item
@@ -59,6 +64,24 @@ bool stream::operator==(const stream &RHS) const { return (impl == RHS.impl); }
5964

6065
bool stream::operator!=(const stream &RHS) const { return !(impl == RHS.impl); }
6166

67+
#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
68+
template <> \
69+
__SYCL_EXPORT bool stream::has_property<param_type>() const noexcept { \
70+
return impl->has_property<param_type>(); \
71+
}
72+
#include <CL/sycl/detail/properties_traits.def>
73+
74+
#undef __SYCL_PARAM_TRAITS_SPEC
75+
76+
#define __SYCL_PARAM_TRAITS_SPEC(param_type) \
77+
template <> \
78+
__SYCL_EXPORT param_type stream::get_property<param_type>() const { \
79+
return impl->get_property<param_type>(); \
80+
}
81+
#include <CL/sycl/detail/properties_traits.def>
82+
83+
#undef __SYCL_PARAM_TRAITS_SPEC
84+
6285
} // namespace sycl
6386
} // __SYCL_INLINE_NAMESPACE(cl)
6487

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,7 +3811,9 @@ _ZN2cl4sycl6detail11stream_impl15accessGlobalBufERNS0_7handlerE
38113811
_ZN2cl4sycl6detail11stream_impl18accessGlobalOffsetERNS0_7handlerE
38123812
_ZN2cl4sycl6detail11stream_impl20accessGlobalFlushBufERNS0_7handlerE
38133813
_ZN2cl4sycl6detail11stream_impl5flushEv
3814+
_ZN2cl4sycl6detail11stream_implC1EmmRKNS0_13property_listE
38143815
_ZN2cl4sycl6detail11stream_implC1EmmRNS0_7handlerE
3816+
_ZN2cl4sycl6detail11stream_implC2EmmRKNS0_13property_listE
38153817
_ZN2cl4sycl6detail11stream_implC2EmmRNS0_7handlerE
38163818
_ZN2cl4sycl6detail12compile_implERKNS0_13kernel_bundleILNS0_12bundle_stateE0EEERKSt6vectorINS0_6deviceESaIS8_EERKNS0_13property_listE
38173819
_ZN2cl4sycl6detail12isOutOfRangeENS0_3vecIiLi4EEENS0_15addressing_modeENS0_5rangeILi3EEE
@@ -3925,7 +3927,9 @@ _ZN2cl4sycl6opencl12make_contextEm
39253927
_ZN2cl4sycl6opencl12make_programERKNS0_7contextEm
39263928
_ZN2cl4sycl6opencl13make_platformEm
39273929
_ZN2cl4sycl6streamC1EmmRNS0_7handlerE
3930+
_ZN2cl4sycl6streamC1EmmRNS0_7handlerERKNS0_13property_listE
39283931
_ZN2cl4sycl6streamC2EmmRNS0_7handlerE
3932+
_ZN2cl4sycl6streamC2EmmRNS0_7handlerERKNS0_13property_listE
39293933
_ZN2cl4sycl7contextC1EP11_cl_contextSt8functionIFvNS0_14exception_listEEE
39303934
_ZN2cl4sycl7contextC1ERKNS0_13property_listE
39313935
_ZN2cl4sycl7contextC1ERKNS0_6deviceERKNS0_13property_listE
@@ -4277,6 +4281,32 @@ _ZNK2cl4sycl6kernel8get_infoILNS0_4info6kernelE4499EEENS3_12param_traitsIS4_XT_E
42774281
_ZNK2cl4sycl6kernel8get_infoILNS0_4info6kernelE4500EEENS3_12param_traitsIS4_XT_EE11return_typeEv
42784282
_ZNK2cl4sycl6kernel8get_infoILNS0_4info6kernelE4501EEENS3_12param_traitsIS4_XT_EE11return_typeEv
42794283
_ZNK2cl4sycl6kernel9getNativeEv
4284+
_ZNK2cl4sycl6stream12get_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEET_v
4285+
_ZNK2cl4sycl6stream12get_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEET_v
4286+
_ZNK2cl4sycl6stream12get_propertyINS0_8property5image12use_host_ptrEEET_v
4287+
_ZNK2cl4sycl6stream12get_propertyINS0_8property5image13context_boundEEET_v
4288+
_ZNK2cl4sycl6stream12get_propertyINS0_8property5image9use_mutexEEET_v
4289+
_ZNK2cl4sycl6stream12get_propertyINS0_8property5queue8in_orderEEET_v
4290+
_ZNK2cl4sycl6stream12get_propertyINS0_8property6buffer12use_host_ptrEEET_v
4291+
_ZNK2cl4sycl6stream12get_propertyINS0_8property6buffer13context_boundEEET_v
4292+
_ZNK2cl4sycl6stream12get_propertyINS0_8property6buffer9use_mutexEEET_v
4293+
_ZNK2cl4sycl6stream12get_propertyINS0_8property6noinitEEET_v
4294+
_ZNK2cl4sycl6stream12get_propertyINS0_8property7context4cuda19use_primary_contextEEET_v
4295+
_ZNK2cl4sycl6stream12get_propertyINS0_8property7no_initEEET_v
4296+
_ZNK2cl4sycl6stream12get_propertyINS0_8property9reduction22initialize_to_identityEEET_v
4297+
_ZNK2cl4sycl6stream12has_propertyINS0_3ext6oneapi4cuda8property7context19use_primary_contextEEEbv
4298+
_ZNK2cl4sycl6stream12has_propertyINS0_3ext6oneapi8property6buffer22use_pinned_host_memoryEEEbv
4299+
_ZNK2cl4sycl6stream12has_propertyINS0_8property5image12use_host_ptrEEEbv
4300+
_ZNK2cl4sycl6stream12has_propertyINS0_8property5image13context_boundEEEbv
4301+
_ZNK2cl4sycl6stream12has_propertyINS0_8property5image9use_mutexEEEbv
4302+
_ZNK2cl4sycl6stream12has_propertyINS0_8property5queue8in_orderEEEbv
4303+
_ZNK2cl4sycl6stream12has_propertyINS0_8property6buffer12use_host_ptrEEEbv
4304+
_ZNK2cl4sycl6stream12has_propertyINS0_8property6buffer13context_boundEEEbv
4305+
_ZNK2cl4sycl6stream12has_propertyINS0_8property6buffer9use_mutexEEEbv
4306+
_ZNK2cl4sycl6stream12has_propertyINS0_8property6noinitEEEbv
4307+
_ZNK2cl4sycl6stream12has_propertyINS0_8property7context4cuda19use_primary_contextEEEbv
4308+
_ZNK2cl4sycl6stream12has_propertyINS0_8property7no_initEEEbv
4309+
_ZNK2cl4sycl6stream12has_propertyINS0_8property9reduction22initialize_to_identityEEEbv
42804310
_ZNK2cl4sycl6stream22get_max_statement_sizeEv
42814311
_ZNK2cl4sycl6stream8get_sizeEv
42824312
_ZNK2cl4sycl6streameqERKS1_

0 commit comments

Comments
 (0)