Skip to content

Commit b8ac69c

Browse files
committed
Support for USM; queue profiling
1 parent 05e4c95 commit b8ac69c

File tree

11 files changed

+612
-55
lines changed

11 files changed

+612
-55
lines changed

include/simsycl/sycl.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
#include "sycl/reduction.hh"
2828
#include "sycl/sub_group.hh"
2929
#include "sycl/type_traits.hh"
30+
#include "sycl/usm.hh"

include/simsycl/sycl/enums.hh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include <cstdint>
4+
5+
36
namespace simsycl::sycl {
47

58
enum class addressing_mode { mirrored_repeat, repeat, clamp_to_edge, clamp, none };
@@ -307,9 +310,17 @@ struct command_execution_status;
307310

308311
namespace simsycl::sycl::info::event_profiling {
309312

310-
struct command_submit;
311-
struct command_start;
312-
struct command_end;
313+
struct command_submit {
314+
using return_type = uint64_t;
315+
};
316+
317+
struct command_start {
318+
using return_type = uint64_t;
319+
};
320+
321+
struct command_end {
322+
using return_type = uint64_t;
323+
};
313324

314325
} // namespace simsycl::sycl::info::event_profiling
315326

include/simsycl/sycl/event.hh

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,110 @@
11
#pragma once
22

33
#include "forward.hh"
4+
#include "type_traits.hh"
45

6+
#include "../detail/reference_type.hh"
7+
8+
#include <chrono>
59
#include <vector>
610

11+
12+
namespace simsycl::detail {
13+
14+
struct execution_status {
15+
std::chrono::steady_clock::time_point t_submit{};
16+
std::chrono::steady_clock::time_point t_start{};
17+
std::chrono::steady_clock::time_point t_end{};
18+
19+
void start() { t_start = std::chrono::steady_clock::now(); }
20+
21+
[[nodiscard]] static execution_status submit() {
22+
execution_status status;
23+
status.t_submit = std::chrono::steady_clock::now();
24+
return status;
25+
}
26+
27+
[[nodiscard]] static execution_status submit_and_start() {
28+
auto status = submit();
29+
status.start();
30+
return status;
31+
}
32+
33+
[[nodiscard]] sycl::event end();
34+
35+
[[nodiscard]] static sycl::event instant();
36+
};
37+
38+
template <typename Clock, typename Dur>
39+
uint64_t nanoseconds_since_epoch(std::chrono::time_point<Clock, Dur> time_point) {
40+
return std::chrono::duration_cast<std::chrono::nanoseconds>(time_point.time_since_epoch()).count();
41+
}
42+
43+
} // namespace simsycl::detail
44+
745
namespace simsycl::sycl {
846

9-
class event {
10-
public:
11-
event() = default;
47+
class event : detail::reference_type<event, detail::execution_status> {
48+
public:
49+
event() = default;
1250

13-
/* -- common interface members -- */
51+
backend get_backend() const noexcept;
1452

15-
backend get_backend() const noexcept;
53+
std::vector<event> get_wait_list();
1654

17-
std::vector<event> get_wait_list();
55+
void wait() {}
1856

19-
void wait() {}
57+
static void wait(const std::vector<event> & /* event_list */) {}
2058

21-
static void wait(const std::vector<event>& /* event_list */) {}
59+
void wait_and_throw() {}
2260

23-
void wait_and_throw() {}
61+
static void wait_and_throw(const std::vector<event> & /* event_list */) {}
2462

25-
static void wait_and_throw(const std::vector<event>& /* event_list */) {}
63+
template <typename Param>
64+
typename Param::return_type get_info() const {
65+
if constexpr(std::is_same_v<Param, info::event::command_execution_status>) {
66+
return info::event_command_status::complete;
67+
} else {
68+
static_assert(detail::always_false<Param>, "Unknown event::get_info() parameter");
69+
}
70+
}
2671

27-
template <typename Param> typename Param::return_type get_info() const;
72+
template <typename Param>
73+
typename Param::return_type get_backend_info() const {
74+
static_assert(detail::always_false<Param>, "Unknown event::get_backend_info() parameter");
75+
}
2876

29-
template <typename Param>
30-
typename Param::return_type get_backend_info() const;
77+
template <typename Param>
78+
typename Param::return_type get_profiling_info() const {
79+
if constexpr(std::is_same_v<Param, info::event_profiling::command_submit>) {
80+
return detail::nanoseconds_since_epoch(state().t_submit);
81+
} else if constexpr(std::is_same_v<Param, info::event_profiling::command_start>) {
82+
return detail::nanoseconds_since_epoch(state().t_start);
83+
} else if constexpr(std::is_same_v<Param, info::event_profiling::command_end>) {
84+
return detail::nanoseconds_since_epoch(state().t_end);
85+
} else {
86+
static_assert(detail::always_false<Param>, "Unknown event::get_profiling_info() parameter");
87+
}
88+
}
3189

32-
template <typename Param>
33-
typename Param::return_type get_profiling_info() const;
90+
private:
91+
friend event detail::make_event(const detail::execution_status &status);
92+
93+
explicit event(const detail::execution_status &status)
94+
: detail::reference_type<event, detail::execution_status>(std::in_place, status) {}
3495
};
3596

36-
} // namespace sycl
97+
} // namespace simsycl::sycl
98+
99+
namespace simsycl::detail {
100+
101+
inline sycl::event make_event(const execution_status &status) { return sycl::event(status); }
102+
103+
inline sycl::event execution_status::end() {
104+
t_end = std::chrono::steady_clock::now();
105+
return make_event(*this);
106+
}
107+
108+
inline sycl::event execution_status::instant() { return submit_and_start().end(); }
109+
110+
} // namespace simsycl::detail

include/simsycl/sycl/forward.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,8 @@ sycl::handler make_handler();
110110

111111
void **require_local_memory(sycl::handler &cgh, size_t size, size_t align);
112112

113+
struct execution_status;
114+
115+
sycl::event make_event(const execution_status &status);
116+
113117
} // namespace simsycl::detail

include/simsycl/sycl/group_algorithms.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ T permute_group(G g, T x, typename G::linear_id_type mask) {
216216
}});
217217
}
218218

219+
template <typename Group, typename T>
220+
T permute_group_by_xor(Group g, T x, typename Group::linear_id_type mask); // TODO
221+
222+
219223
// select
220224

221225
template <SubGroup G, TriviallyCopyable T>

include/simsycl/sycl/multi_ptr.hh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "accessor.hh"
43
#include "enums.hh"
54
#include "forward.hh"
65

@@ -306,4 +305,36 @@ using global_ptr = multi_ptr<ElementType, access::address_space::global_space, I
306305
template <typename ElementType, access::decorated IsDecorated = access::decorated::legacy>
307306
using local_ptr = multi_ptr<ElementType, access::address_space::local_space, IsDecorated>;
308307

308+
// Deprecated in SYCL 2020
309+
template <typename ElementType>
310+
311+
using constant_ptr [[deprecated]]
312+
= multi_ptr<ElementType, access::address_space::constant_space, access::decorated::legacy>;
313+
314+
template <typename ElementType, access::decorated IsDecorated = access::decorated::legacy>
315+
using private_ptr = multi_ptr<ElementType, access::address_space::private_space, IsDecorated>;
316+
317+
// Template specialization aliases for different pointer address spaces.
318+
// The interface exposes non-decorated pointer while keeping the address space information internally.
319+
320+
template <typename ElementType>
321+
using raw_global_ptr = multi_ptr<ElementType, access::address_space::global_space, access::decorated::no>;
322+
323+
template <typename ElementType>
324+
using raw_local_ptr = multi_ptr<ElementType, access::address_space::local_space, access::decorated::no>;
325+
326+
template <typename ElementType>
327+
using raw_private_ptr = multi_ptr<ElementType, access::address_space::private_space, access::decorated::no>;
328+
329+
// Template specialization aliases for different pointer address spaces.
330+
// The interface exposes decorated pointer.
331+
template <typename ElementType>
332+
using decorated_global_ptr = multi_ptr<ElementType, access::address_space::global_space, access::decorated::yes>;
333+
334+
template <typename ElementType>
335+
using decorated_local_ptr = multi_ptr<ElementType, access::address_space::local_space, access::decorated::yes>;
336+
337+
template <typename ElementType>
338+
using decorated_private_ptr = multi_ptr<ElementType, access::address_space::private_space, access::decorated::yes>;
339+
309340
} // namespace simsycl::sycl

include/simsycl/sycl/nd_item.hh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "group.hh"
88
#include "id.hh"
9+
#include "multi_ptr.hh"
910
#include "range.hh"
1011
#include "sub_group.hh"
1112

@@ -41,6 +42,11 @@ sycl::nd_item<Dimensions> make_nd_item(const sycl::item<Dimensions, false> &glob
4142

4243
namespace simsycl::sycl {
4344

45+
class device_event {
46+
public:
47+
void wait() noexcept {}
48+
};
49+
4450
template <int Dimensions>
4551
class nd_item {
4652
public:
@@ -104,6 +110,46 @@ class nd_item {
104110
SIMSYCL_NOT_IMPLEMENTED(access_space);
105111
}
106112

113+
// Deprecated in SYCL 2020.
114+
template <typename DataT>
115+
[[deprecated]] device_event async_work_group_copy(
116+
local_ptr<DataT> dest, global_ptr<DataT> src, size_t num_elements) const;
117+
118+
// Deprecated in SYCL 2020.
119+
template <typename DataT>
120+
[[deprecated]] device_event async_work_group_copy(
121+
global_ptr<DataT> dest, local_ptr<DataT> src, size_t num_elements) const;
122+
123+
// Deprecated in SYCL 2020.
124+
template <typename DataT>
125+
[[deprecated]] device_event async_work_group_copy(
126+
local_ptr<DataT> dest, global_ptr<DataT> src, size_t num_elements, size_t src_stride) const;
127+
128+
// Deprecated in SYCL 2020.
129+
template <typename DataT>
130+
[[deprecated]] device_event async_work_group_copy(
131+
global_ptr<DataT> dest, local_ptr<DataT> src, size_t num_elements, size_t dest_stride) const;
132+
133+
template <typename DestDataT, typename SrcDataT>
134+
requires(std::is_same_v<DestDataT, std::remove_const_t<SrcDataT>>)
135+
device_event async_work_group_copy(
136+
decorated_local_ptr<DestDataT> dest, decorated_global_ptr<SrcDataT> src, size_t num_elements) const;
137+
138+
template <typename DestDataT, typename SrcDataT>
139+
requires(std::is_same_v<DestDataT, std::remove_const_t<SrcDataT>>)
140+
device_event async_work_group_copy(
141+
decorated_global_ptr<DestDataT> dest, decorated_local_ptr<SrcDataT> src, size_t num_elements) const;
142+
143+
template <typename DestDataT, typename SrcDataT>
144+
requires(std::is_same_v<DestDataT, std::remove_const_t<SrcDataT>>)
145+
device_event async_work_group_copy(decorated_local_ptr<DestDataT> dest, decorated_global_ptr<SrcDataT> src,
146+
size_t num_elements, size_t src_stride) const;
147+
148+
template <typename DestDataT, typename SrcDataT>
149+
requires(std::is_same_v<DestDataT, std::remove_const_t<SrcDataT>>)
150+
device_event async_work_group_copy(decorated_global_ptr<DestDataT> dest, decorated_local_ptr<SrcDataT> src,
151+
size_t num_elements, size_t dest_stride) const;
152+
107153
template <typename... Events>
108154
void wait_for(Events... events) const {
109155
m_group.wait_for(events...);

include/simsycl/sycl/property.hh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ class property_list {
3434
requires(is_property_v<Properties> && ...)
3535
property_list(Properties... props) : m_properties{props...} {}
3636

37+
// Implemented by hipSYCL and DPC++ although the spec does not mention any members beside the constructor
38+
template <typename Property>
39+
bool has_property() const noexcept {
40+
return std::any_of(m_properties.begin(), m_properties.end(),
41+
[](const std::any &prop) { return prop.type() == typeid(Property); });
42+
}
43+
44+
// Implemented by hipSYCL and DPC++ although the spec does not mention any members beside the constructor
45+
template <typename Property>
46+
Property get_property() const {
47+
const auto iter = std::find_if(m_properties.begin(), m_properties.end(),
48+
[](const std::any &prop) { return prop.type() == typeid(Property); });
49+
SIMSYCL_CHECK(iter != m_properties.end());
50+
return std::any_cast<Property>(*iter);
51+
}
52+
3753
private:
3854
friend class detail::property_interface;
3955

0 commit comments

Comments
 (0)