diff --git a/sycl/doc/developer/ContributeToDPCPP.md b/sycl/doc/developer/ContributeToDPCPP.md index 63b7d4f4632a3..f7471a97b5205 100644 --- a/sycl/doc/developer/ContributeToDPCPP.md +++ b/sycl/doc/developer/ContributeToDPCPP.md @@ -40,10 +40,10 @@ to signify the component changed, e.g.: `[PI]`, `[CUDA]`, `[Doc]`. According to [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden), the use `#include ` is forbidden in library files. Instead, the -sycl/detail/iostream_proxy.hpp header offers the functionality of +detail/iostream_proxy.hpp header offers the functionality of without its static constructor. -This header should be used in place of in DPC++ headers and runtime -library files. +This header should be used in place of in DPC++ runtime +library files. In DPC++ header files only should be used. ## Tests development diff --git a/sycl/include/sycl/backend_types.hpp b/sycl/include/sycl/backend_types.hpp index d1b89832064ce..a6cdb3bf0aad7 100644 --- a/sycl/include/sycl/backend_types.hpp +++ b/sycl/include/sycl/backend_types.hpp @@ -10,7 +10,8 @@ #include // for __SYCL2020_DEPRECATED -#include // for operator<<, ostream +#include // for operator<<, ostream +#include namespace sycl { inline namespace _V1 { @@ -36,34 +37,7 @@ template using backend_return_t = typename backend_traits::template return_type; -inline std::ostream &operator<<(std::ostream &Out, backend be) { - switch (be) { - case backend::host: - Out << "host"; - break; - case backend::opencl: - Out << "opencl"; - break; - case backend::ext_oneapi_level_zero: - Out << "ext_oneapi_level_zero"; - break; - case backend::ext_oneapi_cuda: - Out << "ext_oneapi_cuda"; - break; - case backend::ext_intel_esimd_emulator: - Out << "ext_intel_esimd_emulator"; - break; - case backend::ext_oneapi_hip: - Out << "ext_oneapi_hip"; - break; - case backend::ext_native_cpu: - Out << "ext_native_cpu"; - break; - case backend::all: - Out << "all"; - } - return Out; -} +__SYCL_EXPORT std::ostream &operator<<(std::ostream &Out, backend be); } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/bit_cast.hpp b/sycl/include/sycl/bit_cast.hpp index e9f92b7cf6c50..23dfef3ee82f3 100644 --- a/sycl/include/sycl/bit_cast.hpp +++ b/sycl/include/sycl/bit_cast.hpp @@ -14,9 +14,11 @@ #include // defines __cpp_lib_bit_cast #endif +#include // __has_builtin + #if __cpp_lib_bit_cast #include -#elif !defined(__has_builtin) || !__has_builtin(__builtin_bit_cast) +#elif !__has_builtin(__builtin_bit_cast) #include #endif @@ -24,8 +26,7 @@ namespace sycl { inline namespace _V1 { template -#if __cpp_lib_bit_cast || \ - (defined(__has_builtin) && __has_builtin(__builtin_bit_cast)) +#if __cpp_lib_bit_cast || __has_builtin(__builtin_bit_cast) constexpr #endif std::enable_if_t(from); #else // __cpp_lib_bit_cast -#if defined(__has_builtin) && __has_builtin(__builtin_bit_cast) +#if __has_builtin(__builtin_bit_cast) return __builtin_bit_cast(To, from); #else // __has_builtin(__builtin_bit_cast) static_assert(std::is_trivially_default_constructible::value, diff --git a/sycl/include/sycl/detail/accessor_iterator.hpp b/sycl/include/sycl/detail/accessor_iterator.hpp index 97c5385bf3624..5c993811dca23 100644 --- a/sycl/include/sycl/detail/accessor_iterator.hpp +++ b/sycl/include/sycl/detail/accessor_iterator.hpp @@ -13,8 +13,8 @@ #include // for id #include // for size_t +#include // for operator<<, ostream, ptrdiff_t #include // for random_access_iterator_tag -#include // for operator<<, ostream, ptrdiff_t /// \file accessor_iterator.hpp /// The file contains implementation of accessor iterator class. @@ -45,6 +45,10 @@ class accessor; namespace detail { +struct accessor_iterator_data; +__SYCL_EXPORT std::ostream &operator<<(std::ostream &os, + const accessor_iterator_data &it); + template class accessor_iterator { public: using difference_type = std::ptrdiff_t; @@ -331,22 +335,30 @@ template class accessor_iterator { #ifndef NDEBUG // Could be useful for debugging, but not a part of the official API, // therefore only available in builds with assertions enabled. + friend struct accessor_iterator_data; friend std::ostream &operator<<(std::ostream &os, const accessor_iterator &it) { - os << "accessor_iterator {\n"; - os << "\tMLinearId: " << it.MLinearId << "\n"; - os << "\tMEnd: " << it.MEnd << "\n"; - os << "\tMStaticOffset: " << it.MStaticOffset << "\n"; - os << "\tMPerRowOffset: " << it.MPerRowOffset << "\n"; - os << "\tMPerSliceOffset: " << it.MPerSliceOffset << "\n"; - os << "\tMRowSize: " << it.MRowSize << "\n"; - os << "\tMSliceSize: " << it.MSliceSize << "\n"; - os << "\tMAccessorIsRanged: " << it.MAccessorIsRanged << "\n"; - os << "}"; - return os; + return os << accessor_iterator_data(it); } #endif // NDEBUG }; +// non-templated copy of accessor_iterator to pass to library +struct accessor_iterator_data { + template + accessor_iterator_data(accessor_iterator it) + : MLinearId(it.MLinearId), MEnd(it.MEnd), MStaticOffset(it.MStaticOffset), + MPerSliceOffset(it.MPerSliceOffset), MPerRowOffset(it.MPerRowOffset), + MRowSize(it.MRowSize), MSliceSize(it.MSliceSize), + MAccessorIsRanged(it.MAccessorIsRanged) {} + size_t MLinearId; + size_t MEnd; + size_t MStaticOffset; + size_t MPerSliceOffset; + size_t MPerRowOffset; + size_t MRowSize; + size_t MSliceSize; + bool MAccessorIsRanged; +}; } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/detail/common.hpp b/sycl/include/sycl/detail/common.hpp index a8c94e32d81c6..5867d199deb0d 100644 --- a/sycl/include/sycl/detail/common.hpp +++ b/sycl/include/sycl/detail/common.hpp @@ -173,14 +173,14 @@ inline std::string codeToString(pi_int32 code) { "Native API returns: " #ifndef __SYCL_SUPPRESS_PI_ERROR_REPORT -#include // TODO: rename all names with direct use of OCL/OPENCL to be backend agnostic. #define __SYCL_REPORT_PI_ERR_TO_STREAM(expr) \ { \ auto code = expr; \ if (code != PI_SUCCESS) { \ - std::cerr << __SYCL_PI_ERROR_REPORT << sycl::detail::codeToString(code) \ - << std::endl; \ + fprintf(stderr, __SYCL_PI_ERROR_REPORT "%s\n", \ + sycl::detail::codeToString(code).c_str()); \ + fflush(stderr); \ } \ } #endif diff --git a/sycl/include/sycl/detail/device_filter.hpp b/sycl/include/sycl/detail/device_filter.hpp index 44e4a2d4ff3a9..7cb73362dbd90 100644 --- a/sycl/include/sycl/detail/device_filter.hpp +++ b/sycl/include/sycl/detail/device_filter.hpp @@ -12,8 +12,8 @@ #include #include +#include #include -#include #include namespace sycl { @@ -23,11 +23,6 @@ namespace detail { // --------------------------------------- // ONEAPI_DEVICE_SELECTOR support -template -std::ostream &operator<<(std::ostream &os, std::optional const &opt) { - return opt ? os << opt.value() : os << "not set "; -} - // the ONEAPI_DEVICE_SELECTOR string gets broken down into these targets // will will match devices. If the target is negative, such as !opencl:* // then matching devices will not be made available to the user. @@ -77,8 +72,8 @@ struct device_filter { device_filter(){}; device_filter(const std::string &FilterString); - friend std::ostream &operator<<(std::ostream &Out, - const device_filter &Filter); + __SYCL_EXPORT friend std::ostream &operator<<(std::ostream &Out, + const device_filter &Filter); }; class device_filter_list { @@ -93,41 +88,10 @@ class device_filter_list { bool backendCompatible(backend Backend); bool deviceTypeCompatible(info::device_type DeviceType); bool deviceNumberCompatible(int DeviceNum); - friend std::ostream &operator<<(std::ostream &Out, - const device_filter_list &List); + __SYCL_EXPORT friend std::ostream &operator<<(std::ostream &Out, + const device_filter_list &List); }; -inline std::ostream &operator<<(std::ostream &Out, - const device_filter &Filter) { - Out << Filter.Backend << ":"; - if (Filter.DeviceType == info::device_type::host) { - Out << "host"; - } else if (Filter.DeviceType == info::device_type::cpu) { - Out << "cpu"; - } else if (Filter.DeviceType == info::device_type::gpu) { - Out << "gpu"; - } else if (Filter.DeviceType == info::device_type::accelerator) { - Out << "accelerator"; - } else if (Filter.DeviceType == info::device_type::all) { - Out << "*"; - } else { - Out << "unknown"; - } - if (Filter.DeviceNum) { - Out << ":" << Filter.DeviceNum.value(); - } - return Out; -} - -inline std::ostream &operator<<(std::ostream &Out, - const device_filter_list &List) { - for (const device_filter &Filter : List.FilterList) { - Out << Filter; - Out << ","; - } - return Out; -} - } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/detail/pi.hpp b/sycl/include/sycl/detail/pi.hpp index c4ddfe9fd1b44..8b4c5381e30d5 100644 --- a/sycl/include/sycl/detail/pi.hpp +++ b/sycl/include/sycl/detail/pi.hpp @@ -20,7 +20,6 @@ #include // for uint64_t, uint32_t #include // for shared_ptr -#include // for operator<<, basic_ostream, string... #include // for size_t #include // for char_traits, string #include // for false_type, true_type @@ -108,22 +107,6 @@ bool trace(TraceLevel level); __SYCL_EXPORT void assertion(bool Condition, const char *Message = nullptr); -template -void handleUnknownParamName(const char *functionName, T parameter) { - std::stringstream stream; - stream << "Unknown parameter " << parameter << " passed to " << functionName - << "\n"; - auto str = stream.str(); - auto msg = str.c_str(); - die(msg); -} - -// This macro is used to report invalid enumerators being passed to PI API -// GetInfo functions. It will print the name of the function that invoked it -// and the value of the unknown enumerator. -#define __SYCL_PI_HANDLE_UNKNOWN_PARAM_NAME(parameter) \ - { sycl::detail::pi::handleUnknownParamName(__func__, parameter); } - using PiPlugin = ::pi_plugin; using PiResult = ::pi_result; using PiPlatform = ::pi_platform; diff --git a/sycl/include/sycl/exception_list.hpp b/sycl/include/sycl/exception_list.hpp index 2a0202fa020a9..80467b6e3f524 100644 --- a/sycl/include/sycl/exception_list.hpp +++ b/sycl/include/sycl/exception_list.hpp @@ -10,12 +10,11 @@ // 4.9.2 Exception Class Interface -#include // for __SYCL_EXPORT -#include // for cerr +#include // for __SYCL_EXPORT #include // for size_t #include // for exception_ptr, exception -#include // for operator<<, basic_ostream +#include // for operator<<, basic_ostream #include // for vector namespace sycl { @@ -55,20 +54,7 @@ class __SYCL_EXPORT exception_list { namespace detail { // Default implementation of async_handler used by queue and context when no // user-defined async_handler is specified. -inline void defaultAsyncHandler(exception_list Exceptions) { - std::cerr << "Default async_handler caught exceptions:"; - for (auto &EIt : Exceptions) { - try { - if (EIt) { - std::rethrow_exception(EIt); - } - } catch (const std::exception &E) { - std::cerr << "\n\t" << E.what(); - } - } - std::cerr << std::endl; - std::terminate(); -} +__SYCL_EXPORT void defaultAsyncHandler(exception_list Exceptions); } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp b/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp index d7c572b4eb5a1..bc9dab1b724d4 100644 --- a/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp +++ b/sycl/include/sycl/ext/intel/esimd/detail/half_type_traits.hpp @@ -14,6 +14,9 @@ #include +#include +#include + /// @cond ESIMD_DETAIL namespace sycl { diff --git a/sycl/include/sycl/ext/intel/esimd/simd.hpp b/sycl/include/sycl/ext/intel/esimd/simd.hpp index 4165c282b5ef9..96b3f3ed02dfc 100644 --- a/sycl/include/sycl/ext/intel/esimd/simd.hpp +++ b/sycl/include/sycl/ext/intel/esimd/simd.hpp @@ -10,6 +10,8 @@ #pragma once +#include + #include #include @@ -21,10 +23,6 @@ #include -#ifndef __SYCL_DEVICE_ONLY__ -#include -#endif // __SYCL_DEVICE_ONLY__ - namespace sycl { inline namespace _V1 { namespace ext::intel::esimd { diff --git a/sycl/include/sycl/half_type.hpp b/sycl/include/sycl/half_type.hpp index 1dac778320977..1e58be02d6ab2 100644 --- a/sycl/include/sycl/half_type.hpp +++ b/sycl/include/sycl/half_type.hpp @@ -8,10 +8,10 @@ #pragma once -#include // for bit_cast -#include // for __SYCL_EXPORT -#include // for istream, ostream -#include // for vector_alignment +#include // for bit_cast +#include // for __has_builtin +#include // for __SYCL_EXPORT +#include // for vector_alignment #ifdef __SYCL_DEVICE_ONLY__ #include @@ -20,11 +20,12 @@ #include // for size_t #include // for uint16_t, uint32_t, uint8_t #include // for hash +#include // for istream, ostream #include // for float_denorm_style, float_r... #include // for hash #include // for enable_if_t -#if !defined(__has_builtin) || !__has_builtin(__builtin_expect) +#if !__has_builtin(__builtin_expect) #define __builtin_expect(a, b) (a) #endif @@ -32,8 +33,7 @@ // `constexpr` could work because the implicit conversion from `float` to // `_Float16` can be `constexpr`. #define __SYCL_CONSTEXPR_HALF constexpr -#elif __cpp_lib_bit_cast || \ - (defined(__has_builtin) && __has_builtin(__builtin_bit_cast)) +#elif __cpp_lib_bit_cast || __has_builtin(__builtin_bit_cast) #define __SYCL_CONSTEXPR_HALF constexpr #else #define __SYCL_CONSTEXPR_HALF @@ -531,18 +531,11 @@ class [[__sycl_detail__::__uses_aspects__(aspect::fp16)]] half { } // Operator << and >> - inline friend std::ostream &operator<<(std::ostream &O, - sycl::half const &rhs) { - O << static_cast(rhs); - return O; - } + friend __SYCL_EXPORT std::ostream &operator<<(std::ostream &O, + sycl::half const &rhs); - inline friend std::istream &operator>>(std::istream &I, sycl::half &rhs) { - float ValFloat = 0.0f; - I >> ValFloat; - rhs = ValFloat; - return I; - } + friend __SYCL_EXPORT std::istream &operator>>(std::istream &I, + sycl::half &rhs); template friend struct std::hash; diff --git a/sycl/include/sycl/handler.hpp b/sycl/include/sycl/handler.hpp index 6d2ff6e8a5a7d..d2210a149d512 100644 --- a/sycl/include/sycl/handler.hpp +++ b/sycl/include/sycl/handler.hpp @@ -1176,9 +1176,11 @@ class __SYCL_EXPORT handler { bool DidAdjust = false; auto Adjust = [&](int Dim, size_t Value) { - if (this->RangeRoundingTrace()) - std::cout << "parallel_for range adjusted at dim " << Dim << " from " - << RoundedRange[Dim] << " to " << Value << std::endl; + if (this->RangeRoundingTrace()) { + printf("parallel_for range adjusted at dim %d from %zu to %zu\n", Dim, + RoundedRange[Dim], Value); + fflush(stdout); + } RoundedRange[Dim] = Value; DidAdjust = true; }; diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index 5b55801796e01..274dbea1efb0d 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -98,5 +98,5 @@ #ifndef SYCL2020_CONFORMANT_APIS // We used to include those and some code might be reliant on that. #include -#include +#include //TODO: remove todo in no_iostream_include test #endif diff --git a/sycl/include/sycl/types.hpp b/sycl/include/sycl/types.hpp index 6a5857e0ed83b..9f1840064c61d 100644 --- a/sycl/include/sycl/types.hpp +++ b/sycl/include/sycl/types.hpp @@ -50,9 +50,9 @@ #include // for size_t, NULL, byte #include // for uint8_t, int16_t, int... #include // for divides, multiplies +#include // for operator<<, basic_ost... #include // for pair #include // for optional -#include // for operator<<, basic_ost... #include // for tuple #include // for enable_if_t, is_same #include // for index_sequence, make_... diff --git a/sycl/include/syclcompat/device.hpp b/sycl/include/syclcompat/device.hpp index be02a42aff4cf..e8b653cdb081e 100644 --- a/sycl/include/syclcompat/device.hpp +++ b/sycl/include/syclcompat/device.hpp @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include #include @@ -65,11 +65,11 @@ auto exception_handler = [](sycl::exception_list exceptions) { try { std::rethrow_exception(e); } catch (sycl::exception const &e) { - std::cerr << "[SYCLcompat] Caught asynchronous SYCL exception:" - << std::endl - << e.what() << std::endl - << "Exception caught at file:" << __FILE__ - << ", line:" << __LINE__ << std::endl; + fprintf(stderr, + "[SYCLcompat] Caught asynchronous SYCL exception:\n%s\n" + "Exception caught at file:" __FILE__ ", line:" __LINE__ "\n", + e.what().c_str()); + fflush(stderr); } } }; diff --git a/sycl/plugins/level_zero/tracing.cpp b/sycl/plugins/level_zero/tracing.cpp index 0049c67a61701..396e384881cfc 100644 --- a/sycl/plugins/level_zero/tracing.cpp +++ b/sycl/plugins/level_zero/tracing.cpp @@ -12,10 +12,11 @@ #endif #include +#include #include #include -#include +#include <../../source/detail/iostream_proxy.hpp> constexpr auto ZE_CALL_STREAM_NAME = "sycl.experimental.level_zero.call"; constexpr auto ZE_DEBUG_STREAM_NAME = "sycl.experimental.level_zero.debug"; diff --git a/sycl/plugins/opencl/pi_opencl.cpp b/sycl/plugins/opencl/pi_opencl.cpp index b15418f35a3c8..ea78667b53c04 100644 --- a/sycl/plugins/opencl/pi_opencl.cpp +++ b/sycl/plugins/opencl/pi_opencl.cpp @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index 1bde471cd67ac..a8ede9817c5e1 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -160,6 +160,7 @@ set(SYCL_SOURCES "backend/level_zero.cpp" "backend.cpp" "detail/accessor_impl.cpp" + "detail/accessor_iterator.cpp" "detail/allowlist.cpp" "detail/bindless_images.cpp" "detail/buffer_impl.cpp" @@ -217,6 +218,7 @@ set(SYCL_SOURCES "detail/util.cpp" "detail/xpti_registry.cpp" "accessor.cpp" + "backend_types.cpp" "buffer.cpp" "context.cpp" "device.cpp" @@ -224,6 +226,7 @@ set(SYCL_SOURCES "event.cpp" "exception.cpp" "exception_list.cpp" + "half_type.cpp" "handler.cpp" "image.cpp" "interop_handle.cpp" diff --git a/sycl/source/backend_types.cpp b/sycl/source/backend_types.cpp new file mode 100644 index 0000000000000..97c9ad8f58be4 --- /dev/null +++ b/sycl/source/backend_types.cpp @@ -0,0 +1,46 @@ +//==------------------- backend_types.cpp ----------------------------------==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +#include + +namespace sycl { +inline namespace _V1 { + +std::ostream &operator<<(std::ostream &Out, backend be) { + switch (be) { + case backend::host: + Out << "host"; + break; + case backend::opencl: + Out << "opencl"; + break; + case backend::ext_oneapi_level_zero: + Out << "ext_oneapi_level_zero"; + break; + case backend::ext_oneapi_cuda: + Out << "ext_oneapi_cuda"; + break; + case backend::ext_intel_esimd_emulator: + Out << "ext_intel_esimd_emulator"; + break; + case backend::ext_oneapi_hip: + Out << "ext_oneapi_hip"; + break; + case backend::ext_native_cpu: + Out << "ext_native_cpu"; + break; + case backend::all: + Out << "all"; + } + return Out; +} + +} // namespace _V1 +} // namespace sycl diff --git a/sycl/source/detail/accessor_iterator.cpp b/sycl/source/detail/accessor_iterator.cpp new file mode 100644 index 0000000000000..315a45d92b04b --- /dev/null +++ b/sycl/source/detail/accessor_iterator.cpp @@ -0,0 +1,35 @@ +//==---------------- accessor_iterator.cpp - SYCL standard source file -----==// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +#include + +namespace sycl { +inline namespace _V1 { + +namespace detail { + +__SYCL_EXPORT std::ostream &operator<<(std::ostream &os, + const accessor_iterator_data &it) { + os << "accessor_iterator {\n"; + os << "\tMLinearId: " << it.MLinearId << "\n"; + os << "\tMEnd: " << it.MEnd << "\n"; + os << "\tMStaticOffset: " << it.MStaticOffset << "\n"; + os << "\tMPerRowOffset: " << it.MPerRowOffset << "\n"; + os << "\tMPerSliceOffset: " << it.MPerSliceOffset << "\n"; + os << "\tMRowSize: " << it.MRowSize << "\n"; + os << "\tMSliceSize: " << it.MSliceSize << "\n"; + os << "\tMAccessorIsRanged: " << it.MAccessorIsRanged << "\n"; + os << "}"; + return os; +} + +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/source/detail/config.cpp b/sycl/source/detail/config.cpp index d57f1dade20e8..89a3329fb24c5 100644 --- a/sycl/source/detail/config.cpp +++ b/sycl/source/detail/config.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include +#include #include #include -#include #include #include diff --git a/sycl/source/detail/config.hpp b/sycl/source/detail/config.hpp index 02ce094579df2..53b9028aaa92c 100644 --- a/sycl/source/detail/config.hpp +++ b/sycl/source/detail/config.hpp @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/sycl/source/detail/device_binary_image.hpp b/sycl/source/detail/device_binary_image.hpp index b2a74febe392f..e53867122e9bc 100644 --- a/sycl/source/detail/device_binary_image.hpp +++ b/sycl/source/detail/device_binary_image.hpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #pragma once +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include namespace sycl { inline namespace _V1 { diff --git a/sycl/source/detail/device_filter.cpp b/sycl/source/detail/device_filter.cpp index 99bbcad3d7a22..c5fb332085158 100644 --- a/sycl/source/detail/device_filter.cpp +++ b/sycl/source/detail/device_filter.cpp @@ -19,6 +19,12 @@ namespace sycl { inline namespace _V1 { namespace detail { +template +std::ostream &operator<<(std::ostream &os, std::optional const &opt) { + return opt ? os << opt.value() : os << "not set "; + return os; +} + std::vector tokenize(const std::string_view &Filter, const std::string &Delim) { std::vector Tokens; @@ -406,6 +412,37 @@ bool device_filter_list::deviceNumberCompatible(int DeviceNum) { }); } +__SYCL_EXPORT std::ostream &operator<<(std::ostream &Out, + const device_filter &Filter) { + Out << Filter.Backend << ":"; + if (Filter.DeviceType == info::device_type::host) { + Out << "host"; + } else if (Filter.DeviceType == info::device_type::cpu) { + Out << "cpu"; + } else if (Filter.DeviceType == info::device_type::gpu) { + Out << "gpu"; + } else if (Filter.DeviceType == info::device_type::accelerator) { + Out << "accelerator"; + } else if (Filter.DeviceType == info::device_type::all) { + Out << "*"; + } else { + Out << "unknown"; + } + if (Filter.DeviceNum) { + Out << ":" << Filter.DeviceNum.value(); + } + return Out; +} + +__SYCL_EXPORT std::ostream &operator<<(std::ostream &Out, + const device_filter_list &List) { + for (const device_filter &Filter : List.FilterList) { + Out << Filter; + Out << ","; + } + return Out; +} + } // namespace detail } // namespace _V1 } // namespace sycl diff --git a/sycl/source/detail/device_info.hpp b/sycl/source/detail/device_info.hpp index 0ff49fe7b64f2..989d7e6716a95 100644 --- a/sycl/source/detail/device_info.hpp +++ b/sycl/source/detail/device_info.hpp @@ -27,6 +27,7 @@ #include #include +#include #include namespace sycl { diff --git a/sycl/include/sycl/detail/iostream_proxy.hpp b/sycl/source/detail/iostream_proxy.hpp similarity index 96% rename from sycl/include/sycl/detail/iostream_proxy.hpp rename to sycl/source/detail/iostream_proxy.hpp index 76f432d687d13..847e8017ec4d2 100644 --- a/sycl/include/sycl/detail/iostream_proxy.hpp +++ b/sycl/source/detail/iostream_proxy.hpp @@ -8,7 +8,7 @@ #pragma once -#include // for ostream, istream +#include // for ostream, istream // Hotfix to account for the different namespaces in libstdc++ and libc++ #ifdef _LIBCPP_BEGIN_NAMESPACE_STD diff --git a/sycl/source/detail/persistent_device_code_cache.hpp b/sycl/source/detail/persistent_device_code_cache.hpp index 323d52b859579..ed397f99e7ae5 100644 --- a/sycl/source/detail/persistent_device_code_cache.hpp +++ b/sycl/source/detail/persistent_device_code_cache.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/sycl/source/detail/platform_impl.cpp b/sycl/source/detail/platform_impl.cpp index 7ccbd43771c65..fc3eab70905b0 100644 --- a/sycl/source/detail/platform_impl.cpp +++ b/sycl/source/detail/platform_impl.cpp @@ -10,10 +10,10 @@ #include #include #include +#include #include #include #include -#include #include #include diff --git a/sycl/source/detail/plugin.hpp b/sycl/source/detail/plugin.hpp index 853027bf7c6bb..063e2f2671ebc 100644 --- a/sycl/source/detail/plugin.hpp +++ b/sycl/source/detail/plugin.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/sycl/source/detail/plugin_printers.hpp b/sycl/source/detail/plugin_printers.hpp index 0da8e1c0efc26..c442c573dbde9 100644 --- a/sycl/source/detail/plugin_printers.hpp +++ b/sycl/source/detail/plugin_printers.hpp @@ -10,8 +10,10 @@ #pragma once +#include #include +#include #include namespace sycl { diff --git a/sycl/source/detail/posix_pi.cpp b/sycl/source/detail/posix_pi.cpp index 220727f3bb59a..ed0da13499f26 100644 --- a/sycl/source/detail/posix_pi.cpp +++ b/sycl/source/detail/posix_pi.cpp @@ -6,11 +6,12 @@ // //===----------------------------------------------------------------------===// +#include #include -#include #include #include +#include #include namespace sycl { diff --git a/sycl/source/detail/spec_constant_impl.cpp b/sycl/source/detail/spec_constant_impl.cpp index 13fbf9fcc9bdd..f1f615cc213e4 100644 --- a/sycl/source/detail/spec_constant_impl.cpp +++ b/sycl/source/detail/spec_constant_impl.cpp @@ -8,8 +8,9 @@ #include +#include +#include #include -#include #include #include #include diff --git a/sycl/source/detail/spec_constant_impl.hpp b/sycl/source/detail/spec_constant_impl.hpp index b576cc243b542..c629c3380ae93 100644 --- a/sycl/source/detail/spec_constant_impl.hpp +++ b/sycl/source/detail/spec_constant_impl.hpp @@ -8,8 +8,8 @@ #pragma once +#include #include -#include #include #include diff --git a/sycl/source/esimd_emulator_device_interface.cpp b/sycl/source/esimd_emulator_device_interface.cpp index 599ff255976ba..904125ac236a3 100644 --- a/sycl/source/esimd_emulator_device_interface.cpp +++ b/sycl/source/esimd_emulator_device_interface.cpp @@ -15,6 +15,8 @@ /// /// \ingroup sycl_pi_esimd_emulator +#include +#include #include #include diff --git a/sycl/source/exception_list.cpp b/sycl/source/exception_list.cpp index 2b31ec3177501..1a16f4df34f55 100644 --- a/sycl/source/exception_list.cpp +++ b/sycl/source/exception_list.cpp @@ -9,6 +9,8 @@ // 4.9.2 Exception Class Interface #include +#include +#include #include namespace sycl { @@ -30,5 +32,24 @@ void exception_list::PushBack(value_type &&Value) { void exception_list::Clear() noexcept { MList.clear(); } +namespace detail { +// Default implementation of async_handler used by queue and context when no +// user-defined async_handler is specified. +void defaultAsyncHandler(exception_list Exceptions) { + std::cerr << "Default async_handler caught exceptions:"; + for (auto &EIt : Exceptions) { + try { + if (EIt) { + std::rethrow_exception(EIt); + } + } catch (const std::exception &E) { + std::cerr << "\n\t" << E.what(); + } + } + std::cerr << std::endl; + std::terminate(); +} +} // namespace detail + } // namespace _V1 } // namespace sycl diff --git a/sycl/source/half_type.cpp b/sycl/source/half_type.cpp new file mode 100644 index 0000000000000..5cf33eb16df84 --- /dev/null +++ b/sycl/source/half_type.cpp @@ -0,0 +1,34 @@ +//===--------------- half_type.cpp - SYCL half type -----------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include + +#include +#include + +namespace sycl { +inline namespace _V1 { +namespace detail { +namespace half_impl { + +std::ostream &operator<<(std::ostream &O, half const &rhs) { + O << static_cast(rhs); + return O; +} + +std::istream &operator>>(std::istream &I, half &rhs) { + float ValFloat = 0.0f; + I >> ValFloat; + rhs = ValFloat; + return I; +} + +} // namespace half_impl +} // namespace detail +} // namespace _V1 +} // namespace sycl diff --git a/sycl/source/spirv_ops.cpp b/sycl/source/spirv_ops.cpp index a635dea89d955..7787d0b5c0f4c 100644 --- a/sycl/source/spirv_ops.cpp +++ b/sycl/source/spirv_ops.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include diff --git a/sycl/test/abi/sycl_symbols_linux.dump b/sycl/test/abi/sycl_symbols_linux.dump index 0ca44740b987f..ea215b131e930 100644 --- a/sycl/test/abi/sycl_symbols_linux.dump +++ b/sycl/test/abi/sycl_symbols_linux.dump @@ -3976,6 +3976,7 @@ _ZN4sycl3_V16detail18make_kernel_bundleEmRKNS0_7contextEbNS0_12bundle_stateENS0_ _ZN4sycl3_V16detail18stringifyErrorCodeEi _ZN4sycl3_V16detail19convertChannelOrderE23_pi_image_channel_order _ZN4sycl3_V16detail19convertChannelOrderENS0_19image_channel_orderE +_ZN4sycl3_V16detail19defaultAsyncHandlerENS0_14exception_listE _ZN4sycl3_V16detail19getImageElementSizeEhNS0_18image_channel_typeE _ZN4sycl3_V16detail19getPluginOpaqueDataILNS0_7backendE5EEEPvS4_ _ZN4sycl3_V16detail19kernel_bundle_plain32set_specialization_constant_implEPKcPvm @@ -4034,8 +4035,13 @@ _ZN4sycl3_V16detail6OSUtil12alignedAllocEmm _ZN4sycl3_V16detail6OSUtil12getOSMemSizeEv _ZN4sycl3_V16detail6OSUtil16getCurrentDSODirB5cxx11Ev _ZN4sycl3_V16detail6OSUtil7makeDirEPKc +_ZN4sycl3_V16detail9half_impllsERSoRKNS2_4halfE +_ZN4sycl3_V16detail9half_implrsERSiRNS2_4halfE _ZN4sycl3_V16detail9join_implERKSt6vectorISt10shared_ptrINS1_18kernel_bundle_implEESaIS5_EENS0_12bundle_stateE _ZN4sycl3_V16detail9link_implERKSt6vectorINS0_13kernel_bundleILNS0_12bundle_stateE1EEESaIS5_EERKS2_INS0_6deviceESaISA_EERKNS0_13property_listE +_ZN4sycl3_V16detaillsERSoRKNS1_13device_filterE +_ZN4sycl3_V16detaillsERSoRKNS1_18device_filter_listE +_ZN4sycl3_V16detaillsERSoRKNS1_22accessor_iterator_dataE _ZN4sycl3_V16device11get_devicesENS0_4info11device_typeE _ZN4sycl3_V16device26ext_oneapi_architecture_isENS0_3ext6oneapi12experimental12architectureE _ZN4sycl3_V16device26ext_oneapi_can_access_peerERKS1_NS0_3ext6oneapi11peer_accessE @@ -4185,6 +4191,7 @@ _ZN4sycl3_V19exceptionD1Ev _ZN4sycl3_V19exceptionD2Ev _ZN4sycl3_V19kernel_idC1EPKc _ZN4sycl3_V19kernel_idC2EPKc +_ZN4sycl3_V1lsERSoNS0_7backendE _ZNK4sycl3_V112cpu_selectorclERKNS0_6deviceE _ZNK4sycl3_V112gpu_selectorclERKNS0_6deviceE _ZNK4sycl3_V113host_selectorclERKNS0_6deviceE diff --git a/sycl/test/abi/sycl_symbols_windows.dump b/sycl/test/abi/sycl_symbols_windows.dump index 1a2a2e42ba08b..e9cffee367a0b 100644 --- a/sycl/test/abi/sycl_symbols_windows.dump +++ b/sycl/test/abi/sycl_symbols_windows.dump @@ -775,6 +775,12 @@ ??4stream_impl@detail@_V1@sycl@@QEAAAEAV0123@$$QEAV0123@@Z ??4stream_impl@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z ??4tls_code_loc_t@detail@_V1@sycl@@QEAAAEAV0123@AEBV0123@@Z +??5half_impl@detail@_V1@sycl@@YAAEAV?$basic_istream@DU?$char_traits@D@std@@@std@@AEAV45@AEAVhalf@0123@@Z +??6half_impl@detail@_V1@sycl@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV45@AEBVhalf@0123@@Z +??6_V1@sycl@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV23@W4backend@01@@Z +??6detail@_V1@sycl@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV34@AEBUaccessor_iterator_data@012@@Z +??6detail@_V1@sycl@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV34@AEBUdevice_filter@012@@Z +??6detail@_V1@sycl@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV34@AEBVdevice_filter_list@012@@Z ??8context@_V1@sycl@@QEBA_NAEBV012@@Z ??8device@_V1@sycl@@QEBA_NAEBV012@@Z ??8device_image_plain@detail@_V1@sycl@@QEBA_NAEBV0123@@Z @@ -974,6 +980,7 @@ ?create_image@experimental@oneapi@ext@_V1@sycl@@YA?AUunsampled_image_handle@12345@AEAVimage_mem@12345@AEBUimage_descriptor@12345@AEBVqueue@45@@Z ?create_image@experimental@oneapi@ext@_V1@sycl@@YA?AUunsampled_image_handle@12345@Uimage_mem_handle@12345@AEBUimage_descriptor@12345@AEBVdevice@45@AEBVcontext@45@@Z ?create_image@experimental@oneapi@ext@_V1@sycl@@YA?AUunsampled_image_handle@12345@Uimage_mem_handle@12345@AEBUimage_descriptor@12345@AEBVqueue@45@@Z +?defaultAsyncHandler@detail@_V1@sycl@@YAXVexception_list@23@@Z ?default_selector_v@_V1@sycl@@YAHAEBVdevice@12@@Z ?deleteAccProps@buffer_plain@detail@_V1@sycl@@IEAAXAEBW4PropWithDataKind@234@@Z ?deleteAccessorProperty@SYCLMemObjT@detail@_V1@sycl@@QEAAXAEBW4PropWithDataKind@234@@Z diff --git a/sycl/test/basic_tests/accessor/atomic_zero_dimension_accessor.cpp b/sycl/test/basic_tests/accessor/atomic_zero_dimension_accessor.cpp index ff53db7bf35b3..74ca08de4a20c 100644 --- a/sycl/test/basic_tests/accessor/atomic_zero_dimension_accessor.cpp +++ b/sycl/test/basic_tests/accessor/atomic_zero_dimension_accessor.cpp @@ -8,6 +8,8 @@ #include +#include + using namespace sycl; using atomic_t = sycl::atomic; diff --git a/sycl/test/basic_tests/accessor/const-type-non-readonly-accessor.cpp b/sycl/test/basic_tests/accessor/const-type-non-readonly-accessor.cpp index 32c20a0bff257..da3a87b511bb6 100644 --- a/sycl/test/basic_tests/accessor/const-type-non-readonly-accessor.cpp +++ b/sycl/test/basic_tests/accessor/const-type-non-readonly-accessor.cpp @@ -2,6 +2,8 @@ #include +#include + using namespace sycl; constexpr size_t dataSize = 1; diff --git a/sycl/test/basic_tests/no_iostream_include.cpp b/sycl/test/basic_tests/no_iostream_include.cpp new file mode 100644 index 0000000000000..c255112cd0965 --- /dev/null +++ b/sycl/test/basic_tests/no_iostream_include.cpp @@ -0,0 +1,12 @@ +// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s +// Test that only iosfwd and not istream, ostream, and iostream_proxy +// are included. +#include + +void t(std::istream &i, std::ostream &o) { + char c; + i >> c; // expected-error-todo {{invalid operands to binary expression}} + o << o; // expected-error {{invalid operands to binary expression}} + std::cout // expected-error {{no member named 'cout' in namespace 'std'}} + << "\n"; +} diff --git a/sycl/test/basic_tests/types.cpp b/sycl/test/basic_tests/types.cpp index 4b4738d99f36b..6036946ae0674 100644 --- a/sycl/test/basic_tests/types.cpp +++ b/sycl/test/basic_tests/types.cpp @@ -12,6 +12,7 @@ #include #include +#include #include using namespace std; diff --git a/sycl/test/extensions/fpga.cpp b/sycl/test/extensions/fpga.cpp index b952f00706f80..3df706ea8cebf 100644 --- a/sycl/test/extensions/fpga.cpp +++ b/sycl/test/extensions/fpga.cpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace intelfpga { diff --git a/sycl/test/regression/half_host_subnormal_min.cpp b/sycl/test/regression/half_host_subnormal_min.cpp index f0e0405e879dd..763453ae5f3a2 100644 --- a/sycl/test/regression/half_host_subnormal_min.cpp +++ b/sycl/test/regression/half_host_subnormal_min.cpp @@ -6,6 +6,8 @@ #include +#include + int main() { sycl::half SubnormalMin = sycl::bit_cast((uint16_t)0b0000000000000001u); diff --git a/sycl/test/regression/host_half_nextafter.cpp b/sycl/test/regression/host_half_nextafter.cpp index fe9bf949c65e3..a4e3efefdda4a 100644 --- a/sycl/test/regression/host_half_nextafter.cpp +++ b/sycl/test/regression/host_half_nextafter.cpp @@ -6,6 +6,8 @@ #include +#include + void check(uint16_t x, uint16_t y, uint16_t ref) { assert(sycl::nextafter(sycl::bit_cast(x), sycl::bit_cast(y)) == diff --git a/sycl/test/regression/host_tanpi_double_accuracy.cpp b/sycl/test/regression/host_tanpi_double_accuracy.cpp index d84a391b36e6a..6641c278aa4ef 100644 --- a/sycl/test/regression/host_tanpi_double_accuracy.cpp +++ b/sycl/test/regression/host_tanpi_double_accuracy.cpp @@ -6,6 +6,7 @@ #include #include +#include #include double get_ulp(double X) { diff --git a/sycl/unittests/pi/BackendString.hpp b/sycl/unittests/pi/BackendString.hpp index ea90e3ff3eb54..e5ab476fbbe16 100644 --- a/sycl/unittests/pi/BackendString.hpp +++ b/sycl/unittests/pi/BackendString.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include namespace pi { diff --git a/sycl/unittests/pi/TestGetPlugin.hpp b/sycl/unittests/pi/TestGetPlugin.hpp index 774d65c02f420..ef6080cdeddf0 100644 --- a/sycl/unittests/pi/TestGetPlugin.hpp +++ b/sycl/unittests/pi/TestGetPlugin.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace pi { inline std::optional