Skip to content

Commit 865092f

Browse files
authored
[SYCL] Refine annotated_arg addrspace with USM kind property (#12211)
Apply #11623 to `annotated_arg` class
1 parent 9c504a5 commit 865092f

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,22 @@ __SYCL_TYPE(annotated_arg) annotated_arg<T *, detail::properties_t<Props...>> {
7070

7171
template <typename T2, typename PropertyListT> friend class annotated_arg;
7272

73+
#ifdef __ENABLE_USM_ADDR_SPACE__
74+
using global_pointer_t = std::conditional_t<
75+
detail::IsUsmKindDevice<property_list_t>::value,
76+
typename sycl::ext::intel::decorated_device_ptr<T>::pointer,
77+
std::conditional_t<
78+
detail::IsUsmKindHost<property_list_t>::value,
79+
typename sycl::ext::intel::decorated_host_ptr<T>::pointer,
80+
typename decorated_global_ptr<T>::pointer>>;
81+
#else // __ENABLE_USM_ADDR_SPACE__
82+
using global_pointer_t = typename decorated_global_ptr<T>::pointer;
83+
#endif // __ENABLE_USM_ADDR_SPACE__
84+
7385
#ifdef __SYCL_DEVICE_ONLY__
7486
void __init([[__sycl_detail__::add_ir_attributes_kernel_parameter(
7587
detail::PropertyMetaInfo<Props>::name...,
76-
detail::PropertyMetaInfo<Props>::value...)]]
77-
typename decorated_global_ptr<T>::pointer _obj) {
88+
detail::PropertyMetaInfo<Props>::value...)]] global_pointer_t _obj) {
7889
obj = _obj;
7990
}
8091
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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_arg` kernel argument is refined
4+
// when:
5+
// 1. `usm_kind` property is specified in annotated_arg 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_arg_t1 =
20+
annotated_arg<int *,
21+
decltype(properties(buffer_location<0>, usm_kind_device))>;
22+
using annotated_arg_t2 =
23+
annotated_arg<int *,
24+
decltype(properties(buffer_location<1>, usm_kind_host))>;
25+
using annotated_arg_t3 =
26+
annotated_arg<int *,
27+
decltype(properties(buffer_location<2>, usm_kind_shared))>;
28+
29+
struct MyIP {
30+
31+
// CHECK-IR: spir_kernel void @_ZTS4MyIP(ptr addrspace(5) {{.*}} %_arg_a, ptr addrspace(6) {{.*}} %_arg_b, ptr addrspace(1) {{.*}} %_arg_c)
32+
annotated_arg_t1 a;
33+
annotated_arg_t2 b;
34+
annotated_arg_t3 c;
35+
36+
void operator()() const { *a = *b + *c; }
37+
};
38+
39+
void TestVectorAddWithAnnotatedMMHosts() {
40+
queue q;
41+
auto p1 = malloc_device<int>(5, q);
42+
auto p2 = malloc_host<int>(5, q);
43+
auto p3 = malloc_shared<int>(5, q);
44+
45+
q.submit([&](handler &h) { h.single_task(MyIP{p1, p2, p3}); }).wait();
46+
47+
free(p1, q);
48+
free(p2, q);
49+
free(p3, q);
50+
}
51+
52+
int main() {
53+
TestVectorAddWithAnnotatedMMHosts();
54+
return 0;
55+
}

0 commit comments

Comments
 (0)