Skip to content

Commit 046824f

Browse files
committed
[SYCL] Decouple builtins from vec::convert
Stop pulling vec::convert in through SYCL builtin headers by using a local relational mask widening path and a public sycl/vector_convert.hpp wrapper for opt-in conversion support. This reduces header dependencies and improves compile time by about 9.3% for host compilation and 7.5% for device compilation on playground/measure_builtin.cpp.
1 parent 2c5fd43 commit 046824f

22 files changed

Lines changed: 109 additions & 46 deletions

sycl/include/sycl/detail/builtins/builtins.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#include <sycl/detail/helpers.hpp>
6868
#include <sycl/detail/type_traits.hpp>
6969
#include <sycl/detail/type_traits/vec_marray_traits.hpp>
70-
#include <sycl/detail/vector_convert.hpp>
70+
#include <sycl/half_type.hpp>
7171
#include <sycl/marray.hpp>
7272
#include <sycl/vector.hpp>
7373

@@ -203,6 +203,28 @@ template <class T, int N> marray<T, N> to_marray(vec<T, N> X) {
203203
return Marray;
204204
}
205205

206+
// Relation builtins widen signed-char masks to the required integer element
207+
// type. Keep that conversion local here so builtins.hpp does not need to pull
208+
// in vector_convert.hpp just for vec::convert.
209+
template <typename NewElemT, int N>
210+
vec<NewElemT, N> relational_mask_widen(vec<signed char, N> X) {
211+
static_assert(is_scalar_arithmetic_v<NewElemT>);
212+
213+
#ifdef __SYCL_DEVICE_ONLY__
214+
if constexpr (N > 1) {
215+
using src_vector_t = signed char __attribute__((ext_vector_type(N)));
216+
using dst_vector_t = NewElemT __attribute__((ext_vector_type(N)));
217+
auto OpenCLVec = bit_cast<src_vector_t>(X);
218+
return bit_cast<vec<NewElemT, N>>(
219+
__builtin_convertvector(OpenCLVec, dst_vector_t));
220+
}
221+
#endif
222+
223+
vec<NewElemT, N> Result{};
224+
loop<N>([&](auto idx) { Result[idx] = static_cast<NewElemT>(X[idx]); });
225+
return Result;
226+
}
227+
206228
namespace builtins {
207229
#ifdef __SYCL_DEVICE_ONLY__
208230
template <typename T> auto convert_arg(T &&x) {

sycl/include/sycl/detail/builtins/relational_functions.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ auto builtin_device_rel_impl(FuncTy F, const Ts &...xs) {
6666
auto tmp = bit_cast<vec<signed char, num_elements<T>::value>>(ret);
6767
using res_elem_type = fixed_width_signed<sizeof(get_elem_type_t<T>)>;
6868
static_assert(is_scalar_arithmetic_v<res_elem_type>);
69-
return tmp.template convert<res_elem_type>();
69+
return relational_mask_widen<res_elem_type>(tmp);
7070
} else if constexpr (std::is_same_v<T, half>) {
7171
return bool{F(builtins::convert_arg(xs)...)};
7272
} else {

sycl/include/sycl/detail/image_accessor_util.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <sycl/image.hpp> // for image_channel_type
2424
#include <sycl/range.hpp> // for range
2525
#include <sycl/sampler.hpp> // for addressing_mode, coor...
26-
#include <sycl/vector.hpp> // for vec, operator*, round...
26+
#include <sycl/vector_convert.hpp> // for vec, vec::convert, operator*, round...
2727

2828
#include <cstdint> // for int32_t, uint16_t
2929
#include <stddef.h> // for size_t

sycl/include/sycl/ext/oneapi/bf16_storage_builtins.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sycl/detail/builtins/builtins.hpp>
1414
#include <sycl/detail/generic_type_traits.hpp>
1515
#include <sycl/detail/type_traits.hpp>
16+
#include <sycl/exception.hpp>
1617

1718
namespace sycl {
1819
inline namespace _V1 {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <sycl/bit_cast.hpp> // for sycl::bit_cast
1313
#include <sycl/builtins.hpp> // for ceil, cos, exp, exp10, exp2
1414
#include <sycl/detail/memcpy.hpp> // sycl::detail::memcpy
15-
#include <sycl/detail/vector_convert.hpp>
1615
#include <sycl/ext/oneapi/bfloat16.hpp> // for bfloat16
1716
#include <sycl/marray.hpp> // for marray
17+
#include <sycl/vector_convert.hpp>
1818

1919
#include <cstring> // for size_t
2020
#include <stdint.h> // for uint32_t

sycl/include/sycl/sycl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ can be disabled by setting SYCL_DISABLE_FSYCL_SYCLHPP_WARNING macro.")
5252
#include <sycl/builtins.hpp>
5353
#include <sycl/context.hpp>
5454
#include <sycl/define_vendors.hpp>
55-
#include <sycl/detail/vector_convert.hpp>
5655
#include <sycl/device.hpp>
5756
#include <sycl/device_aspect_traits.hpp>
5857
#include <sycl/device_selector.hpp>
@@ -87,6 +86,7 @@ can be disabled by setting SYCL_DISABLE_FSYCL_SYCLHPP_WARNING macro.")
8786
#include <sycl/usm/usm_allocator.hpp>
8887
#include <sycl/usm/usm_pointer_info.hpp>
8988
#include <sycl/vector.hpp>
89+
#include <sycl/vector_convert.hpp>
9090
#include <sycl/version.hpp>
9191

9292
#include <sycl/ext/intel/experimental/fp_control_kernel_properties.hpp>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//==-------------- vector_convert.hpp - vec::convert API ------------------==//
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+
#pragma once
10+
11+
#include <sycl/detail/vector_convert.hpp>

sycl/source/detail/image_accessor_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <sycl/accessor.hpp>
1010
#include <sycl/accessor_image.hpp>
1111
#include <sycl/builtins.hpp>
12-
#include <sycl/detail/vector_convert.hpp>
1312
#include <sycl/image.hpp>
13+
#include <sycl/vector_convert.hpp>
1414

1515
namespace sycl {
1616
inline namespace _V1 {

sycl/test-e2e/BFloat16/bfloat16_vec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// RUN: %{run} %t2.out
1313

1414
#include <sycl/detail/core.hpp>
15-
#include <sycl/detail/vector_convert.hpp>
1615
#include <sycl/stream.hpp>
16+
#include <sycl/vector_convert.hpp>
1717

1818
#include <sycl/ext/oneapi/bfloat16.hpp>
1919

sycl/test-e2e/Basic/char_builtins.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <array>
55
#include <sycl/builtins.hpp>
66
#include <sycl/detail/core.hpp>
7+
#include <sycl/vector_convert.hpp>
78

89
using namespace sycl;
910

0 commit comments

Comments
 (0)