@@ -105,6 +105,35 @@ void vec_add(T* in1, T* in2, T* out){
105105}
106106)===" ;
107107
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+
108137auto constexpr BadSource = R"===(
109138#include <sycl/sycl.hpp>
110139
@@ -380,6 +409,53 @@ int test_device_code_split() {
380409 return 0 ;
381410}
382411
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+
383459int test_esimd () {
384460 namespace syclex = sycl::ext::oneapi::experimental;
385461 using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
@@ -540,8 +616,8 @@ int main(int argc, char **) {
540616#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
541617 int optional_tests = (argc > 1 ) ? test_warning () : 0 ;
542618 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;
545621#else
546622 static_assert (false , " Kernel Compiler feature test macro undefined" );
547623#endif
0 commit comments