|
| 1 | +// RUN: %{build} -o %t.out |
| 2 | +// RUN: %if hip %{ env SYCL_JIT_AMDGCN_PTX_TARGET_CPU=%{amd_arch} %} %{l0_leak_check} %{run} %t.out |
| 3 | + |
| 4 | +// XFAIL: target-native_cpu |
| 5 | +// XFAIL-TRACKER: https://github.com/intel/llvm/issues/20142 |
| 6 | + |
| 7 | +#include <sycl/detail/core.hpp> |
| 8 | +#include <sycl/kernel_bundle.hpp> |
| 9 | +#include <sycl/usm.hpp> |
| 10 | + |
| 11 | +#include <chrono> |
| 12 | +#include <thread> |
| 13 | + |
| 14 | +namespace syclexp = sycl::ext::oneapi::experimental; |
| 15 | + |
| 16 | +static constexpr size_t NUM = 1024; |
| 17 | +static constexpr size_t WGSIZE = 16; |
| 18 | + |
| 19 | +int main() { |
| 20 | + sycl::queue q; |
| 21 | + |
| 22 | + std::string source = R"""( |
| 23 | +#define MACRO_TIME __TIME__ |
| 24 | +#include "a.hpp" |
| 25 | +#include <cstring> |
| 26 | +#include <sycl/ext/oneapi/free_function_queries.hpp> |
| 27 | +#include <sycl/ext/oneapi/kernel_properties/properties.hpp> |
| 28 | +namespace syclext = sycl::ext::oneapi; |
| 29 | +namespace syclexp = sycl::ext::oneapi::experimental; |
| 30 | +
|
| 31 | +extern "C" |
| 32 | +SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) |
| 33 | +void foo(char *macro_time, char *var_time) { |
| 34 | + std::strcpy(macro_time, MACRO_TIME); |
| 35 | + std::strcpy(var_time, VAR_TIME); |
| 36 | +} |
| 37 | +)"""; |
| 38 | + |
| 39 | + auto kb_src = syclexp::create_kernel_bundle_from_source( |
| 40 | + q.get_context(), syclexp::source_language::sycl, source, |
| 41 | + syclexp::properties{syclexp::include_files{ |
| 42 | + "a.hpp", "const char * VAR_TIME = MACRO_TIME;"}}); |
| 43 | + |
| 44 | + auto props = syclexp::properties{ |
| 45 | + syclexp::build_options{std::vector<std::string>{"--auto-pch"}}}; |
| 46 | + |
| 47 | + size_t len = std::strlen("hh:mm:ss") + 1; |
| 48 | + char *macro_time = sycl::malloc_shared<char>(len, q); |
| 49 | + char *var_time = sycl::malloc_shared<char>(len, q); |
| 50 | + |
| 51 | + auto Run = [&](auto Prefix) { |
| 52 | + auto krn = syclexp::build(kb_src, props).ext_oneapi_get_kernel("foo"); |
| 53 | + q.submit([&](sycl::handler &cgh) { |
| 54 | + cgh.set_args(macro_time, var_time); |
| 55 | + |
| 56 | + cgh.single_task(krn); |
| 57 | + }).wait(); |
| 58 | + |
| 59 | + return std::pair{std::string{macro_time}, std::string{var_time}}; |
| 60 | + }; |
| 61 | + |
| 62 | + auto [gen_macro, gen_var] = Run("Gen"); |
| 63 | + using namespace std::chrono_literals; |
| 64 | + std::this_thread::sleep_for(2s); |
| 65 | + auto [use_macro, use_var] = Run("Use"); |
| 66 | + |
| 67 | + // If "captured" into a variable, the time is frozen at the moment auto-pch is |
| 68 | + // generated: |
| 69 | + assert(gen_var == use_var); |
| 70 | + |
| 71 | + // If it's just a `#define <..> __TIME__`, and is only "used" outside the |
| 72 | + // preamble, then the time matches the compilation (auto-pch use): |
| 73 | + assert(gen_macro != use_macro); |
| 74 | + |
| 75 | + sycl::free(macro_time, q); |
| 76 | + sycl::free(var_time, q); |
| 77 | +} |
0 commit comments