Skip to content

Commit 82d874f

Browse files
authored
[SYCL] Add (raw|decorated)_generic_ptr aliases (#15389)
KhronosGroup/SYCL-Docs#598 adds these aliases to the spec. Prepare for spec change by adding them to the implementation beforehand. Extend tests so all `multi_ptr` aliases are checked. --------- Signed-off-by: Victor Perez <victor.perez@codeplay.com>
1 parent c0cb28e commit 82d874f

File tree

3 files changed

+97
-6
lines changed

3 files changed

+97
-6
lines changed

sycl/include/sycl/pointers.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ using private_ptr =
4747
// The interface exposes non-decorated pointer while keeping the
4848
// address space information internally.
4949

50+
template <typename ElementType>
51+
using raw_generic_ptr =
52+
multi_ptr<ElementType, access::address_space::generic_space,
53+
access::decorated::no>;
54+
5055
template <typename ElementType>
5156
using raw_global_ptr =
5257
multi_ptr<ElementType, access::address_space::global_space,
@@ -64,6 +69,11 @@ using raw_private_ptr =
6469
// Template specialization aliases for different pointer address spaces.
6570
// The interface exposes decorated pointer.
6671

72+
template <typename ElementType>
73+
using decorated_generic_ptr =
74+
multi_ptr<ElementType, access::address_space::generic_space,
75+
access::decorated::yes>;
76+
6777
template <typename ElementType>
6878
using decorated_global_ptr =
6979
multi_ptr<ElementType, access::address_space::global_space,

sycl/test/check_device_code/extensions/address_cast.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
using namespace sycl;
1212
using namespace sycl::ext::oneapi::experimental;
1313

14-
// FIXME: should be removed when https://github.com/intel/llvm/pull/15389 is merged in.
15-
template <typename ElementType>
16-
using decorated_generic_ptr =
17-
multi_ptr<ElementType, access::address_space::generic_space,
18-
access::decorated::yes>;
19-
2014
namespace static_as_cast {
2115
// CHECK-LABEL: define dso_local spir_func void @_ZN14static_as_cast19to_global_decoratedEN4sycl3_V19multi_ptrIiLNS1_6access13address_spaceE6ELNS3_9decoratedE1EEE(
2216
// CHECK-SAME: ptr addrspace(4) dead_on_unwind noalias nocapture writable writeonly sret(%"class.sycl::_V1::multi_ptr") align 8 [[AGG_RESULT:%.*]], ptr nocapture noundef readonly byval(%"class.sycl::_V1::multi_ptr.0") align 8 [[P:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !srcloc [[META6:![0-9]+]] !sycl_fixed_targets [[META7:![0-9]+]] {

sycl/test/multi_ptr/aliases.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//==--------------- aliases.cpp - SYCL multi_ptr aliases test --------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
10+
11+
// expected-no-diagnostics
12+
13+
#include <sycl/detail/core.hpp>
14+
15+
#include <type_traits>
16+
17+
template <typename T, sycl::access::decorated IsDecorated>
18+
void test_address_space_aliases() {
19+
static_assert(std::is_same_v<
20+
sycl::generic_ptr<T, IsDecorated>,
21+
sycl::multi_ptr<T, sycl::access::address_space::generic_space,
22+
IsDecorated>>);
23+
static_assert(std::is_same_v<
24+
sycl::global_ptr<T, IsDecorated>,
25+
sycl::multi_ptr<T, sycl::access ::address_space::global_space,
26+
IsDecorated>>);
27+
static_assert(std::is_same_v<
28+
sycl::local_ptr<T, IsDecorated>,
29+
sycl::multi_ptr<T, sycl::access::address_space::local_space,
30+
IsDecorated>>);
31+
static_assert(std::is_same_v<
32+
sycl::private_ptr<T, IsDecorated>,
33+
sycl::multi_ptr<T, sycl::access::address_space::private_space,
34+
IsDecorated>>);
35+
}
36+
37+
template <typename T> void test_aliases() {
38+
// Template specialization aliases for different pointer address spaces
39+
test_address_space_aliases<T, sycl::access::decorated::yes>();
40+
test_address_space_aliases<T, sycl::access::decorated::no>();
41+
test_address_space_aliases<T, sycl::access::decorated::legacy>();
42+
43+
// Template specialization aliases for different pointer address spaces.
44+
// The interface exposes non-decorated pointer while keeping the
45+
// address space information internally.
46+
static_assert(std::is_same_v<
47+
sycl::raw_generic_ptr<T>,
48+
sycl::multi_ptr<T, sycl::access::address_space::generic_space,
49+
sycl::access::decorated::no>>);
50+
static_assert(std::is_same_v<
51+
sycl::raw_global_ptr<T>,
52+
sycl::multi_ptr<T, sycl::access::address_space::global_space,
53+
sycl::access::decorated::no>>);
54+
static_assert(std::is_same_v<
55+
sycl::raw_local_ptr<T>,
56+
sycl::multi_ptr<T, sycl::access::address_space::local_space,
57+
sycl::access::decorated::no>>);
58+
static_assert(std::is_same_v<
59+
sycl::raw_private_ptr<T>,
60+
sycl::multi_ptr<T, sycl::access::address_space::private_space,
61+
sycl::access::decorated::no>>);
62+
63+
// Template specialization aliases for different pointer address spaces.
64+
// The interface exposes decorated pointer.
65+
static_assert(std::is_same_v<
66+
sycl::decorated_generic_ptr<T>,
67+
sycl::multi_ptr<T, sycl::access::address_space::generic_space,
68+
sycl::access::decorated::yes>>);
69+
static_assert(std::is_same_v<
70+
sycl::decorated_global_ptr<T>,
71+
sycl::multi_ptr<T, sycl::access::address_space::global_space,
72+
sycl::access::decorated::yes>>);
73+
static_assert(std::is_same_v<
74+
sycl::decorated_local_ptr<T>,
75+
sycl::multi_ptr<T, sycl::access::address_space::local_space,
76+
sycl::access::decorated::yes>>);
77+
static_assert(std::is_same_v<
78+
sycl::decorated_private_ptr<T>,
79+
sycl::multi_ptr<T, sycl::access::address_space::private_space,
80+
sycl::access::decorated::yes>>);
81+
}
82+
83+
// Test "minimal set of types" in the CTS. As we are just testing aliases are
84+
// present in this test, this should work for any type.
85+
86+
template void test_aliases<int>();
87+
template void test_aliases<float>();

0 commit comments

Comments
 (0)