Skip to content

Commit 451c7d8

Browse files
committed
Merge branch 'sycl' into sean/usm-normalized-fix
2 parents 9d86971 + d3d9521 commit 451c7d8

File tree

51 files changed

+240
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+240
-117
lines changed

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

Lines changed: 137 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ Expected<OffloadFile> getInputBitcodeLibrary(StringRef Input) {
251251
Image.StringData["arch"] = Arch;
252252
Image.Image = std::move(*ImageOrError);
253253

254-
std::unique_ptr<MemoryBuffer> Binary =
255-
MemoryBuffer::getMemBufferCopy(OffloadBinary::write(Image));
254+
std::unique_ptr<MemoryBuffer> Binary = MemoryBuffer::getMemBufferCopy(
255+
OffloadBinary::write(Image), Image.Image->getBufferIdentifier());
256256
auto NewBinaryOrErr = OffloadBinary::create(*Binary);
257257
if (!NewBinaryOrErr)
258258
return NewBinaryOrErr.takeError();
@@ -1358,6 +1358,135 @@ static Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles,
13581358
return *DeviceLinkedFile;
13591359
}
13601360

1361+
static bool isStaticArchiveFile(const StringRef Filename) {
1362+
if (!llvm::sys::path::has_extension(Filename))
1363+
// Any file with no extension should not be considered an Archive.
1364+
return false;
1365+
llvm::file_magic Magic;
1366+
llvm::identify_magic(Filename, Magic);
1367+
// Only archive files are to be considered.
1368+
// TODO: .lib check to be added
1369+
return (Magic == llvm::file_magic::archive);
1370+
}
1371+
1372+
static Expected<StringRef> listSection(StringRef Filename,
1373+
const ArgList &Args) {
1374+
Expected<std::string> OffloadBundlerPath = findProgram(
1375+
"clang-offload-bundler", {getMainExecutable("clang-offload-bundler")});
1376+
if (!OffloadBundlerPath)
1377+
return OffloadBundlerPath.takeError();
1378+
BumpPtrAllocator Alloc;
1379+
StringSaver Saver(Alloc);
1380+
1381+
SmallVector<StringRef, 8> CmdArgs;
1382+
CmdArgs.push_back(*OffloadBundlerPath);
1383+
bool IsArchive = isStaticArchiveFile(Filename);
1384+
CmdArgs.push_back(IsArchive ? "-type=aoo" : "-type=o");
1385+
CmdArgs.push_back(Saver.save("-input=" + Filename));
1386+
CmdArgs.push_back("-list");
1387+
auto Output = createOutputFile("bundled-targets", "list");
1388+
if (!Output)
1389+
return Output.takeError();
1390+
SmallVector<std::optional<StringRef>> Redirects{std::nullopt, *Output,
1391+
std::nullopt};
1392+
int ErrCode = llvm::sys::ExecuteAndWait(*OffloadBundlerPath, CmdArgs,
1393+
std::nullopt, Redirects);
1394+
if (ErrCode != 0)
1395+
return createStringError(inconvertibleErrorCode(),
1396+
"Failed to list targets");
1397+
return *Output;
1398+
}
1399+
1400+
// This routine is used to run the clang-offload-bundler tool and unbundle
1401+
// device inputs that have been created with an older compiler where the
1402+
// device object is bundled into a host object.
1403+
static Expected<StringRef> unbundle(StringRef Filename, const ArgList &Args,
1404+
llvm::Triple Triple) {
1405+
Expected<std::string> OffloadBundlerPath = findProgram(
1406+
"clang-offload-bundler", {getMainExecutable("clang-offload-bundler")});
1407+
if (!OffloadBundlerPath)
1408+
return OffloadBundlerPath.takeError();
1409+
1410+
// Create a new file to write the unbundled file to.
1411+
auto TempFileOrErr =
1412+
createOutputFile(sys::path::filename(ExecutableName), "ir");
1413+
if (!TempFileOrErr)
1414+
return TempFileOrErr.takeError();
1415+
1416+
BumpPtrAllocator Alloc;
1417+
StringSaver Saver(Alloc);
1418+
1419+
SmallVector<StringRef, 8> CmdArgs;
1420+
CmdArgs.push_back(*OffloadBundlerPath);
1421+
bool IsArchive = isStaticArchiveFile(Filename);
1422+
CmdArgs.push_back(IsArchive ? "-type=aoo" : "-type=o");
1423+
auto *Target = Args.MakeArgString(Twine("-targets=sycl-") + Triple.str());
1424+
CmdArgs.push_back(Target);
1425+
CmdArgs.push_back(Saver.save("-input=" + Filename));
1426+
CmdArgs.push_back(Saver.save("-output=" + *TempFileOrErr));
1427+
CmdArgs.push_back("-unbundle");
1428+
CmdArgs.push_back("-allow-missing-bundles");
1429+
if (Error Err = executeCommands(*OffloadBundlerPath, CmdArgs))
1430+
return std::move(Err);
1431+
return *TempFileOrErr;
1432+
}
1433+
1434+
Error extractBundledObjects(StringRef Filename, const ArgList &Args,
1435+
SmallVector<OffloadFile> &Binaries) {
1436+
auto List = listSection(Filename, Args);
1437+
if (!List)
1438+
return List.takeError();
1439+
SmallVector<StringRef> TriplesInFile;
1440+
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> TripleList =
1441+
llvm::MemoryBuffer::getFileOrSTDIN(*List, /*isText=*/true);
1442+
if (std::error_code EC = TripleList.getError())
1443+
return createFileError(*List, EC);
1444+
(*TripleList)
1445+
->getBuffer()
1446+
.split(TriplesInFile, '\n', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
1447+
for (StringRef TripleStr : TriplesInFile) {
1448+
StringRef SYCLPrefix = "sycl-";
1449+
if (!TripleStr.starts_with(SYCLPrefix))
1450+
continue;
1451+
llvm::Triple Triple(TripleStr.substr(SYCLPrefix.size()));
1452+
auto UnbundledFile = unbundle(Filename, Args, Triple);
1453+
if (!UnbundledFile)
1454+
return UnbundledFile.takeError();
1455+
if (*UnbundledFile == Filename)
1456+
continue;
1457+
1458+
SmallVector<StringRef> ObjectFilePaths;
1459+
if (sycl::isStaticArchiveFile(Filename)) {
1460+
llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> ObjList =
1461+
llvm::MemoryBuffer::getFileOrSTDIN(*UnbundledFile, /*isText=*/true);
1462+
if (std::error_code EC = ObjList.getError())
1463+
return createFileError(*UnbundledFile, EC);
1464+
(*ObjList)->getBuffer().split(ObjectFilePaths, '\n', /*MaxSplit=*/-1,
1465+
/*KeepEmpty=*/false);
1466+
} else {
1467+
ObjectFilePaths.push_back(*UnbundledFile);
1468+
}
1469+
for (StringRef ObjectFilePath : ObjectFilePaths) {
1470+
llvm::file_magic Magic;
1471+
llvm::identify_magic(ObjectFilePath, Magic);
1472+
if (Magic == file_magic::spirv_object)
1473+
return createStringError(
1474+
"SPIR-V fat objects must be generated with --offload-new-driver");
1475+
auto Arg = Args.MakeArgString(
1476+
"sycl-" +
1477+
(Triple.isSPIROrSPIRV() ? Triple.str() + "-" : Triple.str()) + "=" +
1478+
ObjectFilePath);
1479+
auto Binary = getInputBitcodeLibrary(Arg);
1480+
1481+
if (!Binary)
1482+
return Binary.takeError();
1483+
1484+
Binaries.push_back(std::move(*Binary));
1485+
}
1486+
}
1487+
return Error::success();
1488+
}
1489+
13611490
} // namespace sycl
13621491

13631492
namespace generic {
@@ -2634,8 +2763,14 @@ getDeviceInput(const ArgList &Args) {
26342763
if (identify_magic(Buffer.getBuffer()) == file_magic::elf_shared_object)
26352764
continue;
26362765
SmallVector<OffloadFile> Binaries;
2766+
size_t OldSize = Binaries.size();
26372767
if (Error Err = extractOffloadBinaries(Buffer, Binaries))
26382768
return std::move(Err);
2769+
if (Binaries.size() == OldSize) {
2770+
if (Error Err = sycl::extractBundledObjects(*Filename, Args, Binaries))
2771+
return std::move(Err);
2772+
}
2773+
26392774
for (auto &OffloadFile : Binaries) {
26402775
if (identify_magic(Buffer.getBuffer()) == file_magic::archive &&
26412776
!WholeArchive)

llvm/include/llvm/SYCLLowerIR/SpecConstants.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ class SpecConstantsPass : public PassInfoMixin<SpecConstantsPass> {
7272
collectSpecConstantDefaultValuesMetadata(const Module &M,
7373
std::vector<char> &DefaultValues);
7474

75-
// Name of the metadata which holds a list of all specialization constants
76-
// (with associated information) encountered in the module
77-
static constexpr char SPEC_CONST_MD_STRING[] =
78-
"sycl.specialization-constants";
79-
8075
// Name of the metadata which indicates this module was proccessed with the
8176
// default values handing mode.
8277
static constexpr char SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING[] =

llvm/lib/SYCLLowerIR/ComputeModuleRuntimeInfo.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,11 @@ PropSetRegTy computeModuleProperties(const Module &M,
150150
PropSet.add(PropSetRegTy::SYCL_DEVICE_REQUIREMENTS,
151151
computeDeviceRequirements(M, EntryPoints).asMap());
152152
}
153-
auto *SpecConstsMD =
154-
M.getNamedMetadata(SpecConstantsPass::SPEC_CONST_MD_STRING);
155-
bool SpecConstsMet =
156-
SpecConstsMD != nullptr && SpecConstsMD->getNumOperands() != 0;
157-
if (SpecConstsMet) {
158-
// extract spec constant maps per each module
159-
SpecIDMapTy TmpSpecIDMap;
160-
SpecConstantsPass::collectSpecConstantMetadata(M, TmpSpecIDMap);
153+
154+
// extract spec constant maps per each module
155+
SpecIDMapTy TmpSpecIDMap;
156+
SpecConstantsPass::collectSpecConstantMetadata(M, TmpSpecIDMap);
157+
if (!TmpSpecIDMap.empty()) {
161158
PropSet.add(PropSetRegTy::SYCL_SPECIALIZATION_CONSTANTS, TmpSpecIDMap);
162159

163160
// Add property with the default values of spec constants

llvm/lib/SYCLLowerIR/SpecConstants.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ constexpr char SPIRV_GET_SPEC_CONST_VAL[] = "__spirv_SpecConstant";
4747
constexpr char SPIRV_GET_SPEC_CONST_COMPOSITE[] =
4848
"__spirv_SpecConstantComposite";
4949

50+
// Name of the metadata which holds a list of all specialization constants (with
51+
// associated information) encountered in the module
52+
constexpr char SPEC_CONST_MD_STRING[] = "sycl.specialization-constants";
5053
// Name of the metadata which holds a default value list of all specialization
5154
// constants encountered in the module
5255
constexpr char SPEC_CONST_DEFAULT_VAL_MD_STRING[] =
@@ -1026,9 +1029,6 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
10261029
for (const auto &P : DefaultsMetadata)
10271030
MDDefaults->addOperand(P);
10281031

1029-
if (Mode == HandlingMode::default_values)
1030-
M.getOrInsertNamedMetadata(SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING);
1031-
10321032
return IRModified ? PreservedAnalyses::none() : PreservedAnalyses::all();
10331033
}
10341034

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ processSpecConstantsWithDefaultValues(const module_split::ModuleDesc &MD) {
509509
assert(NewModuleDesc->Props.SpecConstsMet &&
510510
"This property should be true since the presence of SpecConsts "
511511
"has been checked before the run of the pass");
512+
// Add metadata to the module so we can identify it as the default value split
513+
// later.
514+
NewModuleDesc->getModule().getOrInsertNamedMetadata(
515+
SpecConstantsPass::SPEC_CONST_DEFAULT_VAL_MODULE_MD_STRING);
512516
NewModuleDesc->rebuildEntryPoints();
513517
return NewModuleDesc;
514518
}

sycl/cmake/modules/FetchUnifiedRuntime.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ if(SYCL_UR_USE_FETCH_CONTENT)
123123
# Date: Tue Aug 20 16:28:30 2024 +0100
124124
# Merge pull request #1940 from RossBrunton/ross/urcall
125125
# [XPTI] Use `ur.call` rather than `ur` in XPTI
126-
set(UNIFIED_RUNTIME_TAG 94cb7b07e5dc5712432d9793b2879916dc9b8653)
126+
set(UNIFIED_RUNTIME_TAG e3545928c8b629ef4a221b75965a3dfea008c171)
127127

128128
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
129129
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need

sycl/doc/design/CompilerAndRuntimeDesign.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ Note: Kernel naming is not fully stable for now.
776776
##### Kernel Fusion Support
777777

778778
The [experimental kernel fusion
779-
extension](../extensions/experimental/sycl_ext_codeplay_kernel_fusion.asciidoc)
779+
extension](../extensions/removed/sycl_ext_codeplay_kernel_fusion.asciidoc)
780780
also supports the CUDA and HIP backends. However, as the CUBIN, PTX and AMD assembly
781781
are not suitable input formats for the [kernel fusion JIT compiler](KernelFusionJIT.md), a
782782
suitable IR has to be added as an additional device binary.

sycl/source/detail/queue_impl.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -784,18 +784,19 @@ class queue_impl {
784784
if (Type == CGType::Barrier && !Deps.UnenqueuedCmdEvents.empty()) {
785785
Handler.depends_on(Deps.UnenqueuedCmdEvents);
786786
}
787-
if (Deps.LastBarrier)
787+
if (Deps.LastBarrier && (Type == CGType::CodeplayHostTask ||
788+
(!Deps.LastBarrier->isEnqueued())))
788789
Handler.depends_on(Deps.LastBarrier);
790+
789791
EventRet = Handler.finalize();
790792
EventImplPtr EventRetImpl = getSyclObjImpl(EventRet);
791793
if (Type == CGType::CodeplayHostTask)
792794
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
793-
else if (!EventRetImpl->isEnqueued()) {
794-
if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
795-
Deps.LastBarrier = EventRetImpl;
796-
Deps.UnenqueuedCmdEvents.clear();
797-
} else
798-
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
795+
else if (Type == CGType::Barrier || Type == CGType::BarrierWaitlist) {
796+
Deps.LastBarrier = EventRetImpl;
797+
Deps.UnenqueuedCmdEvents.clear();
798+
} else if (!EventRetImpl->isEnqueued()) {
799+
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl);
799800
}
800801
}
801802
}

sycl/test-e2e/AOT/fpga-aoc-archive-early2.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
////////////////////////////////////////////////////////////////////////////////
1919
////////////////////////////////////////////////////////////////////////////////
2020
// Build any image archive binaries from early archives.
21-
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image %t_early_sub.a -o %t_early_image_sub.a
22-
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image %t_early_add.a -o %t_early_image_add.a
23-
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image %t_early_sub_x.a -o %t_early_image_sub_x.a
24-
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image %t_early_add_x.a -o %t_early_image_add_x.a
21+
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image -Wno-unused-command-line-argument %t_early_sub.a -o %t_early_image_sub.a
22+
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image -Wno-unused-command-line-argument %t_early_add.a -o %t_early_image_add.a
23+
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image -Wno-unused-command-line-argument %t_early_sub_x.a -o %t_early_image_sub_x.a
24+
// RUN: %clangxx -fintelfpga -fsycl -fsycl-link=image -Wno-unused-command-line-argument %t_early_add_x.a -o %t_early_image_add_x.a
2525
////////////////////////////////////////////////////////////////////////////////
2626
// Use a variety of archive orders
2727
////////////////////////////////////////////////////////////////////////////////

sycl/test-e2e/BFloat16/bfloat16_vec_builtins.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %{build} -fno-fast-math -o %t.out
1+
// DEFINE: %{mathflags} = %if cl_options %{/clang:-fno-fast-math%} %else %{-fno-fast-math%}
2+
// RUN: %{build} %{mathflags} -o %t.out
23
// RUN: %{run} %t.out
34

45
// Test new, ABI-breaking for all platforms.

0 commit comments

Comments
 (0)