Skip to content

Commit 5e901d9

Browse files
committed
Merge branch 'urlog' of github.com:mateuszpn/llvm into urlog
2 parents 5e1d659 + 358d73f commit 5e901d9

Some content is hidden

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

47 files changed

+640
-404
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Benchmarks
2+
3+
# This workflow is a WIP: this workflow file acts as a placeholder.
4+
5+
on: [ workflow_dispatch ]
6+
7+
jobs:
8+
do-nothing:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- run: echo 'This workflow is a WIP.'
12+

.github/workflows/ur-benchmarks-reusable.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Benchmarks Reusable
22

33
# This workflow is a WIP: This workflow file acts as a placeholder.
4+
#
5+
# This workflow is set to be merged into benchmark.yml
46

57
on: [ workflow_call ]
68

.github/workflows/ur-benchmarks.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
name: Benchmarks
22

33
# This workflow is a WIP: this workflow file acts as a placeholder.
4+
#
5+
# This workflow is set to be merged into benchmark.yml
46

57
on: [ workflow_dispatch ]
68

clang/test/Driver/linker-wrapper-sycl.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747
// RUN: clang-linker-wrapper -sycl-device-libraries=%t.devicelib.o -sycl-post-link-options="SYCL_POST_LINK_OPTIONS" -llvm-spirv-options="LLVM_SPIRV_OPTIONS" "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" -shared "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run 2>&1 | FileCheck -check-prefix=CHK-SHARED %s
4848
// CHK-SHARED: "{{.*}}clang"{{.*}} -fPIC
4949

50-
// RUN: rm %T/linker_wrapper_dump || true
51-
// RUN: clang-linker-wrapper -sycl-dump-device-code=%T/linker_wrapper_dump -sycl-device-libraries=%t.devicelib.o "--host-triple=x86_64-unknown-linux-gnu" "--triple=spir64" "--linker-path=/usr/bin/ld" -shared "--" HOST_LINKER_FLAGS "-dynamic-linker" HOST_DYN_LIB "-o" "a.out" HOST_LIB_PATH HOST_STAT_LIB %t.o --dry-run
52-
// RUN: ls %T/linker_wrapper_dump | FileCheck -check-prefix=CHK-SYCL-DUMP-DEVICE %s
53-
// CHK-SYCL-DUMP-DEVICE: {{.*}}.spv
54-
5550
/// Check for list of commands for standalone clang-linker-wrapper run for sycl (AOT for Intel GPU)
5651
// -------
5752
// Generate .o file as linker wrapper input.

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

+17-30
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static std::optional<llvm::module_split::IRSplitMode> SYCLModuleSplitMode;
151151

152152
static bool UseSYCLPostLinkTool;
153153

154-
static SmallString<128> SPIRVDumpDir;
154+
static SmallString<128> OffloadImageDumpDir;
155155

156156
using OffloadingImage = OffloadBinary::OffloadingImage;
157157

@@ -923,29 +923,6 @@ static Expected<StringRef> runLLVMToSPIRVTranslation(StringRef File,
923923
if (Error Err = executeCommands(*LLVMToSPIRVPath, CmdArgs))
924924
return std::move(Err);
925925

926-
if (!SPIRVDumpDir.empty()) {
927-
std::error_code EC =
928-
llvm::sys::fs::create_directory(SPIRVDumpDir, /*IgnoreExisting*/ true);
929-
if (EC)
930-
return createStringError(
931-
EC,
932-
formatv("failed to create dump directory. path: {0}, error_code: {1}",
933-
SPIRVDumpDir, EC.value()));
934-
935-
StringRef Sep = llvm::sys::path::get_separator();
936-
StringRef Path = *TempFileOrErr;
937-
StringRef Filename = Path.rsplit(Sep).second;
938-
SmallString<128> CopyPath = SPIRVDumpDir;
939-
CopyPath.append(Filename);
940-
EC = llvm::sys::fs::copy_file(Path, CopyPath);
941-
if (EC)
942-
return createStringError(
943-
EC,
944-
formatv(
945-
"failed to copy file. original: {0}, copy: {1}, error_code: {2}",
946-
Path, CopyPath, EC.value()));
947-
}
948-
949926
return *TempFileOrErr;
950927
}
951928

@@ -1103,6 +1080,18 @@ wrapSYCLBinariesFromFile(std::vector<module_split::SplitModule> &SplitModules,
11031080
RegularTarget = "spir64";
11041081

11051082
for (auto &SI : SplitModules) {
1083+
if (!OffloadImageDumpDir.empty()) {
1084+
StringRef CopyFrom = SI.ModuleFilePath;
1085+
SmallString<128> CopyTo = OffloadImageDumpDir;
1086+
StringRef Filename = sys::path::filename(CopyFrom);
1087+
CopyTo.append(Filename);
1088+
std::error_code EC = sys::fs::copy_file(CopyFrom, CopyTo);
1089+
if (EC)
1090+
return createStringError(EC, formatv("failed to copy file. From: "
1091+
"{0} to: {1}, error_code: {2}",
1092+
CopyFrom, CopyTo, EC.value()));
1093+
}
1094+
11061095
auto MBOrDesc = MemoryBuffer::getFile(SI.ModuleFilePath);
11071096
if (!MBOrDesc)
11081097
return createFileError(SI.ModuleFilePath, MBOrDesc.getError());
@@ -2618,13 +2607,11 @@ int main(int Argc, char **Argv) {
26182607

26192608
if (Args.hasArg(OPT_sycl_dump_device_code_EQ)) {
26202609
Arg *A = Args.getLastArg(OPT_sycl_dump_device_code_EQ);
2621-
SmallString<128> Dir(A->getValue());
2622-
if (Dir.empty())
2623-
llvm::sys::path::native(Dir = "./");
2610+
OffloadImageDumpDir = A->getValue();
2611+
if (OffloadImageDumpDir.empty())
2612+
sys::path::native(OffloadImageDumpDir = "./");
26242613
else
2625-
Dir.append(llvm::sys::path::get_separator());
2626-
2627-
SPIRVDumpDir = Dir;
2614+
OffloadImageDumpDir.append(sys::path::get_separator());
26282615
}
26292616

26302617
{

clang/tools/clang-linker-wrapper/LinkerWrapperOpts.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Flags<[WrapperOnlyOption]>, HelpText<"Embed LLVM IR for runtime kernel fusion">
242242

243243
def sycl_dump_device_code_EQ : Joined<["--", "-"], "sycl-dump-device-code=">,
244244
Flags<[WrapperOnlyOption]>,
245-
HelpText<"Path to the folder where the tool dumps SPIR-V device code. Other formats aren't dumped.">;
245+
HelpText<"Directory to dump offloading images to.">;
246246

247247
// Options to enable/disable device dynamic linking.
248248
def sycl_allow_device_image_dependencies : Flag<["--", "-"], "sycl-allow-device-image-dependencies">,

llvm/lib/SYCLLowerIR/ESIMD/ESIMDVerifier.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ static const char *LegalSYCLFunctionsInStatelessMode[] = {
8989

9090
namespace {
9191

92+
class BuffDeleter {
93+
public:
94+
BuffDeleter(char *Buffer) : Buff(Buffer) {};
95+
~BuffDeleter() { std::free(Buff); };
96+
97+
BuffDeleter() = delete;
98+
BuffDeleter(const BuffDeleter &) = delete;
99+
BuffDeleter(BuffDeleter &&) = delete;
100+
101+
private:
102+
char *Buff;
103+
};
104+
92105
class ESIMDVerifierImpl {
93106
const Module &M;
94107
bool MayNeedForceStatelessMemModeAPI;
@@ -149,6 +162,7 @@ class ESIMDVerifierImpl {
149162
continue;
150163

151164
id::OutputBuffer NameBuf;
165+
BuffDeleter NameBufDeleter(NameBuf.getBuffer());
152166
NameNode->print(NameBuf);
153167
StringRef Name(NameBuf.getBuffer(), NameBuf.getCurrentPosition());
154168

llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp

+72-2
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,19 @@ struct ThreadSanitizerOnSpirv {
118118

119119
void initialize();
120120

121-
void instrumentKernelsMetadata();
121+
void instrumentModule();
122122

123123
void appendDebugInfoToArgs(Instruction *I, SmallVectorImpl<Value *> &Args);
124124

125125
private:
126+
void instrumentGlobalVariables();
127+
128+
void instrumentKernelsMetadata();
129+
126130
bool isSupportedSPIRKernel(Function &F);
127131

132+
bool isUnsupportedDeviceGlobal(const GlobalVariable &G);
133+
128134
GlobalVariable *GetOrCreateGlobalString(StringRef Name, StringRef Value,
129135
unsigned AddressSpace);
130136

@@ -243,7 +249,7 @@ PreservedAnalyses ModuleThreadSanitizerPass::run(Module &M,
243249
return PreservedAnalyses::all();
244250
if (Triple(M.getTargetTriple()).isSPIROrSPIRV()) {
245251
ThreadSanitizerOnSpirv Spirv(M);
246-
Spirv.instrumentKernelsMetadata();
252+
Spirv.instrumentModule();
247253
} else
248254
insertModuleCtor(M);
249255
return PreservedAnalyses::none();
@@ -327,6 +333,70 @@ bool ThreadSanitizerOnSpirv::isSupportedSPIRKernel(Function &F) {
327333
return true;
328334
}
329335

336+
bool ThreadSanitizerOnSpirv::isUnsupportedDeviceGlobal(
337+
const GlobalVariable &G) {
338+
if (G.user_empty())
339+
return true;
340+
// Skip instrumenting on "__TsanKernelMetadata" etc.
341+
if (G.getName().starts_with("__Tsan"))
342+
return true;
343+
if (G.getName().starts_with("__tsan_"))
344+
return true;
345+
if (G.getName().starts_with("__spirv_BuiltIn"))
346+
return true;
347+
if (G.getName().starts_with("__usid_str"))
348+
return true;
349+
// TODO: Will support global variable with local address space later.
350+
if (G.getAddressSpace() == kSpirOffloadLocalAS)
351+
return true;
352+
// Global variables have constant value or constant address space will not
353+
// trigger race condition.
354+
if (G.isConstant() || G.getAddressSpace() == kSpirOffloadConstantAS)
355+
return true;
356+
return false;
357+
}
358+
359+
void ThreadSanitizerOnSpirv::instrumentModule() {
360+
instrumentGlobalVariables();
361+
instrumentKernelsMetadata();
362+
}
363+
364+
void ThreadSanitizerOnSpirv::instrumentGlobalVariables() {
365+
SmallVector<Constant *, 8> DeviceGlobalMetadata;
366+
367+
// Device global metadata is described by a structure
368+
// size_t device_global_size
369+
// size_t beginning address of the device global
370+
StructType *StructTy = StructType::get(IntptrTy, IntptrTy);
371+
372+
for (auto &G : M.globals()) {
373+
if (isUnsupportedDeviceGlobal(G)) {
374+
for (auto *User : G.users())
375+
if (auto *Inst = dyn_cast<Instruction>(User))
376+
Inst->setNoSanitizeMetadata();
377+
continue;
378+
}
379+
380+
DeviceGlobalMetadata.push_back(ConstantStruct::get(
381+
StructTy,
382+
ConstantInt::get(IntptrTy, DL.getTypeAllocSize(G.getValueType())),
383+
ConstantExpr::getPointerCast(&G, IntptrTy)));
384+
}
385+
386+
if (DeviceGlobalMetadata.empty())
387+
return;
388+
389+
// Create meta data global to record device globals' information
390+
ArrayType *ArrayTy = ArrayType::get(StructTy, DeviceGlobalMetadata.size());
391+
Constant *MetadataInitializer =
392+
ConstantArray::get(ArrayTy, DeviceGlobalMetadata);
393+
GlobalVariable *MsanDeviceGlobalMetadata = new GlobalVariable(
394+
M, MetadataInitializer->getType(), false, GlobalValue::AppendingLinkage,
395+
MetadataInitializer, "__TsanDeviceGlobalMetadata", nullptr,
396+
GlobalValue::NotThreadLocal, 1);
397+
MsanDeviceGlobalMetadata->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
398+
}
399+
330400
void ThreadSanitizerOnSpirv::instrumentKernelsMetadata() {
331401
SmallVector<Constant *, 8> SpirKernelsMetadata;
332402

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: opt < %s -passes='function(tsan),module(tsan-module)' -tsan-instrument-func-entry-exit=0 -tsan-instrument-memintrinsics=0 -S | FileCheck %s
2+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64-G1"
3+
target triple = "spir64-unknown-unknown"
4+
5+
@dev_global = external addrspace(1) global { [4 x i32] }
6+
@dev_global_no_users = dso_local addrspace(1) global { [4 x i32] } zeroinitializer
7+
@.str = external addrspace(1) constant [59 x i8]
8+
@__spirv_BuiltInGlobalInvocationId = external addrspace(1) constant <3 x i64>
9+
10+
; CHECK: @__TsanDeviceGlobalMetadata
11+
; CHECK-NOT: @dev_global_no_users
12+
; CHECK-NOT: @.str
13+
; CHECK-NOT: @__spirv_BuiltInGlobalInvocationId
14+
; CHECK-SAME: @dev_global
15+
16+
define spir_func void @test() {
17+
entry:
18+
%call = call spir_func ptr addrspace(4) null(ptr addrspace(4) addrspacecast (ptr addrspace(1) @dev_global to ptr addrspace(4)), i64 0)
19+
ret void
20+
}

sycl/doc/design/SYCL2020-SpecializationConstants.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ as:
8080
[sycl-2020-spec-constant-glossary]: https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#specialization-constant
8181
[sycl-2020-glossary]: https://www.khronos.org/registry/SYCL/specs/sycl-2020/html/sycl-2020.html#glossary
8282

83-
And implementation is based on [SPIR-V speficiation][spirv-spec] support
83+
And implementation is based on [SPIR-V specification][spirv-spec] support
8484
for [Specialization][spirv-specialization]. However, the specification also
8585
states the following:
8686

@@ -172,7 +172,7 @@ Based on those limitations, the following mapping design is proposed:
172172
```
173173
namespace detail {
174174
// assuming user defined the following specialization_id:
175-
// constexpr specialiation_id<int> int_const;
175+
// constexpr specialization_id<int> int_const;
176176
// class Wrapper {
177177
// public:
178178
// static constexpr specialization_id<float> float_const;
@@ -341,7 +341,7 @@ used to identify the specialization constants at SPIR-V level.
341341
As noted above one symbolic ID can have several numeric IDs assigned to it -
342342
such 1:N mapping comes from the fact that at SPIR-V level, composite
343343
specialization constants don't have dedicated IDs and they are being identified
344-
and specialized through their scalar leafs and corresponding numeric IDs.
344+
and specialized through their scalar leaves and corresponding numeric IDs.
345345

346346
For example, the following code:
347347
```
@@ -375,7 +375,7 @@ unique_symbolic_id_for_id_A -> { 1, 2, 3 }
375375

376376
As it is shown in the example above, if a composite specialization constant
377377
contains another composite within it, that nested composite is also being
378-
"flattened" and its leafs are considered to be leafs of the parent
378+
"flattened" and its leaves are considered to be leaves of the parent
379379
specialization constants. This done by depth-first search through the composite
380380
elements.
381381

@@ -509,8 +509,8 @@ constant in that buffer:
509509
```
510510
[
511511
0, // for id_int, the first constant is at the beginning of the buffer
512-
4, // sizeof(int) == 4, the second constant is located right after the fisrt one
513-
16, // sizeof(int) + sizezof(A) == 4, the same approach for the third constant
512+
4, // sizeof(int) == 4, the second constant is located right after the first one
513+
16, // sizeof(int) + sizeof(A) == 4, the same approach for the third constant
514514
]
515515
```
516516

@@ -661,9 +661,9 @@ While transforming SYCL kernel function into an OpenCL kernel, DPC++ FE should
661661
- Communicate to DPC++ RT which kernel argument should be used for passing
662662
a buffer with specialization constant values when they are emulated.
663663

664-
DPC++ FE provides implementation of `__builtin_sycl_unique_id` built-in function and
665-
it also populates special integration footer with the content required by DPC++
666-
RT for access to right device image properties describing specialization
664+
DPC++ FE provides implementation of `__builtin_sycl_unique_id` built-in function
665+
and it also populates special integration footer with the content required by
666+
DPC++ RT for access to right device image properties describing specialization
667667
constants.
668668

669669
#### SYCL Kernel function transformations
@@ -763,7 +763,7 @@ struct A {
763763
};
764764
765765
constexpr specialization_id<int> id_int;
766-
struct Wraper {
766+
struct Wrapper {
767767
public:
768768
static constexpr specialization_id<A> id_A;
769769
};
@@ -839,10 +839,10 @@ constexpr sycl::specialization_id<int> same_name{1};
839839
840840
namespace {
841841
constexpr sycl::specialization_id<int> same_name{2}:
842-
/* application code that referenes ::(unnamed)::same_name */
842+
/* application code that references ::(unnamed)::same_name */
843843
namespace {
844844
constexpr sycl::specialization_id<int> same_name{3}:
845-
/* application code that referenes ::(unnamed)::(unnamed)::same_name */
845+
/* application code that references ::(unnamed)::(unnamed)::same_name */
846846
}
847847
}
848848
@@ -899,7 +899,7 @@ namespace {
899899
900900
namespace __sycl_detail {
901901
// Sometimes we need a 'shim', which points to another 'shim' in order to
902-
// "extract" a variable from an anonymous namespace unambiguosly
902+
// "extract" a variable from an anonymous namespace unambiguously
903903
static constexpr decltype(__sycl_detail::__shim_1()) &__shim_2() {
904904
// still address of ::(unnamed)::(unnamed)::same_name;
905905
return __sycl_detail::__shim_1();
@@ -972,7 +972,7 @@ address of the specialization constant provided by user and `offset` field of
972972
the descriptor as `(char*)(SpecConstantValuesMap[SymbolicID]) + offset`.
973973

974974
That calculation is required, because at SPIR-V level composite
975-
specialization constants are respresented by several specialization constants
975+
specialization constants are represented by several specialization constants
976976
for each element of a composite, whilst on a SYCL level, the whole composite
977977
is passed by user as a single blob of data. `offset` field from properties is
978978
used to specify which exact piece of that blob should be extracted to perform
@@ -1053,7 +1053,7 @@ the translator will generate `OpSpecConstant` SPIR-V instructions with proper
10531053
OpDecorate %A.float SpecId 44 ; ID of the 2nd member
10541054
%A.i32 = OpSpecConstant %int.type 0 ; 1st member with default value
10551055
%A.float = OpSpecConstant %float.type 0.0 ; 2nd member with default value
1056-
%struct = OpSpecConstantComposite %struct.type %A.i32 %A.float ; Composite doens't need IDs or default value
1056+
%struct = OpSpecConstantComposite %struct.type %A.i32 %A.float ; Composite doesn't need IDs or default value
10571057
%1 = OpTypeFunction %int
10581058
10591059
%get = OpFunction %int None %1

sycl/include/sycl/detail/spinlock.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ namespace detail {
2626
/// std::mutex, that doesn't provide such guarantees).
2727
class SpinLock {
2828
public:
29+
bool try_lock() { return !MLock.test_and_set(std::memory_order_acquire); }
30+
2931
void lock() {
3032
while (MLock.test_and_set(std::memory_order_acquire))
3133
std::this_thread::yield();

0 commit comments

Comments
 (0)