okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ad33b8074
main
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 45return ::dpct::get_default_queue (); 46#else 47return * ::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 , 55memcpy_direction direction = memcpy_direction::automatic , 56const std::vector < sycl::event > & dep_events = {}) { 57#if USE_DPCT_HELPER 58return ::dpct::detail:: dpct_memcpy ( q , to_ptr , from_ptr , size , direction , 59dep_events ); 60#else 61return ::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 , 67size_t from_pitch , size_t x , size_t y , 68memcpy_direction direction = memcpy_direction:: automatic , 69const std::vector < sycl::event > & dep_events = {}) { 70#if USE_DPCT_HELPER 71return ::dpct::detail:: dpct_memcpy ( 72q , to_ptr , from_ptr , sycl:: range < 3 > ( to_pitch , y , 1 ), 73sycl:: range < 3 > ( from_pitch , y , 1 ), sycl:: id < 3 > ( 0 , 0 , 0 ), 74sycl:: id < 3 > ( 0 , 0 , 0 ), sycl:: range < 3 > ( x , y , 1 ), direction , dep_events ); 75#else 76return ::syclcompat::detail:: memcpy ( 77q , to_ptr , from_ptr , sycl:: range < 3 > ( to_pitch , y , 1 ), 78sycl:: range < 3 > ( from_pitch , y , 1 ), sycl:: id < 3 > ( 0 , 0 , 0 ), 79sycl:: 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 85return ::dpct:: dpct_malloc ( size , q ); 86#else 87return ::syclcompat:: malloc ( size , q ); 88#endif 89} 90 91template < typename valueT > 92inline sycl::event fill (sycl::queue & q , void * dev_ptr , valueT value , 93size_t size ) { 94#if USE_DPCT_HELPER 95return ::dpct::detail:: dpct_memset < valueT > ( q , dev_ptr , value , size ); 96#else 97return ::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 103return ::dpct::detail:: dpct_free ( to_ptr , q ); 104#else 105return ::syclcompat:: free ( to_ptr , q ); 106#endif 107} 108 109inline sycl::event enqueue_free ( const std::vector < void *> & pointers , 110const std::vector < sycl::event > & events , 111sycl::queue q = get_default_queue ()) { 112#if USE_DPCT_HELPER 113return ::dpct::detail:: async_dpct_free ( pointers , events , q ); 114#else 115return ::syclcompat:: enqueue_free ( pointers , events , q ); 116#endif 117} 118 119} // namespace cs 120} // namespace dpct 121 122#endif // __DPCT_COMPAT_SERVICE_HPP__