okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-139b-arc' into f-139-relad33b8074

main
4.0 KiB122 linesraw
1//==---- compat_service.hpp -----------------------*- C++ -*----------------==//
2//
3// Copyright (C) Intel Corporation
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5// See https://llvm.org/LICENSE.txt for license information.
6//
7//===----------------------------------------------------------------------===//
8// This file contains some compatibility service APIs which are used by all
9// library utility helper functions. The compatibility service APIs are based on
10// either dpct implementation or syclcompat implementation, which is controlled
11// by the macro USE_DPCT_HELPER.
12//===----------------------------------------------------------------------===//
13
14#ifndef __DPCT_COMPAT_SERVICE_HPP__
15#define __DPCT_COMPAT_SERVICE_HPP__
16
17namespace dpct {
18namespace cs {
19#if USE_DPCT_HELPER
20namespace ns = ::dpct;
21using memcpy_direction = ::dpct::memcpy_direction;
22template <class... Args> using kernel_name = dpct_kernel_name<Args...>;
23using byte_t = ::dpct::byte_t;
24#else
25namespace ns = ::syclcompat;
26using memcpy_direction = ::syclcompat::detail::memcpy_direction;
27template <class... Args> using kernel_name = syclcompat_kernel_name<Args...>;
28#ifndef __dpct_inline__
29#define __dpct_inline__ __syclcompat_inline__
30#endif
31using byte_t = ::syclcompat::byte_t;
32#endif
33
34using ns::get_current_device;
35using ns::get_default_context;
36using ns::queue_ptr;
37
38namespace detail {
39using ns::detail::get_pointer_attribute;
40using ns::detail::pointer_access_attribute;
41} // namespace detail
42
43inline sycl::queue &get_default_queue() {
44#if USE_DPCT_HELPER
45  return ::dpct::get_default_queue();
46#else
47  return *::syclcompat::detail::dev_mgr::instance()
48              .current_device()
49              .default_queue();
50#endif
51}
52
53inline sycl::event
54memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t size,
55       memcpy_direction direction = memcpy_direction::automatic,
56       const std::vector<sycl::event> &dep_events = {}) {
57#if USE_DPCT_HELPER
58  return ::dpct::detail::dpct_memcpy(q, to_ptr, from_ptr, size, direction,
59                                     dep_events);
60#else
61  return ::syclcompat::detail::memcpy(q, to_ptr, from_ptr, size, dep_events);
62#endif
63}
64
65inline std::vector<sycl::event>
66memcpy(sycl::queue &q, void *to_ptr, const void *from_ptr, size_t to_pitch,
67       size_t from_pitch, size_t x, size_t y,
68       memcpy_direction direction = memcpy_direction::automatic,
69       const std::vector<sycl::event> &dep_events = {}) {
70#if USE_DPCT_HELPER
71  return ::dpct::detail::dpct_memcpy(
72      q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
73      sycl::range<3>(from_pitch, y, 1), sycl::id<3>(0, 0, 0),
74      sycl::id<3>(0, 0, 0), sycl::range<3>(x, y, 1), direction, dep_events);
75#else
76  return ::syclcompat::detail::memcpy(
77      q, to_ptr, from_ptr, sycl::range<3>(to_pitch, y, 1),
78      sycl::range<3>(from_pitch, y, 1), sycl::id<3>(0, 0, 0),
79      sycl::id<3>(0, 0, 0), sycl::range<3>(x, y, 1), dep_events);
80#endif
81}
82
83inline void *malloc(size_t size, sycl::queue q = get_default_queue()) {
84#if USE_DPCT_HELPER
85  return ::dpct::dpct_malloc(size, q);
86#else
87  return ::syclcompat::malloc(size, q);
88#endif
89}
90
91template <typename valueT>
92inline sycl::event fill(sycl::queue &q, void *dev_ptr, valueT value,
93                        size_t size) {
94#if USE_DPCT_HELPER
95  return ::dpct::detail::dpct_memset<valueT>(q, dev_ptr, value, size);
96#else
97  return ::syclcompat::detail::fill<valueT>(q, dev_ptr, value, size);
98#endif
99}
100
101inline void free(void *to_ptr, sycl::queue q) {
102#if USE_DPCT_HELPER
103  return ::dpct::detail::dpct_free(to_ptr, q);
104#else
105  return ::syclcompat::free(to_ptr, q);
106#endif
107}
108
109inline sycl::event enqueue_free(const std::vector<void *> &pointers,
110                                const std::vector<sycl::event> &events,
111                                sycl::queue q = get_default_queue()) {
112#if USE_DPCT_HELPER
113  return ::dpct::detail::async_dpct_free(pointers, events, q);
114#else
115  return ::syclcompat::enqueue_free(pointers, events, q);
116#endif
117}
118
119} // namespace cs
120} // namespace dpct
121
122#endif // __DPCT_COMPAT_SERVICE_HPP__