@@ -105,6 +105,35 @@ void vec_add(T* in1, T* in2, T* out){
105
105
}
106
106
)===" ;
107
107
108
+ auto constexpr DeviceLibrariesSource = R"===(
109
+ #include <sycl/sycl.hpp>
110
+ #include <cmath>
111
+ #include <complex>
112
+ #include <sycl/ext/intel/math.hpp>
113
+
114
+ extern "C" SYCL_EXTERNAL
115
+ SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(sycl::ext::oneapi::experimental::single_task_kernel)
116
+ void device_libs_kernel(float *ptr) {
117
+ // Extension list: llvm/lib/SYCLLowerIR/SYCLDeviceLibReqMask.cpp
118
+
119
+ // cl_intel_devicelib_assert is not available for opencl:gpu; skip testing it.
120
+ // Only test the fp32 variants of complex, math and imf to keep this test
121
+ // device-agnostic.
122
+
123
+ // cl_intel_devicelib_math
124
+ ptr[0] = erff(ptr[0]);
125
+
126
+ // cl_intel_devicelib_complex
127
+ ptr[1] = std::abs(std::complex<float>{1.0f, ptr[1]});
128
+
129
+ // cl_intel_devicelib_cstring
130
+ ptr[2] = memcmp(ptr + 2, ptr + 2, sizeof(float));
131
+
132
+ // cl_intel_devicelib_imf
133
+ ptr[3] = sycl::ext::intel::math::sqrt(ptr[3] * 2);
134
+ }
135
+ )===" ;
136
+
108
137
auto constexpr BadSource = R"===(
109
138
#include <sycl/sycl.hpp>
110
139
@@ -380,6 +409,53 @@ int test_device_code_split() {
380
409
return 0 ;
381
410
}
382
411
412
+ int test_device_libraries () {
413
+ namespace syclex = sycl::ext::oneapi::experimental;
414
+ using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
415
+ using exe_kb = sycl::kernel_bundle<sycl::bundle_state::executable>;
416
+
417
+ sycl::queue q;
418
+ sycl::context ctx = q.get_context ();
419
+
420
+ bool ok =
421
+ q.get_device ().ext_oneapi_can_compile (syclex::source_language::sycl_jit);
422
+ if (!ok) {
423
+ std::cout << " Apparently this device does not support `sycl_jit` source "
424
+ " kernel bundle extension: "
425
+ << q.get_device ().get_info <sycl::info::device::name>()
426
+ << std::endl;
427
+ return -1 ;
428
+ }
429
+
430
+ source_kb kbSrc = syclex::create_kernel_bundle_from_source (
431
+ ctx, syclex::source_language::sycl_jit, DeviceLibrariesSource);
432
+ exe_kb kbExe = syclex::build (kbSrc);
433
+
434
+ sycl::kernel k = kbExe.ext_oneapi_get_kernel (" device_libs_kernel" );
435
+ constexpr size_t nElem = 4 ;
436
+ float *ptr = sycl::malloc_shared<float >(nElem, q);
437
+ for (int i = 0 ; i < nElem; ++i)
438
+ ptr[i] = 1 .0f ;
439
+
440
+ q.submit ([&](sycl::handler &cgh) {
441
+ cgh.set_arg (0 , ptr);
442
+ cgh.single_task (k);
443
+ });
444
+ q.wait_and_throw ();
445
+
446
+ // Check that the kernel was executed. Given the {1.0, 1.0, 1.0, 1.0} input,
447
+ // the expected result is approximately {0.84, 1.41, 0.0, 1.41}.
448
+ for (unsigned i = 0 ; i < nElem; ++i) {
449
+ std::cout << ptr[i] << ' ' ;
450
+ assert (ptr[i] != 1 .0f );
451
+ }
452
+ std::cout << std::endl;
453
+
454
+ sycl::free (ptr, q);
455
+
456
+ return 0 ;
457
+ }
458
+
383
459
int test_esimd () {
384
460
namespace syclex = sycl::ext::oneapi::experimental;
385
461
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
@@ -540,8 +616,8 @@ int main(int argc, char **) {
540
616
#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
541
617
int optional_tests = (argc > 1 ) ? test_warning () : 0 ;
542
618
return test_build_and_run () || test_lifetimes () || test_device_code_split () ||
543
- test_esimd () || test_unsupported_options () || test_error () ||
544
- optional_tests;
619
+ test_device_libraries () || test_esimd () ||
620
+ test_unsupported_options () || test_error () || optional_tests;
545
621
#else
546
622
static_assert (false , " Kernel Compiler feature test macro undefined" );
547
623
#endif
0 commit comments