Skip to content

Commit 15e81fa

Browse files
authored
[SYCL] Refine annotated_ptr address space based on compile-time USM kind (#11623)
Right now the annotated_ptr extension applies compile-time properties on `decorated_global_ptr` for SYCL device code. As the SYCL extension [sycl_ext_oneapi_usm_malloc_properties](https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_usm_malloc_properties.asciidoc#sycl_ext_oneapi_usm_malloc_properties) introduces compile-time property "usm_kind"(implemented in #10235 ), this PR further refines the address space of this pointer (using `decorated_device_ptr` or `decorated_host_ptr`) when 1. `usm_kind` property is specified in annotated_ptr type, and 2. both `__SYCL_DEVICE_ONLY__` and `__ENABLE_USM_ADDR_SPACE__` are turned on (i.e. requiring compiler flags "-fsycl-device-only -fsycl-targets=spir64_fpga") Other changes: - move `annotated_ptr.hpp` out from `annotated_arg` file into a separate folder - add new header file `annotated_ptr_properties.hpp` for annotated_ptr specific properties
1 parent eaf8268 commit 15e81fa

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,20 @@ __SYCL_TYPE(annotated_ptr) annotated_ptr<T, detail::properties_t<Props...>> {
177177
T, typename unpack<filtered_properties>::type>;
178178

179179
#ifdef __SYCL_DEVICE_ONLY__
180+
#ifdef __ENABLE_USM_ADDR_SPACE__
181+
using global_pointer_t = std::conditional_t<
182+
detail::IsUsmKindDevice<property_list_t>::value,
183+
typename sycl::ext::intel::decorated_device_ptr<T>::pointer,
184+
std::conditional_t<
185+
detail::IsUsmKindHost<property_list_t>::value,
186+
typename sycl::ext::intel::decorated_host_ptr<T>::pointer,
187+
typename decorated_global_ptr<T>::pointer>>;
188+
#else
180189
using global_pointer_t = typename decorated_global_ptr<T>::pointer;
190+
#endif // __ENABLE_USM_ADDR_SPACE__
181191
#else
182192
using global_pointer_t = T *;
183-
#endif
193+
#endif // __SYCL_DEVICE_ONLY__
184194

185195
global_pointer_t m_Ptr;
186196

sycl/include/sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr_properties.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ struct PropertyMetaInfo<usm_kind_key::value_t<Kind>> {
6262
static constexpr sycl::usm::alloc value = Kind;
6363
};
6464

65+
template <typename PropertyListT> struct IsUsmKindDevice : std::false_type {};
66+
template <typename... Props>
67+
struct IsUsmKindDevice<detail::properties_t<Props...>>
68+
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_device)>,
69+
std::tuple<Props...>> {};
70+
71+
template <typename PropertyListT> struct IsUsmKindHost : std::false_type {};
72+
template <typename... Props>
73+
struct IsUsmKindHost<detail::properties_t<Props...>>
74+
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_host)>,
75+
std::tuple<Props...>> {};
76+
77+
template <typename PropertyListT> struct IsUsmKindShared : std::false_type {};
78+
template <typename... Props>
79+
struct IsUsmKindShared<detail::properties_t<Props...>>
80+
: detail::ContainsProperty<std::remove_const_t<decltype(usm_kind_shared)>,
81+
std::tuple<Props...>> {};
82+
6583
} // namespace detail
6684

6785
} // namespace experimental
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: %clangxx -fsycl-device-only -fsycl-targets=spir64_fpga -S -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK-IR
2+
3+
// Tests that the address space of `annotated_ptr` kernel argument is refined
4+
// when:
5+
// 1. `usm_kind` property is specified in annotated_ptr type, and
6+
// 2. both `__SYCL_DEVICE_ONLY__` and `__ENABLE_USM_ADDR_SPACE__` are turned on
7+
// (i.e. equiv to flags "-fsycl-device-only -fsycl-targets=spir64_fpga")
8+
9+
#include "sycl/sycl.hpp"
10+
11+
#include <sycl/ext/intel/fpga_extensions.hpp>
12+
13+
#include <iostream>
14+
15+
using namespace sycl;
16+
using namespace ext::oneapi::experimental;
17+
using namespace ext::intel::experimental;
18+
19+
using annotated_ptr_t1 =
20+
annotated_ptr<int,
21+
decltype(properties(buffer_location<0>, usm_kind_device))>;
22+
using annotated_ptr_t2 =
23+
annotated_ptr<int, decltype(properties(buffer_location<1>, usm_kind_host))>;
24+
using annotated_ptr_t3 =
25+
annotated_ptr<int,
26+
decltype(properties(buffer_location<2>, usm_kind_shared))>;
27+
28+
struct MyIP {
29+
30+
// CHECK-IR: spir_kernel void @_ZTS4MyIP(ptr addrspace(5) {{.*}} %_arg_a, ptr addrspace(6) {{.*}} %_arg_b, ptr addrspace(1) {{.*}} %_arg_c)
31+
annotated_ptr_t1 a;
32+
annotated_ptr_t2 b;
33+
annotated_ptr_t3 c;
34+
35+
MyIP(int *a_, int *b_, int *c_) : a(a_), b(b_), c(c_) {}
36+
37+
void operator()() const { *a = *b + *c; }
38+
};
39+
40+
void TestVectorAddWithAnnotatedMMHosts() {
41+
queue q;
42+
auto p1 = malloc_device<int>(5, q);
43+
auto p2 = malloc_host<int>(5, q);
44+
auto p3 = malloc_shared<int>(5, q);
45+
46+
q.submit([&](handler &h) { h.single_task(MyIP{p1, p2, p3}); }).wait();
47+
48+
free(p1, q);
49+
free(p2, q);
50+
free(p3, q);
51+
}
52+
53+
int main() {
54+
TestVectorAddWithAnnotatedMMHosts();
55+
return 0;
56+
}

0 commit comments

Comments
 (0)