Skip to content

Commit f59ec98

Browse files
swolchokpytorchmergebot
authored andcommitted
Add C10_EMBEDDED to gate ostream usage in Half/BFloat16 (pytorch#140566)
We want to use Half/BFloat16 in ExecuTorch to support shared kernel code. They will need to be used in ExecuTorch core, so they can't have streams. This diff introduces a macro to gate the stream code off. Differential Revision: [D65888035](https://our.internmc.facebook.com/intern/diff/D65888035/) Pull Request resolved: pytorch#140566 Approved by: https://github.com/ezyang, https://github.com/malfet ghstack dependencies: pytorch#140564, pytorch#140565
1 parent 0f1a88c commit f59ec98

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

c10/util/BFloat16.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#include <cstdint>
99
#include <cstring>
1010
#include <iosfwd>
11+
#ifndef C10_EMBEDDED
1112
#include <ostream>
13+
#endif // C10_EMBEDDED
1214

1315
#if defined(__CUDACC__) && !defined(USE_ROCM)
1416
#include <cuda_bf16.h>
@@ -114,12 +116,14 @@ struct alignas(2) BFloat16 {
114116
#endif
115117
};
116118

119+
#ifndef C10_EMBEDDED
117120
C10_API inline std::ostream& operator<<(
118121
std::ostream& out,
119122
const BFloat16& value) {
120123
out << (float)value;
121124
return out;
122125
}
126+
#endif // C10_EMBEDDED
123127

124128
} // namespace c10
125129

c10/util/Half.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
#include <cstring>
3030
#include <iosfwd>
3131
#include <limits>
32+
#ifndef C10_EMBEDDED
3233
#include <ostream>
34+
#endif // C10_EMBEDDED
3335

3436
#ifdef __CUDACC__
3537
#include <cuda_fp16.h>
@@ -384,10 +386,12 @@ struct alignas(2) Half {
384386
#endif
385387
};
386388

389+
#ifndef C10_EMBEDDED
387390
C10_API inline std::ostream& operator<<(std::ostream& out, const Half& value) {
388391
out << (float)value;
389392
return out;
390393
}
394+
#endif // C10_EMBEDDED
391395

392396
} // namespace c10
393397

0 commit comments

Comments
 (0)