Skip to content

Commit 865ed57

Browse files
authored
[SYCL][COMPAT] Added wait and throw free function. Minor fixes in documentation. (#13029)
This PR is mostly cleanup: - adds a free function to call to wrap queue wait and throw, which was in the documentation but not implemented. - It reduces testing coupling by including the relevant headers. - Adds a missing header in launch.cpp, which was detected when fixing the testing header includes. - Fixes a lot of function definitions in the documentation which didn't match the actual definition in the library.
1 parent 599a195 commit 865ed57

File tree

6 files changed

+66
-53
lines changed

6 files changed

+66
-53
lines changed

sycl/doc/syclcompat/README.md

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ namespace syclcompat {
8282
class dim3 {
8383
public:
8484
const size_t x, y, z;
85-
constexpr dim3(const sycl::range<3> &r);
86-
constexpr dim3(const sycl::range<2> &r);
87-
constexpr dim3(const sycl::range<1> &r);
85+
dim3(const sycl::range<3> &r);
86+
dim3(const sycl::range<2> &r);
87+
dim3(const sycl::range<1> &r);
8888
constexpr dim3(size_t x, size_t y = 1, size_t z = 1);
8989

9090
constexpr size_t size();
@@ -95,9 +95,9 @@ public:
9595
};
9696

9797
// Element-wise operators
98-
dim3 operator*(const dim3 &a, const dim3 &b);
99-
dim3 operator+(const dim3 &a, const dim3 &b);
100-
dim3 operator-(const dim3 &a, const dim3 &b);
98+
inline dim3 operator*(const dim3 &a, const dim3 &b);
99+
inline dim3 operator+(const dim3 &a, const dim3 &b);
100+
inline dim3 operator-(const dim3 &a, const dim3 &b);
101101

102102
} // syclcompat
103103
```
@@ -113,39 +113,39 @@ addition to the global range, the following helper functions are also provided:
113113
namespace syclcompat {
114114
115115
namespace local_id {
116-
size_t x();
117-
size_t y();
118-
size_t z();
116+
inline size_t x();
117+
inline size_t y();
118+
inline size_t z();
119119
} // namespace local_id
120120
121121
namespace local_range {
122-
size_t x();
123-
size_t y();
124-
size_t z();
122+
inline size_t x();
123+
inline size_t y();
124+
inline size_t z();
125125
} // namespace local_range
126126
127127
namespace work_group_id {
128-
size_t x();
129-
size_t y();
130-
size_t z();
128+
inline size_t x();
129+
inline size_t y();
130+
inline size_t z();
131131
} // namespace work_group_id
132132
133133
namespace work_group_range {
134-
size_t x();
135-
size_t y();
136-
size_t z();
134+
inline size_t x();
135+
inline size_t y();
136+
inline size_t z();
137137
} // namespace work_group_range
138138
139139
namespace global_range {
140-
size_t x();
141-
size_t y();
142-
size_t z();
140+
inline size_t x();
141+
inline size_t y();
142+
inline size_t z();
143143
} // namespace global_range
144144
145145
namespace global_id {
146-
size_t x();
147-
size_t y();
148-
size_t z();
146+
inline size_t x();
147+
inline size_t y();
148+
inline size_t z();
149149
} // namespace global_id
150150
151151
} // syclcompat
@@ -308,12 +308,13 @@ group size in each dimension.
308308
```c++
309309
namespace syclcompat {
310310
311-
void wg_barrier();
311+
inline void wg_barrier();
312312
313313
template <int Dim>
314-
sycl::nd_range<Dim> compute_nd_range(sycl::range<Dim> global_size_in,
315-
sycl::range<Dim> work_group_size);
316-
sycl::nd_range<1> compute_nd_range(int global_size_in, int work_group_size);
314+
inline sycl::nd_range<Dim> compute_nd_range(sycl::range<Dim> global_size_in,
315+
sycl::range<Dim> work_group_size);
316+
inline sycl::nd_range<1> compute_nd_range(int global_size_in,
317+
int work_group_size);
317318
318319
} // syclcompat
319320
```
@@ -330,8 +331,8 @@ out-of-order queue, either created manually or retrieved via a call to
330331
```c++
331332
namespace syclcompat {
332333

333-
sycl::queue create_queue(bool print_on_async_exceptions = false,
334-
bool in_order = true);
334+
inline sycl::queue create_queue(bool print_on_async_exceptions = false,
335+
bool in_order = true);
335336

336337
} // syclcompat
337338
```
@@ -739,46 +740,46 @@ follows:
739740
namespace syclcompat {
740741

741742
// Util function to create a new queue for the current device
742-
sycl::queue create_queue(bool print_on_async_exceptions = false,
743-
bool in_order = true);
743+
static inline sycl::queue create_queue(bool print_on_async_exceptions = false,
744+
bool in_order = true);
744745

745746
// Util function to get the default queue of current device in
746747
// device manager.
747-
sycl::queue get_default_queue();
748+
static inline sycl::queue get_default_queue();
748749

749750
// Util function to set the default queue of the current device in the
750751
// device manager.
751752
// If the device extension saved queue is the default queue,
752753
// the previous saved queue will be overwritten as well.
753754
// This function will be blocking if there are submitted kernels in the
754755
// previous default queue.
755-
void set_default_queue(const sycl::queue &q);
756+
static inline void set_default_queue(const sycl::queue &q);
756757

757758
// Util function to wait for the queued kernels.
758-
void wait(sycl::queue q = get_default_queue());
759+
static inline void wait(sycl::queue q = get_default_queue());
759760

760761
// Util function to wait for the queued kernels and throw unhandled errors.
761-
void wait_and_throw(sycl::queue q = get_default_queue());
762+
static inline void wait_and_throw(sycl::queue q = get_default_queue());
762763

763764
// Util function to get the id of current device in
764765
// device manager.
765-
unsigned int get_current_device_id();
766+
static inline unsigned int get_current_device_id();
766767

767768
// Util function to get the current device.
768-
device_ext &get_current_device();
769+
static inline device_ext &get_current_device();
769770

770771
// Util function to get a device by id.
771-
device_ext &get_device(unsigned int id);
772+
static inline device_ext &get_device(unsigned int id);
772773

773774
// Util function to get the context of the default queue of current
774775
// device in device manager.
775-
sycl::context get_default_context();
776+
static inline sycl::context get_default_context();
776777

777778
// Util function to get a CPU device.
778-
device_ext &cpu_device();
779+
static inline device_ext &cpu_device();
779780

780781
// Util function to select a device by its id
781-
unsigned int select_device(unsigned int id);
782+
static inline unsigned int select_device(unsigned int id);
782783

783784
} // syclcompat
784785
```

sycl/include/syclcompat/device.hpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
#include <unistd.h>
4646
#endif
4747
#if defined(_WIN64)
48+
#ifndef NOMINMAX
4849
#define NOMINMAX
50+
#endif
4951
#include <windows.h>
5052
#endif
5153

@@ -56,11 +58,10 @@
5658

5759
namespace syclcompat {
5860

59-
// Note: this is all code from SYCLomatic's device.hpp helper header
6061
namespace detail {
6162

6263
/// SYCL default exception handler
63-
auto exception_handler = [](sycl::exception_list exceptions) {
64+
inline auto exception_handler = [](sycl::exception_list exceptions) {
6465
for (std::exception_ptr const &e : exceptions) {
6566
try {
6667
std::rethrow_exception(e);
@@ -514,8 +515,8 @@ class dev_mgr {
514515

515516
} // namespace detail
516517

517-
inline sycl::queue create_queue(bool print_on_async_exceptions = false,
518-
bool in_order = true) {
518+
static inline sycl::queue create_queue(bool print_on_async_exceptions = false,
519+
bool in_order = true) {
519520
return *detail::dev_mgr::instance().current_device().create_queue(
520521
print_on_async_exceptions, in_order);
521522
}
@@ -537,7 +538,11 @@ static inline void set_default_queue(const sycl::queue &q) {
537538
detail::dev_mgr::instance().current_device().set_default_queue(q);
538539
}
539540

540-
inline void wait(sycl::queue q = get_default_queue()) { q.wait(); }
541+
static inline void wait(sycl::queue q = get_default_queue()) { q.wait(); }
542+
543+
static inline void wait_and_throw(sycl::queue q = get_default_queue()) {
544+
q.wait_and_throw();
545+
}
541546

542547
/// Util function to get the id of current device in
543548
/// device manager.

sycl/include/syclcompat/launch.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ sycl::event launch(const sycl::nd_range<3> &range, size_t mem_size,
9090
} // namespace detail
9191

9292
template <int Dim>
93-
sycl::nd_range<Dim> compute_nd_range(sycl::range<Dim> global_size_in,
94-
sycl::range<Dim> work_group_size) {
93+
inline sycl::nd_range<Dim> compute_nd_range(sycl::range<Dim> global_size_in,
94+
sycl::range<Dim> work_group_size) {
9595

9696
if (global_size_in.size() == 0 || work_group_size.size() == 0) {
9797
throw std::invalid_argument("Global or local size is zero!");

sycl/test-e2e/syclcompat/id_query/id_query_fixt.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
#pragma once
2424

2525
#include <sycl/sycl.hpp>
26-
#include <syclcompat.hpp>
26+
27+
#include <syclcompat/id_query.hpp>
28+
#include <syclcompat/launch.hpp>
29+
#include <syclcompat/memory.hpp>
2730

2831
// Class to launch a kernel and run a lambda on output data
2932
template <auto F> class QueryLauncher {

sycl/test-e2e/syclcompat/launch/launch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
// RUN: %clangxx -std=c++20 -fsycl -fsycl-device-code-split=per_kernel -fsycl-targets=%{sycl_triple} %s -o %t.out
2424
// RUN: %{run} %t.out
2525

26+
#include <type_traits>
27+
2628
#include <sycl/sycl.hpp>
29+
2730
#include <syclcompat/device.hpp>
2831
#include <syclcompat/launch.hpp>
29-
30-
#include <type_traits>
32+
#include <syclcompat/memory.hpp>
3133

3234
#include "../common.hpp"
3335
#include "launch_fixt.hpp"

sycl/test-e2e/syclcompat/launch/launch_fixt.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#pragma once
2424

2525
#include <sycl/sycl.hpp>
26-
#include <syclcompat.hpp>
26+
27+
#include <syclcompat/device.hpp>
28+
#include <syclcompat/dims.hpp>
2729

2830
// Struct containing test case data (local & global ranges)
2931
template <int Dim> struct RangeParams {

0 commit comments

Comments
 (0)