Skip to content

Commit fbc93e3

Browse files
authored
Merge branch 'release/rocm-rel-7.0' into amd/dev/chfang/opsel-cp
2 parents f854571 + 06da02d commit fbc93e3

File tree

11 files changed

+433
-210
lines changed

11 files changed

+433
-210
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
253253

254254
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
255255
CUMode = !(GPUFeatures & llvm::AMDGPU::FEATURE_WGP);
256-
for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"})
257-
ReadOnlyFeatures.insert(F);
256+
257+
for (auto F : {"image-insts", "gws", "vmem-to-lds-load-insts"}) {
258+
if (GPUKind != llvm::AMDGPU::GK_NONE)
259+
ReadOnlyFeatures.insert(F);
260+
}
258261
HalfArgsAndReturns = true;
259262
}
260263

clang/test/CodeGenOpenCL/amdgpu-features-readonly.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple amdgcn -target-feature +gws -o /dev/null %s 2>&1 \
1+
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx942 -target-feature +gws -o /dev/null %s 2>&1 \
22
// RUN: | FileCheck --check-prefix=GWS %s
33

44
// GWS: warning: feature flag '+gws' is ignored since the feature is read only [-Winvalid-command-line-argument]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: amdgpu-registered-target
2+
3+
// Check the readonly feature will can be written to the IR
4+
// if there is no target specified.
5+
6+
// RUN: %clang_cc1 -triple amdgcn -emit-llvm -o - %s | FileCheck --check-prefix=NOCPU %s
7+
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx942 -emit-llvm -o - %s | FileCheck --check-prefix=GFX942 %s
8+
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1100 -emit-llvm -o - %s | FileCheck --check-prefix=GFX1100 %s
9+
// RUN: %clang_cc1 -triple amdgcn -target-cpu gfx1200 -emit-llvm -o - %s | FileCheck --check-prefix=GFX1200 %s
10+
11+
__attribute__((target("gws,image-insts,vmem-to-lds-load-insts"))) void test() {}
12+
13+
// NOCPU: "target-features"="+gws,+image-insts,+vmem-to-lds-load-insts"
14+
// GFX942: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+fp8-conversion-insts,+fp8-insts,+gfx8-insts,+gfx9-insts,+gfx90a-insts,+gfx940-insts,+mai-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,+xf32-insts"
15+
// GFX1100: "target-features"="+16-bit-insts,+atomic-fadd-rtn-insts,+ci-insts,+dl-insts,+dot10-insts,+dot12-insts,+dot5-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"
16+
// GFX1200: "target-features"="+16-bit-insts,+atomic-buffer-global-pk-add-f16-insts,+atomic-buffer-pk-add-bf16-inst,+atomic-ds-pk-add-16-insts,+atomic-fadd-rtn-insts,+atomic-flat-pk-add-16-insts,+atomic-global-pk-add-bf16-inst,+ci-insts,+dl-insts,+dot10-insts,+dot11-insts,+dot12-insts,+dot7-insts,+dot8-insts,+dot9-insts,+dpp,+fp8-conversion-insts,+gfx10-3-insts,+gfx10-insts,+gfx11-insts,+gfx12-insts,+gfx8-insts,+gfx9-insts,+wavefrontsize32"

llvm/include/llvm/Object/OffloadBundle.h

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,56 @@ namespace llvm {
3131

3232
namespace object {
3333

34+
// CompressedOffloadBundle represents the format for the compressed offload
35+
// bundles.
36+
//
37+
// The format is as follows:
38+
// - Magic Number (4 bytes) - A constant "CCOB".
39+
// - Version (2 bytes)
40+
// - Compression Method (2 bytes) - Uses the values from
41+
// llvm::compression::Format.
42+
// - Total file size (4 bytes in V2, 8 bytes in V3).
43+
// - Uncompressed Size (4 bytes in V1/V2, 8 bytes in V3).
44+
// - Truncated MD5 Hash (8 bytes).
45+
// - Compressed Data (variable length).
3446
class CompressedOffloadBundle {
3547
private:
36-
static inline const size_t MagicSize = 4;
37-
static inline const size_t VersionFieldSize = sizeof(uint16_t);
38-
static inline const size_t MethodFieldSize = sizeof(uint16_t);
39-
static inline const size_t FileSizeFieldSize = sizeof(uint32_t);
40-
static inline const size_t UncompressedSizeFieldSize = sizeof(uint32_t);
41-
static inline const size_t HashFieldSize = sizeof(uint64_t);
42-
static inline const size_t V1HeaderSize =
43-
MagicSize + VersionFieldSize + MethodFieldSize +
44-
UncompressedSizeFieldSize + HashFieldSize;
45-
static inline const size_t V2HeaderSize =
46-
MagicSize + VersionFieldSize + FileSizeFieldSize + MethodFieldSize +
47-
UncompressedSizeFieldSize + HashFieldSize;
4848
static inline const llvm::StringRef MagicNumber = "CCOB";
49-
static inline const uint16_t Version = 2;
5049

5150
public:
51+
struct CompressedBundleHeader {
52+
unsigned Version;
53+
llvm::compression::Format CompressionFormat;
54+
std::optional<size_t> FileSize;
55+
size_t UncompressedFileSize;
56+
uint64_t Hash;
57+
58+
static llvm::Expected<CompressedBundleHeader> tryParse(llvm::StringRef);
59+
};
60+
61+
static inline const uint16_t DefaultVersion = 2;
62+
5263
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
5364
compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,
54-
bool Verbose = false);
65+
uint16_t Version, bool Verbose = false);
5566
static llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
56-
decompress(llvm::MemoryBufferRef &Input, bool Verbose = false);
67+
decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
5768
};
5869

5970
/// Bundle entry in binary clang-offload-bundler format.
6071
struct OffloadBundleEntry {
6172
uint64_t Offset = 0u;
6273
uint64_t Size = 0u;
6374
uint64_t IDLength = 0u;
64-
StringRef ID;
65-
OffloadBundleEntry(uint64_t O, uint64_t S, uint64_t I, StringRef T)
66-
: Offset(O), Size(S), IDLength(I), ID(T) {}
75+
std::string ID;
76+
OffloadBundleEntry(uint64_t O, uint64_t S, uint64_t I, std::string T)
77+
: Offset(O), Size(S), IDLength(I) {
78+
ID.reserve(T.size());
79+
ID = T;
80+
}
6781
void dumpInfo(raw_ostream &OS) {
6882
OS << "Offset = " << Offset << ", Size = " << Size
69-
<< ", ID Length = " << IDLength << ", ID = " << ID;
83+
<< ", ID Length = " << IDLength << ", ID = " << ID << "\n";
7084
}
7185
void dumpURI(raw_ostream &OS, StringRef FilePath) {
7286
OS << ID.data() << "\tfile://" << FilePath << "#offset=" << Offset
@@ -81,16 +95,21 @@ class OffloadBundleFatBin {
8195
StringRef FileName;
8296
uint64_t NumberOfEntries;
8397
SmallVector<OffloadBundleEntry> Entries;
98+
bool Decompressed;
8499

85100
public:
101+
std::unique_ptr<MemoryBuffer> DecompressedBuffer;
102+
86103
SmallVector<OffloadBundleEntry> getEntries() { return Entries; }
87104
uint64_t getSize() const { return Size; }
88105
StringRef getFileName() const { return FileName; }
89106
uint64_t getNumEntries() const { return NumberOfEntries; }
107+
bool isDecompressed() const { return Decompressed; }
90108

91-
static Expected<std::unique_ptr<OffloadBundleFatBin>>
92-
create(MemoryBufferRef, uint64_t SectionOffset, StringRef FileName);
93-
Error extractBundle(const ObjectFile &Source);
109+
LLVM_ABI static Expected<std::unique_ptr<OffloadBundleFatBin>>
110+
create(MemoryBufferRef, uint64_t SectionOffset, StringRef FileName,
111+
bool Decompress = false);
112+
LLVM_ABI Error extractBundle(const ObjectFile &Source);
94113

95114
Error dumpEntryToCodeObject();
96115

@@ -105,9 +124,15 @@ class OffloadBundleFatBin {
105124
Entry.dumpURI(outs(), FileName);
106125
}
107126

108-
OffloadBundleFatBin(MemoryBufferRef Source, StringRef File)
109-
: FileName(File), NumberOfEntries(0),
110-
Entries(SmallVector<OffloadBundleEntry>()) {}
127+
OffloadBundleFatBin(MemoryBufferRef Source, StringRef File,
128+
bool Decompress = false)
129+
: FileName(File), Decompressed(Decompress), NumberOfEntries(0),
130+
Entries(SmallVector<OffloadBundleEntry>()) {
131+
if (Decompress) {
132+
DecompressedBuffer =
133+
MemoryBuffer::getMemBufferCopy(Source.getBuffer(), File);
134+
}
135+
}
111136
};
112137

113138
enum UriTypeT { FILE_URI, MEMORY_URI };
@@ -190,6 +215,10 @@ Error extractOffloadBundleFatBinary(
190215
Error extractCodeObject(const ObjectFile &Source, int64_t Offset, int64_t Size,
191216
StringRef OutputFileName);
192217

218+
/// Extract code object memory from the given \p Source object file at \p Offset
219+
/// and of \p Size, and copy into \p OutputFileName.
220+
LLVM_ABI Error extractCodeObject(MemoryBufferRef Buffer, int64_t Offset,
221+
int64_t Size, StringRef OutputFileName);
193222
/// Extracts an Offload Bundle Entry given by URI
194223
Error extractOffloadBundleByURI(StringRef URIstr);
195224

0 commit comments

Comments
 (0)