Skip to content

Commit ca2c5bb

Browse files
authored
[SYCL] Rework of SYCL poperties (#2196)
Changed property_list class to support properties of unknown type. This is achieved by splitting properties to two types: simple and complex. Simple are those which do not have any date - just represent that something is enabled or disabled. Compilex properties have some data. Simple properties have compile time known id, so they are always stored in the property_list even if they are not set. Complex are allocated dynamically and accessed through the common base class.
1 parent 17f0d2b commit ca2c5bb

File tree

12 files changed

+371
-300
lines changed

12 files changed

+371
-300
lines changed

sycl/include/CL/sycl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
#include <CL/sycl/platform.hpp>
3838
#include <CL/sycl/pointers.hpp>
3939
#include <CL/sycl/program.hpp>
40+
#include <CL/sycl/properties/accessor_properties.hpp>
41+
#include <CL/sycl/properties/buffer_properties.hpp>
42+
#include <CL/sycl/properties/context_properties.hpp>
43+
#include <CL/sycl/properties/image_properties.hpp>
44+
#include <CL/sycl/properties/queue_properties.hpp>
4045
#include <CL/sycl/queue.hpp>
4146
#include <CL/sycl/range.hpp>
4247
#include <CL/sycl/sampler.hpp>

sycl/include/CL/sycl/accessor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <CL/sycl/id.hpp>
2323
#include <CL/sycl/image.hpp>
2424
#include <CL/sycl/pointers.hpp>
25+
#include <CL/sycl/properties/accessor_properties.hpp>
26+
#include <CL/sycl/property_list.hpp>
2527
#include <CL/sycl/sampler.hpp>
2628

2729
/// \file accessor.hpp
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//==--------- property_helper.hpp --- SYCL property helper -----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/detail/common.hpp>
12+
13+
__SYCL_INLINE_NAMESPACE(cl) {
14+
namespace sycl {
15+
16+
namespace detail {
17+
18+
// All properties are split here to dataless properties and properties with
19+
// data. A dataless property is one which has no data stored in it. A property
20+
// with data is one which has data stored in it and usually provides and access
21+
// to it. For dataless property we just store a bool which indicates if a
22+
// property is set or not. For properties with data we store a pointer to the
23+
// base class because we do not know the size of such properties beforehand.
24+
25+
// List of all dataless properties' IDs
26+
enum DataLessPropKind {
27+
BufferUseHostPtr = 0,
28+
ImageUseHostPtr,
29+
QueueEnableProfiling,
30+
InOrder,
31+
NoInit,
32+
BufferUsePinnedHostMemory,
33+
UsePrimaryContext,
34+
DataLessPropKindSize
35+
};
36+
37+
// List of all properties with data IDs
38+
enum PropWithDataKind {
39+
BufferUseMutex = 0,
40+
BufferContextBound,
41+
ImageUseMutex,
42+
ImageContextBound,
43+
PropWithDataKindSize
44+
};
45+
46+
// Base class for dataless properties, needed to check that the type of an
47+
// object passed to the property_list is a property.
48+
class DataLessPropertyBase {};
49+
50+
// Helper class for the dataless properties. Every such property is supposed
51+
// to inherit from it. The ID template parameter should be one from
52+
// DataLessPropKind.
53+
template <int ID> class DataLessProperty : DataLessPropertyBase {
54+
public:
55+
static constexpr int getKind() { return ID; }
56+
};
57+
58+
// Base class for properties with data, needed to check that the type of an
59+
// object passed to the property_list is a property and for checking if two
60+
// properties with data are of the same type.
61+
class PropertyWithDataBase {
62+
public:
63+
PropertyWithDataBase(int ID) : MID(ID) {}
64+
bool isSame(int ID) const { return ID == MID; }
65+
virtual ~PropertyWithDataBase() = default;
66+
67+
private:
68+
int MID = -1;
69+
};
70+
71+
// Helper class for the properties with data. Every such property is supposed
72+
// to inherit from it. The ID template parameter should be one from
73+
// PropWithDataKind.
74+
template <int ID> class PropertyWithData : public PropertyWithDataBase {
75+
public:
76+
PropertyWithData() : PropertyWithDataBase(ID) {}
77+
static int getKind() { return ID; }
78+
};
79+
80+
} // namespace detail
81+
82+
} // namespace sycl
83+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <CL/sycl/detail/sycl_mem_obj_i.hpp>
1515
#include <CL/sycl/detail/type_traits.hpp>
1616
#include <CL/sycl/event.hpp>
17+
#include <CL/sycl/properties/buffer_properties.hpp>
18+
#include <CL/sycl/properties/image_properties.hpp>
1719
#include <CL/sycl/property_list.hpp>
1820
#include <CL/sycl/stl.hpp>
1921

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//==----------- accessor_properties.hpp --- SYCL accessor properties -------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/detail/common.hpp>
12+
#include <CL/sycl/detail/property_helper.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace property {
17+
18+
class noinit : public detail::DataLessProperty<detail::NoInit> {};
19+
20+
} // namespace property
21+
22+
#if __cplusplus > 201402L
23+
24+
inline constexpr property::noinit noinit;
25+
26+
#else
27+
28+
namespace {
29+
30+
constexpr const auto &noinit =
31+
sycl::detail::InlineVariableHelper<property::noinit>::value;
32+
}
33+
34+
#endif
35+
36+
} // namespace sycl
37+
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//==----------- buffer_properties.hpp --- SYCL buffer properties -----------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/context.hpp>
12+
#include <CL/sycl/detail/property_helper.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
17+
namespace property {
18+
namespace buffer {
19+
class use_host_ptr : public detail::DataLessProperty<detail::BufferUseHostPtr> {
20+
};
21+
22+
class use_mutex : public detail::PropertyWithData<detail::BufferUseMutex> {
23+
public:
24+
use_mutex(sycl::mutex_class &MutexRef) : MMutex(MutexRef) {}
25+
26+
sycl::mutex_class *get_mutex_ptr() const { return &MMutex; }
27+
28+
private:
29+
sycl::mutex_class &MMutex;
30+
};
31+
32+
class context_bound
33+
: public detail::PropertyWithData<detail::BufferContextBound> {
34+
public:
35+
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}
36+
37+
context get_context() const { return MCtx; }
38+
39+
private:
40+
sycl::context MCtx;
41+
};
42+
} // namespace buffer
43+
} // namespace property
44+
45+
namespace ext {
46+
namespace oneapi {
47+
namespace property {
48+
namespace buffer {
49+
50+
class use_pinned_host_memory
51+
: public detail::DataLessProperty<detail::BufferUsePinnedHostMemory> {};
52+
} // namespace buffer
53+
} // namespace property
54+
} // namespace oneapi
55+
} // namespace ext
56+
} // namespace sycl
57+
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//==----------- context_properties.hpp --- SYCL context properties ---------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/context.hpp>
12+
#include <CL/sycl/detail/property_helper.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace property {
17+
namespace context {
18+
namespace cuda {
19+
class use_primary_context
20+
: public detail::DataLessProperty<detail::UsePrimaryContext> {};
21+
} // namespace cuda
22+
} // namespace context
23+
} // namespace property
24+
} // namespace sycl
25+
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//==----------- image_properties.hpp --- SYCL image properties -------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/context.hpp>
12+
#include <CL/sycl/detail/property_helper.hpp>
13+
14+
__SYCL_INLINE_NAMESPACE(cl) {
15+
namespace sycl {
16+
namespace property {
17+
namespace image {
18+
class use_host_ptr : public detail::DataLessProperty<detail::ImageUseHostPtr> {
19+
};
20+
21+
class use_mutex : public detail::PropertyWithData<detail::ImageUseMutex> {
22+
public:
23+
use_mutex(sycl::mutex_class &MutexRef) : MMutex(MutexRef) {}
24+
25+
sycl::mutex_class *get_mutex_ptr() const { return &MMutex; }
26+
27+
private:
28+
sycl::mutex_class &MMutex;
29+
};
30+
31+
class context_bound
32+
: public detail::PropertyWithData<detail::ImageContextBound> {
33+
public:
34+
context_bound(sycl::context BoundContext) : MCtx(std::move(BoundContext)) {}
35+
36+
context get_context() const { return MCtx; }
37+
38+
private:
39+
sycl::context MCtx;
40+
};
41+
} // namespace image
42+
} // namespace property
43+
} // namespace sycl
44+
} // __SYCL_INLINE_NAMESPACE(cl)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//==----------- queue_properties.hpp --- SYCL queue properties -------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/detail/property_helper.hpp>
12+
13+
__SYCL_INLINE_NAMESPACE(cl) {
14+
namespace sycl {
15+
namespace property {
16+
namespace queue {
17+
class in_order : public detail::DataLessProperty<detail::InOrder> {};
18+
class enable_profiling
19+
: public detail::DataLessProperty<detail::QueueEnableProfiling> {};
20+
} // namespace queue
21+
} // namespace property
22+
} // namespace sycl
23+
} // __SYCL_INLINE_NAMESPACE(cl)

0 commit comments

Comments
 (0)