-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Don't include <complex> from <sycl/sycl.hpp> #11196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7e5f95
[SYCL] Don't include <complex> from <sycl/sycl.hpp>
aelovikov-intel 3c8d1e9
clang-format
aelovikov-intel d6e66a7
Add a test
aelovikov-intel db67e53
Adjust driver test
aelovikov-intel f26062d
Address code review comments
aelovikov-intel acca082
License header + top file comment
aelovikov-intel ff17b18
Merge remote-tracking branch 'origin/sycl' into HEAD
aelovikov-intel 4d6721f
Try to fix failure on CUDA
aelovikov-intel 4c9f607
Merge remote-tracking branch 'origin/sycl' into HEAD
aelovikov-intel 8ba2b51
Merge remote-tracking branch 'origin/sycl' into HEAD
aelovikov-intel bde036b
Support -fsycl-host-compiler=g++
aelovikov-intel cd5d586
Implement workaround on Win
aelovikov-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -622,8 +622,18 @@ | |
// Verify header search dirs are added with -fsycl | ||
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck %s -check-prefixes=CHECK-HEADER-DIR | ||
// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck %s -check-prefixes=CHECK-HEADER-DIR | ||
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-device"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include" | ||
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-host"{{.*}} "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" "-internal-isystem" "{{.*}}bin{{[/\\]+}}..{{[/\\]+}}include"{{.*}} | ||
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-device" | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT:[^"]*]]bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" | ||
// CHECK-HEADER-DIR-NOT: -internal-isystem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous version didn't catch cases where we had extra includes between the ones we match (due to |
||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT]]bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers" | ||
// CHECK-HEADER-DIR-NOT: -internal-isystem | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT]]bin{{[/\\]+}}..{{[/\\]+}}include" | ||
// CHECK-HEADER-DIR: clang{{.*}} "-fsycl-is-host" | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT]]bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl" | ||
// CHECK-HEADER-DIR-NOT: -internal-isystem | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT]]bin{{[/\\]+}}..{{[/\\]+}}include{{[/\\]+}}sycl{{[/\\]+}}stl_wrappers" | ||
// CHECK-HEADER-DIR-NOT: -internal-isystem | ||
// CHECK-HEADER-DIR-SAME: "-internal-isystem" "[[ROOT]]bin{{[/\\]+}}..{{[/\\]+}}include" | ||
|
||
/// Check for option incompatibility with -fsycl | ||
// RUN: not %clang -### -fsycl -ffreestanding %s 2>&1 \ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
//==---------------- <complex> wrapper around STL --------------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// STL's <complex> includes <cmath> which, in turn, pollutes global namespace. | ||
// As such, we cannot include <complex> from SYCL headers unconditionally and | ||
// have to provide support for std::complex only when the customer included | ||
// <complex> explicitly. Do that by providing our own <complex> that is | ||
// implemented as a wrapper around the STL header using "#include_next" | ||
// functionality. | ||
|
||
#pragma once | ||
|
||
// Include real STL <complex> header - the next one from the include search | ||
// directories. | ||
#if defined(__has_include_next) | ||
// GCC/clang support go through this path. | ||
#include_next <complex> | ||
aelovikov-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#else | ||
// MSVC doesn't support "#include_next", so we have to be creative. | ||
// Our header is located in "stl_wrappers/complex" so it won't be picked by the | ||
// following include. MSVC's installation, on the other hand, has the layout | ||
// where the following would result in the <complex> we want. This is obviously | ||
// hacky, but the best we can do... | ||
#include <../include/complex> | ||
#endif | ||
|
||
// Now that we have std::complex available, implement SYCL functionality related | ||
// to it. | ||
|
||
#include <type_traits> | ||
|
||
#include <CL/__spirv/spirv_ops.hpp> // for __SYCL_CONVERGENT__ | ||
#include <sycl/half_type.hpp> // for half | ||
|
||
// We provide std::complex specializations here for the following: | ||
// select_cl_scalar_complex_or_T: | ||
#include <sycl/detail/generic_type_traits.hpp> | ||
// sycl::detail::GroupOpTag: | ||
#include <sycl/ext/oneapi/functional.hpp> | ||
// sycl::detail::is_complex: | ||
#include <sycl/group_algorithm.hpp> | ||
// sycl::detail::isComplex | ||
#include <sycl/known_identity.hpp> | ||
|
||
namespace __spv { | ||
struct complex_float { | ||
complex_float() = default; | ||
complex_float(std::complex<float> x) : real(x.real()), imag(x.imag()) {} | ||
operator std::complex<float>() { return {real, imag}; } | ||
float real, imag; | ||
}; | ||
|
||
struct complex_double { | ||
complex_double() = default; | ||
complex_double(std::complex<double> x) : real(x.real()), imag(x.imag()) {} | ||
operator std::complex<double>() { return {real, imag}; } | ||
double real, imag; | ||
}; | ||
|
||
struct complex_half { | ||
complex_half() = default; | ||
complex_half(std::complex<sycl::half> x) : real(x.real()), imag(x.imag()) {} | ||
operator std::complex<sycl::half>() { return {real, imag}; } | ||
sycl::half real, imag; | ||
}; | ||
} // namespace __spv | ||
|
||
__SYCL_CONVERGENT__ extern __DPCPP_SYCL_EXTERNAL | ||
__SYCL_EXPORT __spv::complex_half | ||
__spirv_GroupCMulINTEL(unsigned int, unsigned int, | ||
__spv::complex_half) noexcept; | ||
__SYCL_CONVERGENT__ extern __DPCPP_SYCL_EXTERNAL | ||
__SYCL_EXPORT __spv::complex_float | ||
__spirv_GroupCMulINTEL(unsigned int, unsigned int, | ||
__spv::complex_float) noexcept; | ||
__SYCL_CONVERGENT__ extern __DPCPP_SYCL_EXTERNAL | ||
__SYCL_EXPORT __spv::complex_double | ||
__spirv_GroupCMulINTEL(unsigned int, unsigned int, | ||
__spv::complex_double) noexcept; | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace detail { | ||
template <typename T> | ||
struct isComplex<T, std::enable_if_t<std::is_same_v<T, std::complex<float>> || | ||
std::is_same_v<T, std::complex<double>>>> | ||
: public std::true_type {}; | ||
|
||
// NOTE: std::complex<long double> not yet supported by group algorithms. | ||
template <typename T> | ||
struct is_complex<T, std::enable_if_t<std::is_same_v<T, std::complex<half>> || | ||
std::is_same_v<T, std::complex<float>> || | ||
std::is_same_v<T, std::complex<double>>>> | ||
: public std::true_type {}; | ||
|
||
#ifdef __SYCL_DEVICE_ONLY__ | ||
template <typename T> | ||
struct GroupOpTag< | ||
T, std::enable_if_t<std::is_same<T, std::complex<half>>::value || | ||
std::is_same<T, std::complex<float>>::value || | ||
std::is_same<T, std::complex<double>>::value>> { | ||
using type = GroupOpC; | ||
}; | ||
#endif | ||
|
||
template <typename T> | ||
struct select_cl_scalar_complex_or_T<T, | ||
std::enable_if_t<is_complex<T>::value>> { | ||
using type = std::conditional_t< | ||
std::is_same_v<T, std::complex<float>>, __spv::complex_float, | ||
std::conditional_t<std::is_same_v<T, std::complex<double>>, | ||
__spv::complex_double, __spv::complex_half>>; | ||
}; | ||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.