Skip to content

Commit 4201a6a

Browse files
committed
progress
1 parent 63688ab commit 4201a6a

File tree

12 files changed

+137
-34
lines changed

12 files changed

+137
-34
lines changed

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ static cl::opt<std::string> PassPipeline(
121121
static cl::alias PassPipeline2("p", cl::aliasopt(PassPipeline),
122122
cl::desc("Alias for -passes"));
123123

124+
static cl::opt<bool> PreviewBreakingChanges(
125+
"fpreview-breaking-changes", cl::desc("Enable preview breaking changes"),
126+
cl::init(false), cl::Hidden);
127+
124128
/// Path of the current binary.
125129
static const char *LinkerExecutable;
126130

@@ -1129,7 +1133,8 @@ wrapSYCLBinariesFromFile(std::vector<module_split::SplitModule> &SplitModules,
11291133
errs() << formatv(" offload-wrapper: compile-opts: {0}, link-opts: {1}\n",
11301134
CompileOptions, LinkOptions);
11311135
}
1132-
if (Error E = offloading::wrapSYCLBinaries(M, Images, WrappingOptions))
1136+
if (Error E = offloading::wrapSYCLBinaries(M, Images, WrappingOptions,
1137+
PreviewBreakingChanges))
11331138
return E;
11341139

11351140
if (Args.hasArg(OPT_print_wrapped_module))

clang/tools/clang-offload-wrapper/SymPropReader.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
//===-- clang-offload-wrapper/SymPropReader.cpp -----------*- C++ -*-===//
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+
/// \file
10+
/// Helper class for reading symbol and property information from SYCL
11+
/// device image bitcode files in the context of the clang-offload-wrapper tool.
12+
/// It provides utilities to extract device image initializers, entry names,
13+
/// and property sets from LLVM IR modules, enabling the wrapper to interpret
14+
/// and manage offload image metadata, such as kernel entry points and
15+
/// device-specific properties, for SYCL offloading.
16+
//===----------------------------------------------------------------------===//
17+
118
#include "llvm/Bitcode/BitcodeReader.h"
219
#include "llvm/IR/Constants.h"
320
#include "llvm/IR/LLVMContext.h"
@@ -57,10 +74,12 @@ auto getInitializerNumElements(const Constant *Initializer) {
5774
// /// a null-terminated string; target- and compiler-specific options
5875
// /// which are suggested to use to "link" program at runtime
5976
// const char *LinkOptions;
77+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
6078
// /// Pointer to the manifest data start
6179
// const unsigned char *ManifestStart;
6280
// /// Pointer to the manifest data end
6381
// const unsigned char *ManifestEnd;
82+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
6483
// /// Pointer to the device binary image start
6584
// void *ImageStart;
6685
// /// Pointer to the device binary image end

llvm/include/llvm/Frontend/Offloading/SYCLOffloadWrapper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ struct SYCLWrappingOptions {
7070
/// Wraps the input bundled images and accompanied data into the module \p M
7171
/// as global symbols and registers the images with the SYCL Runtime.
7272
/// \param Options Settings that allows to turn on optional data and settings.
73+
/// \param _PreviewBreakingChanges Enable preview breaking changes that are not
74+
/// backward compatible with the existing SYCL Runtime.
75+
/// \returns Error if wrapping fails, success otherwise.
7376
llvm::Error
7477
wrapSYCLBinaries(llvm::Module &M, const llvm::SmallVector<SYCLImage> &Images,
75-
SYCLWrappingOptions Options = SYCLWrappingOptions());
78+
SYCLWrappingOptions Options = SYCLWrappingOptions(),
79+
bool _PreviewBreakingChanges = false);
7680

7781
} // namespace offloading
7882
} // namespace llvm

llvm/lib/Frontend/Offloading/SYCLOffloadWrapper.cpp

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ using namespace llvm::util;
4646

4747
namespace {
4848

49+
/// Enable preview breaking changes
50+
static bool PreviewBreakingChanges = false;
51+
4952
/// Note: Returned values are a part of ABI. If you want to change them
5053
/// then coordinate it with SYCL Runtime.
5154
int8_t binaryImageFormatToInt8(SYCLBinaryImageFormat Format) {
@@ -137,7 +140,6 @@ struct Wrapper {
137140
}
138141

139142
// TODO: Drop Version in favor of the Version in Binary Descriptor.
140-
// TODO: Drop Manifest fields.
141143
/// Creates a structure corresponding to:
142144
/// SYCL specific image descriptor type.
143145
/// \code
@@ -159,10 +161,12 @@ struct Wrapper {
159161
/// // a null-terminated string; target- and compiler-specific options
160162
/// // which are suggested to use to "link" program at runtime
161163
/// const char *LinkOptions;
164+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
162165
/// // Pointer to the manifest data start
163166
/// const unsigned char *ManifestStart;
164167
/// // Pointer to the manifest data end
165168
/// const unsigned char *ManifestEnd;
169+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
166170
/// // Pointer to the device binary image start
167171
/// void *ImageStart;
168172
/// // Pointer to the device binary image end
@@ -175,24 +179,43 @@ struct Wrapper {
175179
/// };
176180
/// \endcode
177181
StructType *getSyclDeviceImageTy() {
178-
return StructType::create(
179-
{
180-
Type::getInt16Ty(C), // Version
181-
Type::getInt8Ty(C), // OffloadKind
182-
Type::getInt8Ty(C), // Format
183-
PointerType::getUnqual(C), // DeviceTargetSpec
184-
PointerType::getUnqual(C), // CompileOptions
185-
PointerType::getUnqual(C), // LinkOptions
186-
PointerType::getUnqual(C), // ManifestStart
187-
PointerType::getUnqual(C), // ManifestEnd
188-
PointerType::getUnqual(C), // ImageStart
189-
PointerType::getUnqual(C), // ImageEnd
190-
PointerType::getUnqual(C), // EntriesBegin
191-
PointerType::getUnqual(C), // EntriesEnd
192-
PointerType::getUnqual(C), // PropertySetBegin
193-
PointerType::getUnqual(C) // PropertySetEnd
194-
},
195-
"__sycl.tgt_device_image");
182+
if (!PreviewBreakingChanges) {
183+
return StructType::create(
184+
{
185+
Type::getInt16Ty(C), // Version
186+
Type::getInt8Ty(C), // OffloadKind
187+
Type::getInt8Ty(C), // Format
188+
PointerType::getUnqual(C), // DeviceTargetSpec
189+
PointerType::getUnqual(C), // CompileOptions
190+
PointerType::getUnqual(C), // LinkOptions
191+
PointerType::getUnqual(C), // ManifestStart
192+
PointerType::getUnqual(C), // ManifestEnd
193+
PointerType::getUnqual(C), // ImageStart
194+
PointerType::getUnqual(C), // ImageEnd
195+
PointerType::getUnqual(C), // EntriesBegin
196+
PointerType::getUnqual(C), // EntriesEnd
197+
PointerType::getUnqual(C), // PropertySetBegin
198+
PointerType::getUnqual(C) // PropertySetEnd
199+
},
200+
"__sycl.tgt_device_image");
201+
} else {
202+
return StructType::create(
203+
{
204+
Type::getInt16Ty(C), // Version
205+
Type::getInt8Ty(C), // OffloadKind
206+
Type::getInt8Ty(C), // Format
207+
PointerType::getUnqual(C), // DeviceTargetSpec
208+
PointerType::getUnqual(C), // CompileOptions
209+
PointerType::getUnqual(C), // LinkOptions
210+
PointerType::getUnqual(C), // ImageStart
211+
PointerType::getUnqual(C), // ImageEnd
212+
PointerType::getUnqual(C), // EntriesBegin
213+
PointerType::getUnqual(C), // EntriesEnd
214+
PointerType::getUnqual(C), // PropertySetBegin
215+
PointerType::getUnqual(C) // PropertySetEnd
216+
},
217+
"__sycl.tgt_device_image");
218+
}
196219
}
197220

198221
/// Creates a structure for SYCL specific binary descriptor type. Corresponds
@@ -545,7 +568,12 @@ struct Wrapper {
545568
auto *NullPtr = Constant::getNullValue(PointerType::getUnqual(C));
546569
// DeviceImageStructVersion change log:
547570
// -- version 2: updated to PI 1.2 binary image format
548-
constexpr uint16_t DeviceImageStructVersion = 2;
571+
// -- version 3: removed ManifestStart, ManifestEnd pointers
572+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
573+
uint16_t DeviceImageStructVersion = PreviewBreakingChanges ? 3 : 2;
574+
#else // __INTEL_PREVIEW_BREAKING_CHANGES
575+
constexpr uint16_t DeviceImageStructVersion = 3;
576+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
549577
constexpr uint8_t SYCLOffloadKind = 4; // Corresponds to SYCL
550578
auto *Version =
551579
ConstantInt::get(Type::getInt16Ty(C), DeviceImageStructVersion);
@@ -573,20 +601,27 @@ struct Wrapper {
573601
Twine(OffloadKindTag) + ImageID + ".data", Image.Target);
574602
}
575603

576-
// TODO: Manifests are going to be removed.
577-
// Note: Manifests are deprecated but corresponding nullptr fields should
578-
// remain to comply ABI.
604+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
579605
std::pair<Constant *, Constant *> Manifests = {NullPtr, NullPtr};
606+
#endif
580607

581608
// For SYCL image offload entries are defined here, by wrapper, so
582609
// those are created per image
583610
std::pair<Constant *, Constant *> ImageEntriesPtrs =
584611
addOffloadEntriesToModule(Image.Entries);
585-
Constant *WrappedImage = ConstantStruct::get(
586-
SyclDeviceImageTy, Version, Kind, Format, Target, CompileOptions,
587-
LinkOptions, Manifests.first, Manifests.second, Binary.first,
588-
Binary.second, ImageEntriesPtrs.first, ImageEntriesPtrs.second,
589-
PropSets.first, PropSets.second);
612+
Constant *WrappedImage =
613+
PreviewBreakingChanges
614+
? ConstantStruct::get(
615+
SyclDeviceImageTy, Version, Kind, Format, Target,
616+
CompileOptions, LinkOptions, Binary.first, Binary.second,
617+
ImageEntriesPtrs.first, ImageEntriesPtrs.second,
618+
PropSets.first, PropSets.second)
619+
: ConstantStruct::get(
620+
SyclDeviceImageTy, Version, Kind, Format, Target,
621+
CompileOptions, LinkOptions, Manifests.first,
622+
Manifests.second, Binary.first, Binary.second,
623+
ImageEntriesPtrs.first, ImageEntriesPtrs.second,
624+
PropSets.first, PropSets.second);
590625

591626
if (Options.EmitRegistrationFunctions)
592627
emitRegistrationFunctions(Binary.first, Image.Image->getBufferSize(),
@@ -648,7 +683,11 @@ struct Wrapper {
648683
/// ...
649684
/// static const char ImageN[] = { <Bufs.back() contents> };
650685
///
686+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
651687
/// static constexpr uint16_t Version = 2;
688+
#else // __INTEL_PREVIEW_BREAKING_CHANGES
689+
/// static constexpr uint16_t Version = 3;
690+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
652691
/// static constexpr uint16_t OffloadKind = 4; // SYCL
653692
///
654693
/// static const __sycl.tgt_device_image Images[] = {
@@ -660,8 +699,10 @@ struct Wrapper {
660699
// NULL, /*DeviceTargetSpec*/
661700
/// CompileOptions0, /*CompileOptions0*/
662701
/// LinkOptions0, /*LinkOptions0*/
702+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
663703
/// NULL, /*ManifestStart*/
664704
/// NULL, /*ManifestEnd*/
705+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
665706
/// Image0, /*ImageStart*/
666707
/// Image0 + sizeof(Image0), /*ImageEnd*/
667708
/// __start_offloading_entries0, /*EntriesBegin*/
@@ -785,7 +826,9 @@ struct Wrapper {
785826

786827
Error llvm::offloading::wrapSYCLBinaries(llvm::Module &M,
787828
const SmallVector<SYCLImage> &Images,
788-
SYCLWrappingOptions Options) {
829+
SYCLWrappingOptions Options,
830+
bool _PreviewBreakingChanges) {
831+
PreviewBreakingChanges = _PreviewBreakingChanges;
789832
Wrapper W(M, Options);
790833
GlobalVariable *Desc = W.createFatbinDesc(Images);
791834
if (!Desc)

sycl/source/detail/compiler.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ enum sycl_device_binary_type : uint8_t {
190190
};
191191

192192
// Device binary descriptor version supported by this library.
193+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
193194
static const uint16_t SYCL_DEVICE_BINARY_VERSION = 1;
195+
#else // __INTEL_PREVIEW_BREAKING_CHANGES
196+
static const uint16_t SYCL_DEVICE_BINARY_VERSION = 3;
197+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
194198

195199
// The kind of offload model the binary employs; must be 4 for SYCL
196200
static const uint8_t SYCL_DEVICE_BINARY_OFFLOAD_KIND_SYCL = 4;
@@ -227,10 +231,12 @@ struct sycl_device_binary_struct {
227231
/// a null-terminated string; target- and compiler-specific options
228232
/// which are suggested to use to "link" program at runtime
229233
const char *LinkOptions;
234+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
230235
/// Pointer to the manifest data start
231236
const char *ManifestStart;
232237
/// Pointer to the manifest data end
233238
const char *ManifestEnd;
239+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
234240
/// Pointer to the target code start
235241
const unsigned char *BinaryStart;
236242
/// Pointer to the target code end

sycl/source/detail/device_binary_image.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,10 @@ DynRTDeviceBinaryImage::DynRTDeviceBinaryImage()
219219
Bin->Kind = SYCL_DEVICE_BINARY_OFFLOAD_KIND_SYCL;
220220
Bin->CompileOptions = "";
221221
Bin->LinkOptions = "";
222+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
222223
Bin->ManifestStart = nullptr;
223224
Bin->ManifestEnd = nullptr;
225+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
224226
Bin->BinaryStart = nullptr;
225227
Bin->BinaryEnd = nullptr;
226228
Bin->EntriesBegin = nullptr;

sycl/source/detail/jit_device_binaries.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ sycl_device_binary_struct DeviceBinaryContainer::getPIDeviceBinary(
110110
DeviceBinary.Format = Format;
111111
DeviceBinary.CompileOptions = CompileOptions ? CompileOptions.get() : "";
112112
DeviceBinary.LinkOptions = "";
113+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
113114
DeviceBinary.ManifestStart = nullptr;
114115
DeviceBinary.ManifestEnd = nullptr;
116+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
115117
// It is safe to use these pointers here, as their lifetime is managed by
116118
// the JITContext.
117119
DeviceBinary.BinaryStart = BinaryStart;

sycl/source/detail/syclbin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,10 @@ SYCLBINBinaries::SYCLBINBinaries(const char *SYCLBINContent, size_t SYCLBINSize)
295295
__SYCL_DEVICE_BINARY_TARGET_SPIRV64; // TODO: Determine.
296296
DeviceBinary.CompileOptions = nullptr;
297297
DeviceBinary.LinkOptions = nullptr;
298+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
298299
DeviceBinary.ManifestStart = nullptr;
299300
DeviceBinary.ManifestEnd = nullptr;
301+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
300302
DeviceBinary.BinaryStart =
301303
reinterpret_cast<const unsigned char *>(IRM.RawIRBytes.data());
302304
DeviceBinary.BinaryEnd = reinterpret_cast<const unsigned char *>(
@@ -329,8 +331,10 @@ SYCLBINBinaries::SYCLBINBinaries(const char *SYCLBINContent, size_t SYCLBINSize)
329331
getDeviceTargetSpecFromTriple(TargetTriple);
330332
DeviceBinary.CompileOptions = nullptr;
331333
DeviceBinary.LinkOptions = nullptr;
334+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
332335
DeviceBinary.ManifestStart = nullptr;
333336
DeviceBinary.ManifestEnd = nullptr;
337+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
334338
DeviceBinary.BinaryStart = reinterpret_cast<const unsigned char *>(
335339
NDCI.RawDeviceCodeImageBytes.data());
336340
DeviceBinary.BinaryEnd = reinterpret_cast<const unsigned char *>(

sycl/unittests/compression/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ add_sycl_unittest(CompressionTests OBJECT
22
CompressionTests.cpp
33
)
44
target_compile_definitions(CompressionTests_non_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)
5-
target_compile_definitions(CompressionTests_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)
5+
target_compile_definitions(CompressionTests_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE __INTEL_PREVIEW_BREAKING_CHANGES)

sycl/unittests/compression/CompressionTests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,20 @@ TEST(CompressionTest, ConcurrentDecompressionOfDeviceImage) {
135135
_sycl_offload_entry_struct EntryStruct = {
136136
/*addr*/ nullptr, const_cast<char *>(EntryName), strlen(EntryName),
137137
/*flags*/ 0, /*reserved*/ 0};
138+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
138139
sycl_device_binary_struct BinStruct{/*Version*/ 1,
140+
#else
141+
sycl_device_binary_struct BinStruct{/*Version*/ 3,
142+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
139143
/*Kind*/ 4,
140144
/*Format*/ SYCL_DEVICE_BINARY_TYPE_SPIRV,
141145
/*DeviceTargetSpec*/ nullptr,
142146
/*CompileOptions*/ nullptr,
143147
/*LinkOptions*/ nullptr,
148+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
144149
/*ManifestStart*/ nullptr,
145150
/*ManifestEnd*/ nullptr,
151+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
146152
/*BinaryStart*/ compressedDataPtr,
147153
/*BinaryEnd*/ compressedDataPtr +
148154
compressedSize,

0 commit comments

Comments
 (0)