Skip to content

Commit 799d267

Browse files
joeatoddAlcpz
andauthored
[SYCL][COMPAT] Re-add buffer (USM_LEVEL_NONE) support (#15683)
This PR enables (a subset of) the SYCLcompat memory APIs on devices which lack USM support. Defining `COMPAT_USM_LEVEL_NONE` enables this mode, in which `syclcompat` memory APIs (`malloc`, `memcpy`, `memset`, `free`, etc) operate with virtual device pointers, backed by buffers. --------- Co-authored-by: Alberto Cabrera Pérez <alberto.cabrera@intel.com>
1 parent 27ab422 commit 799d267

20 files changed

+2922
-124
lines changed

sycl/doc/syclcompat/README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ If available, the following extensions extend SYCLcompat functionality:
5959
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_max_work_group_query.md)
6060
\[Optional\]
6161

62+
### Hardware Requirements
63+
64+
Some of the functionalities provided by SYCLcompat rely on Unified Shared Memory (`aspect::usm_device_allocations`), though most of the USM-like memory APIs (malloc*, memcpy*, memset*) support hardware with only buffer/accessor support. See section [Buffer Support](#buffer-support) below.
65+
6266
## Usage
6367

6468
All functionality is available under the `syclcompat::` namespace, imported
@@ -606,14 +610,6 @@ namespace syclcompat {
606610
namespace experimental {
607611
// Forward declarations for types relating to unsupported memcpy_parameter API:
608612

609-
enum memcpy_direction {
610-
host_to_host,
611-
host_to_device,
612-
device_to_host,
613-
device_to_device,
614-
automatic
615-
};
616-
617613
#ifdef SYCL_EXT_ONEAPI_BINDLESS_IMAGES
618614
class image_mem_wrapper;
619615
#endif
@@ -632,7 +628,6 @@ struct memcpy_parameter {
632628
data_wrapper from{};
633629
data_wrapper to{};
634630
sycl::range<3> size{};
635-
syclcompat::detail::memcpy_direction direction{syclcompat::detail::memcpy_direction::automatic};
636631
};
637632

638633
/// [UNSUPPORTED] Synchronously copies 2D/3D memory data specified by \p param .
@@ -709,18 +704,16 @@ enum class memory_region {
709704

710705
using byte_t = uint8_t;
711706

712-
enum class target { device, local };
713-
714707
template <memory_region Memory, class T = byte_t> class memory_traits {
715708
public:
716709
static constexpr sycl::access::address_space asp =
717710
(Memory == memory_region::local)
718711
? sycl::access::address_space::local_space
719712
: sycl::access::address_space::global_space;
720-
static constexpr target target =
713+
static constexpr sycl::target target =
721714
(Memory == memory_region::local)
722-
? target::local
723-
: target::device;
715+
? sycl::target::local
716+
: sycl::target::device;
724717
static constexpr sycl::access_mode mode =
725718
(Memory == memory_region::constant)
726719
? sycl::access_mode::read
@@ -731,7 +724,7 @@ public:
731724
using value_t = typename std::remove_cv_t<T>;
732725
template <size_t Dimension = 1>
733726
using accessor_t = typename std::conditional_t<
734-
target == target::local,
727+
target == sycl::target::local,
735728
sycl::local_accessor<T, Dimension>,
736729
sycl::accessor<T, Dimension, mode>>;
737730
using pointer_t = T *;
@@ -855,6 +848,23 @@ public:
855848
} // syclcompat
856849
```
857850
851+
#### Buffer Support
852+
853+
Although SYCLcompat is primarily designed around the Unified Shared Memory
854+
model, there is (limited) support for the buffer/accessor model. This can be
855+
enabled by setting the compiler define `SYCLCOMPAT_USM_LEVEL_NONE`. This macro
856+
instructs SYCLcompat to effectively provide emulated USM pointers via a Memory
857+
Manager singleton.
858+
859+
Note that in `SYCLCOMPAT_USM_LEVEL_NONE` mode, the pointers returned by e.g.
860+
`syclcompat::malloc`, and passed to `syclcompat::memcpy` can *only* interact
861+
with `syclcompat` APIs. It is legal to perform pointer arithmetic on these
862+
virtual pointers, but attempting to dereference them, passing them to `sycl`
863+
APIs, or passing them into kernels will result in an error.
864+
865+
The SYCLcompat tests with the suffix `_usmnone.cpp` provide examples of how to
866+
use `SYCLCOMPAT_USM_LEVEL_NONE`.
867+
858868
### ptr_to_int
859869
860870
The following cuda backend specific function is introduced in order to

sycl/include/syclcompat/defs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
**************************************************************************/
2323

2424
// The original source was under the license below:
25-
//==---- dpct.hpp ---------------------------------*- C++ -*----------------==//
25+
//==---- defs.hpp ---------------------------------*- C++ -*----------------==//
2626
//
2727
// Copyright (C) Intel Corporation
2828
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

0 commit comments

Comments
 (0)