Skip to content

Commit de7413f

Browse files
authored
[SYCL][COMPAT] Added helper functions to manage library and kernel rt loads (#13053)
Marked as draft until #13027 gets merged. - Adds functionality to SYCLcompat to load and unload libraries at runtime. - Adds helper functions to load kernel functors from said libraries. Minor: - Tests updated to match the style of the rest of the library
1 parent 7cd48cb commit de7413f

File tree

5 files changed

+531
-62
lines changed

5 files changed

+531
-62
lines changed

sycl/doc/syclcompat/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,11 @@ expressions that might throw `sycl::exception` and `std::runtime_error`.
12371237
If no exceptions are thrown, it returns `syclcompat::error_code::SUCCESS`.
12381238
If a `sycl::exception` is caught, it returns `syclcompat::error_code::BACKEND_ERROR`.
12391239
If a `std::runtime_error` exception is caught,
1240+
12401241
`syclcompat::error_code::DEFAULT_ERROR` is returned instead. For both cases, it
12411242
prints the error message to the standard error stream.
12421243

1244+
12431245
``` c++
12441246
namespace syclcompat {
12451247

@@ -1268,6 +1270,7 @@ template <int Arg> class syclcompat_kernel_scalar;
12681270
#define SYCLCOMPAT_EXPORT
12691271
#endif
12701272

1273+
12711274
namespace syclcompat {
12721275
enum error_code { SUCCESS = 0, BACKEND_ERROR = 1, DEFAULT_ERROR = 999 };
12731276
}
@@ -1287,6 +1290,15 @@ to get the kernel information. Overloads are provided to allow either returning
12871290
a `kernel_function_info` object, or to return by pointer argument. In the
12881291
current version, `kernel_function_info` describes only maximum work-group size.
12891292
1293+
SYCLcompat also provides the `kernel_library` and `kernel_function` classes.
1294+
`kernel_library` facilitates the loading and unloading of kernel libraries.
1295+
`kernel_function` represents a specific kernel function within a loaded librariy
1296+
and can be invoked with specified arguments.
1297+
`load_kernel_library`, `load_kernel_library_mem`, and `unload_kernel_library` are
1298+
free functions to handle the loading and unloading of `kernel_library` objects.
1299+
`get_kernel_function`, and `invoke_kernel_function` offer a similar functionality
1300+
for `kernel_function` objects.
1301+
12901302
``` c++
12911303
namespace syclcompat {
12921304
@@ -1297,6 +1309,34 @@ struct kernel_function_info {
12971309
static void get_kernel_function_info(kernel_function_info *kernel_info,
12981310
const void *function);
12991311
static kernel_function_info get_kernel_function_info(const void *function);
1312+
1313+
class kernel_library {
1314+
kernel_library();
1315+
kernel_library(void *ptr);
1316+
operator void *() const;
1317+
};
1318+
1319+
static kernel_library load_kernel_library(const std::string &name);
1320+
static kernel_library load_kernel_library_mem(char const *const image);
1321+
static void unload_kernel_library(const kernel_library &library);
1322+
1323+
class kernel_function {
1324+
kernel_function();
1325+
kernel_function(kernel_functor ptr);
1326+
operator void *() const;
1327+
void operator()(sycl::queue &q, const sycl::nd_range<3> &range,
1328+
unsigned int local_mem_size, void **args, void **extra);
1329+
};
1330+
1331+
static kernel_function get_kernel_function(kernel_library &library,
1332+
const std::string &name);
1333+
static void invoke_kernel_function(kernel_function &function,
1334+
sycl::queue &queue,
1335+
sycl::range<3> group_range,
1336+
sycl::range<3> local_range,
1337+
unsigned int local_mem_size,
1338+
void **kernel_params, void **extra);
1339+
13001340
} // namespace syclcompat
13011341
```
13021342

0 commit comments

Comments
 (0)