Skip to content

[SYCL][ABI-break] Remove <iostream> headers from "sycl/sycl.hpp" and related files #6337

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

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3fe426b
replaced cout|cin|clog with respective c counterparts to remove <iost…
raaiq1 Jun 17, 2022
58ebf67
Merge pull request #2 from intel/sycl
raaiq1 Jun 17, 2022
f2b5f89
remoeved iostream from sycl headers
raaiq1 Jun 17, 2022
1ba59dd
Merge branch 'sycl' into raaiq
raaiq1 Jun 17, 2022
780cb9c
small chagnes
raaiq1 Jun 21, 2022
60cb520
Removed unnecessary comments
raaiq1 Jun 22, 2022
06f3856
Merge pull request #4 from intel/sycl
raaiq1 Jun 22, 2022
96ff86e
Merge branch 'sycl' into raaiq
raaiq1 Jun 22, 2022
1f63594
Addressing PR issues
raaiq1 Jun 27, 2022
de8792b
next pr
raaiq1 Jun 27, 2022
d64275a
format changes
raaiq1 Jun 27, 2022
3a66ee4
more clang-format changes
raaiq1 Jun 27, 2022
8ce2fe9
Merge branch 'raaiq' of https://github.com/raaiq1/llvm into raaiq
raaiq1 Jun 27, 2022
63e2155
thought formatting was done
raaiq1 Jun 27, 2022
6c85afe
Merge pull request #5 from intel/sycl
raaiq1 Jun 28, 2022
3104b5f
fixed compilation errors
raaiq1 Jun 28, 2022
786b793
fixed bugs and errors on previous changes
raaiq1 Jun 29, 2022
8c49996
Refectored persistent_device_code_cache.cpp to exclude iostream, fail…
raaiq1 Jun 30, 2022
672176e
Merge branch 'NextPr' into raaiq
raaiq1 Jun 30, 2022
8513d2b
format changes
raaiq1 Jun 30, 2022
6d1e9b2
a
raaiq1 Jun 30, 2022
6b787df
Fixed some unittest bugs related to removing iostream from sycl
raaiq1 Jul 6, 2022
3e16843
Merge pull request #6 from intel/sycl
raaiq1 Jul 6, 2022
e13331b
Merge pull request #7 from intel/sycl
raaiq1 Jul 6, 2022
7ec4559
Small bug fix
raaiq1 Jul 6, 2022
f49ef6c
Format changes
raaiq1 Jul 6, 2022
995bfa4
Added <fstream> back to persistant_device_code_cache.cpp and removed …
raaiq1 Jul 7, 2022
e137e4e
Apply suggestions from code review
raaiq1 Jul 7, 2022
603791e
Applied more suggestions from code review
raaiq1 Jul 7, 2022
e241fc0
Merge branch 'raaiq' of https://github.com/raaiq0/llvm into raaiq
raaiq1 Jul 7, 2022
030acda
Small change
raaiq1 Jul 7, 2022
4152ca5
more format changes
raaiq1 Jul 7, 2022
3d5aaef
clang-format.patch: great tool
raaiq1 Jul 7, 2022
00f14e6
Added exception handling
raaiq1 Jul 8, 2022
49a7d63
Forgot something
raaiq1 Jul 9, 2022
d3af226
Used unused function returns
raaiq1 Jul 11, 2022
cdd4a54
fixed warning fail
raaiq1 Jul 11, 2022
9f7e3be
Plugin changes
raaiq1 Jul 11, 2022
67d6459
Fixe dmore plugin bugs
raaiq1 Jul 11, 2022
8be9589
Merge branch 'intel:sycl' into sycl
raaiq1 Jul 12, 2022
be34f48
Merge branch 'intel:sycl' into raaiq
raaiq1 Jul 12, 2022
949ec50
[SYCL][abi-break] Remove <iostream> from 'sycl/sycl.hpp' headers and …
raaiq1 Jul 12, 2022
5e94fcf
Merge branch 'raaiq' of https://github.com/raaiq1/llvm into raaiq
raaiq1 Jul 12, 2022
0081330
Merge branch 'sycl' into raaiq
raaiq1 Jul 13, 2022
f514b07
Added test tocheck if <iostream> is included in headers
raaiq1 Jul 13, 2022
56d8eab
Fixed refactoring bugs
raaiq1 Jul 14, 2022
d141036
Merge branch 'sycl' of https://github.com/intel/llvm into intel-sycl
raaiq1 Jul 14, 2022
424b6b0
Merge branch 'intel-sycl' into raaiq
raaiq1 Jul 14, 2022
7119d2a
Fixed format issues
raaiq1 Jul 14, 2022
4a85979
small change
raaiq1 Jul 14, 2022
71ea7ed
More format changes
raaiq1 Jul 14, 2022
52a45da
message
raaiq1 Jul 14, 2022
1f6df1b
Casted all intergral types to long long for portability
raaiq1 Jul 15, 2022
4deaffd
Marked gdb counter test unsupported and moved test to better directory
raaiq1 Jul 15, 2022
8657632
Merge pull request #11 from intel/sycl
raaiq1 Jul 15, 2022
d890d56
Whats up
raaiq1 Jul 18, 2022
31cf873
Merge branch 'raaiq' of https://github.com/raaiq1/llvm into raaiq
raaiq1 Jul 18, 2022
171094b
Merge branch 'intel:sycl' into raaiq
raaiq1 Jul 19, 2022
dc561f7
Merge branch 'intel:sycl' into raaiq
raaiq1 Jul 20, 2022
76cfc00
Merge branch 'intel:sycl' into raaiq
raaiq1 Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions sycl/include/sycl/backend_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

#include <sycl/detail/defines.hpp>

#include <fstream>
#include <iostream>
#include <istream>
#include <string>

__SYCL_INLINE_NAMESPACE(cl) {
Expand All @@ -31,7 +28,7 @@ enum class backend : char {
esimd_cpu __SYCL2020_DEPRECATED("use 'ext_oneapi_esimd_emulator' instead") =
ext_intel_esimd_emulator,
ext_oneapi_hip = 6,
hip __SYCL2020_DEPRECATED("use 'ext_oneapi_hip' instead") = ext_oneapi_hip,
hip __SYCL2020_DEPRECATED("use 'ext_oneapi_hip' instead") = ext_oneapi_hip
};

template <backend Backend> class backend_traits;
Expand All @@ -43,30 +40,25 @@ template <backend Backend, typename SYCLObjectT>
using backend_return_t =
typename backend_traits<Backend>::template return_type<SYCLObjectT>;

inline std::ostream &operator<<(std::ostream &Out, backend be) {
inline std::string backend_to_string(const backend &be) {

switch (be) {
case backend::host:
Out << "host";
break;
return "host";
case backend::opencl:
Out << "opencl";
break;
return "opencl";
case backend::ext_oneapi_level_zero:
Out << "ext_oneapi_level_zero";
break;
return "ext_oneapi_level_zero";
case backend::ext_oneapi_cuda:
Out << "ext_oneapi_cuda";
break;
return "ext_oneapi_cuda";
case backend::ext_intel_esimd_emulator:
Out << "ext_intel_esimd_emulator";
break;
return "ext_intel_esimd_emulator";
case backend::ext_oneapi_hip:
Out << "ext_oneapi_hip";
break;
return "ext_oneapi_hip";
case backend::all:
Out << "all";
return "all";
}
return Out;
return "";
}

} // namespace sycl
Expand Down
8 changes: 5 additions & 3 deletions sycl/include/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ static inline std::string codeToString(pi_int32 code) {
"Native API returns: "

#ifndef __SYCL_SUPPRESS_PI_ERROR_REPORT
#include <iostream>
#include <cstdio>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raaiq1, please, add motivation for this change to the PR description. Right now it just describes what PR does, but doesn't explain why do we need this change.

I guess performance has something to do with it. Am I right?
FYI: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slio3-prefer-iostreams-for-io

Copy link
Contributor Author

@raaiq1 raaiq1 Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main motivation behind it to abide by llvm coding standards, in this case it's avoid including <iostream> in library files: https://llvm.org/docs/CodingStandards.html#include-iostream-is-forbidden

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add such information to the pull request description. It's important context information for doing code review.

// 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 \
<< cl::sycl::detail::codeToString(code) << std::endl; \
\
fprintf(stderr, __SYCL_PI_ERROR_REPORT "%s\n", \
cl::sycl::detail::codeToString(code).c_str()); \
} \
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/detail/device_binary_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RTDeviceBinaryImage : public pi::DeviceBinaryImage {

void print() const override {
pi::DeviceBinaryImage::print();
std::cerr << " OSModuleHandle=" << ModuleHandle << "\n";
fprintf(stderr, " OSModuleHandle=%lld\n", (long long int)ModuleHandle);
}

protected:
Expand All @@ -60,7 +60,7 @@ class DynRTDeviceBinaryImage : public RTDeviceBinaryImage {

void print() const override {
RTDeviceBinaryImage::print();
std::cerr << " DYNAMICALLY CREATED\n";
fprintf(stderr, " DYNAMICALLY CREATED\n");
}

protected:
Expand Down
60 changes: 33 additions & 27 deletions sycl/include/sycl/detail/device_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <sycl/detail/defines.hpp>
#include <sycl/info/info_desc.hpp>

#include <iostream>
#include <string>

__SYCL_INLINE_NAMESPACE(cl) {
Expand All @@ -30,8 +29,7 @@ struct device_filter {

device_filter(){};
device_filter(const std::string &FilterString);
friend std::ostream &operator<<(std::ostream &Out,
const device_filter &Filter);
inline operator std::string() const;
};

class device_filter_list {
Expand All @@ -47,37 +45,45 @@ class device_filter_list {
bool deviceTypeCompatible(info::device_type DeviceType);
bool deviceNumberCompatible(int DeviceNum);
bool containsHost();
friend std::ostream &operator<<(std::ostream &Out,
const device_filter_list &List);
inline operator std::string() const;
};

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";
inline device_filter::operator std::string() const {
std::string Out{};
Out += backend_to_string(this->Backend);
Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string Out{};
Out += backend_to_string(this->Backend);
std::string Out = backend_to_string(this->Backend);

Out += ":";
switch (this->DeviceType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: is this-> really needed here?

case info::device_type::host:
Out += "host";
break;
case info::device_type::cpu:
Out += "cpu";
break;
case info::device_type::gpu:
Out += "gpu";
break;
case info::device_type::accelerator:
Out += "accelerator";
break;
case info::device_type::all:
Out += "*";
break;
default:
Out += "unknown";
break;
}
if (Filter.HasDeviceNum) {
Out << ":" << Filter.DeviceNum;

if (this->HasDeviceNum) {
Out += ":" + std::to_string(this->DeviceNum);
}
return Out;
}

inline std::ostream &operator<<(std::ostream &Out,
const device_filter_list &List) {
for (const device_filter &Filter : List.FilterList) {
Out << Filter;
Out << ",";
inline device_filter_list::operator std::string() const {
std::string Out;
for (const device_filter &Filter : this->FilterList) {
Out += Filter;
Out += ",";
}
return Out;
}
Expand Down
1 change: 0 additions & 1 deletion sycl/include/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <sycl/types.hpp>

#include <cmath>
#include <iostream>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
Expand Down
21 changes: 10 additions & 11 deletions sycl/include/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <cassert>
#include <cstdint>
#include <memory>
#include <sstream>
#include <string>
#include <vector>

Expand Down Expand Up @@ -82,11 +81,14 @@ __SYCL_EXPORT void assertion(bool Condition, const char *Message = nullptr);

template <typename T>
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();
std::string string;
string += "Unknown parameter ";
string += parameter;
string += " passed to ";
string += functionName;
string += "\n";

auto msg = string.c_str();
die(msg);
}

Expand Down Expand Up @@ -232,15 +234,12 @@ class DeviceBinaryProperty {
pi_uint32 asUint32() const;
ByteArray asByteArray() const;
const char *asCString() const;
operator std::string() const;

protected:
friend std::ostream &operator<<(std::ostream &Out,
const DeviceBinaryProperty &P);
const _pi_device_binary_property_struct *Prop;
};

std::ostream &operator<<(std::ostream &Out, const DeviceBinaryProperty &P);

// C++ convenience wrapper over the pi_device_binary_struct structure.
class DeviceBinaryImage {
public:
Expand Down Expand Up @@ -298,7 +297,7 @@ class DeviceBinaryImage {
DeviceBinaryImage() : Bin(nullptr){};

virtual void print() const;
virtual void dump(std::ostream &Out) const;
virtual void dump(FILE *file) const;

size_t getSize() const {
assert(Bin && "binary image data not set");
Expand Down
13 changes: 0 additions & 13 deletions sycl/include/sycl/ext/intel/esimd/detail/elem_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,19 +713,6 @@ __esimd_wrapper_type_bitcast_from<sycl::half>(sycl::half Val) {
template <>
struct is_esimd_arithmetic_type<__raw_t<sycl::half>, void> : std::true_type {};

// Misc
inline std::ostream &operator<<(std::ostream &O, sycl::half const &rhs) {
O << static_cast<float>(rhs);
return O;
}

inline std::istream &operator>>(std::istream &I, sycl::half &rhs) {
float ValFloat = 0.0f;
I >> ValFloat;
rhs = ValFloat;
return I;
}

// The only other place which needs to be updated to support a new type is
// the is_wrapper_elem_type_v meta function.

Expand Down
5 changes: 4 additions & 1 deletion sycl/include/sycl/ext/intel/esimd/detail/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

#pragma once

#include <string>
#include <sycl/detail/defines.hpp>
#include <sycl/detail/stl_type_traits.hpp> // to define C++14,17 extensions
#include <sycl/ext/intel/esimd/common.hpp>
#include <sycl/ext/intel/esimd/detail/region.hpp>
#include <sycl/half_type.hpp>

#if defined(__ESIMD_DBG_HOST) && !defined(__SYCL_DEVICE_ONLY__)
#define __esimd_dbg_print(a) std::cout << ">>> " << #a << "\n"
#define __esimd_dbg_print(a) \
printf(">>> %s\n", #a); \
fflush(stdout);
#else
#define __esimd_dbg_print(a)
#endif // defined(__ESIMD_DBG_HOST) && !defined(__SYCL_DEVICE_ONLY__)
Expand Down
45 changes: 23 additions & 22 deletions sycl/include/sycl/ext/intel/esimd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <sycl/ext/oneapi/experimental/invoke_simd.hpp>

#ifndef __SYCL_DEVICE_ONLY__
#include <iostream>
#include <cstdio>
#endif // __SYCL_DEVICE_ONLY__

__SYCL_INLINE_NAMESPACE(cl) {
Expand Down Expand Up @@ -125,9 +125,30 @@ class simd : public detail::simd_obj_impl<
return sycl::ext::oneapi::experimental::simd<Ty, N1>(base_type::data());
}

/// @ingroup sycl_esimd_misc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is wrong doc group. just drop it

/// Prints a \c simd object to an output stream.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not what the code is doing now, it rather converts the object to std::string

/// TODO: implemented for host code only.
operator std::string() const
#ifdef __SYCL_DEVICE_ONLY__
{}
#else
{
std::string OS;
OS += "{";
for (int I = 0; I < N; I++) {
OS += (*this)[I];
if (I < N - 1)
OS += ",";
}
OS += "}";
return OS;
}
#endif // __SYCL_DEVICE_ONLY__

/// Prefix increment, increments elements of this object.
/// @return Reference to this object.
simd &operator++() {
simd &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please drop this change

operator++() {
*this += 1;
return *this;
}
Expand Down Expand Up @@ -200,23 +221,3 @@ template <int N> using simd_mask = detail::simd_mask_type<N>;

} // namespace __ESIMD_NS
} // __SYCL_INLINE_NAMESPACE(cl)

/// @ingroup sycl_esimd_misc
/// Prints a \c simd object to an output stream.
/// TODO: implemented for host code only.
template <typename Ty, int N>
std::ostream &operator<<(std::ostream &OS, const __ESIMD_NS::simd<Ty, N> &V)
#ifdef __SYCL_DEVICE_ONLY__
{}
#else
{
OS << "{";
for (int I = 0; I < N; I++) {
OS << V[I];
if (I < N - 1)
OS << ",";
}
OS << "}";
return OS;
}
#endif // __SYCL_DEVICE_ONLY__
Loading