Skip to content

Commit eeb5d84

Browse files
authored
[HIP] compressed bundle format defaults to v3 (llvm#3503)
2 parents 7e0e42b + d785555 commit eeb5d84

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

clang/docs/ClangOffloadBundler.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,15 @@ The compressed offload bundle begins with a header followed by the compressed bi
525525
This is a unique identifier to distinguish compressed offload bundles. The value is the string 'CCOB' (Compressed Clang Offload Bundle).
526526

527527
- **Version Number (16-bit unsigned int)**:
528-
This denotes the version of the compressed offload bundle format. The current version is `2`.
528+
This denotes the version of the compressed offload bundle format. The current version is `3`.
529529

530530
- **Compression Method (16-bit unsigned int)**:
531531
This field indicates the compression method used. The value corresponds to either `zlib` or `zstd`, represented as a 16-bit unsigned integer cast from the LLVM compression enumeration.
532532

533-
- **Total File Size (32-bit unsigned int)**:
533+
- **Total File Size (unsigned int, 32-bit in v2, 64-bit in v3)**:
534534
This is the total size (in bytes) of the file, including the header. Available in version 2 and above.
535535

536-
- **Uncompressed Binary Size (32-bit unsigned int)**:
536+
- **Uncompressed Binary Size (unsigned int, 32-bit in v2, 64-bit in v3)**:
537537
This is the size (in bytes) of the binary data before it was compressed.
538538

539539
- **Hash (64-bit unsigned int)**:
@@ -542,4 +542,4 @@ The compressed offload bundle begins with a header followed by the compressed bi
542542
- **Compressed Data**:
543543
The actual compressed binary data follows the header. Its size can be inferred from the total size of the file minus the header size.
544544

545-
> **Note**: Version 3 of the format is under development. It uses 64-bit fields for Total File Size and Uncompressed Binary Size to support files larger than 4GB. To experiment with version 3, set the environment variable `COMPRESSED_BUNDLE_FORMAT_VERSION=3`. This support is experimental and not recommended for production use.
545+
> **Note**: Version 3 is now the default format. For backward compatibility with older HIP runtimes that support version 2 only, set the environment variable `COMPRESSED_BUNDLE_FORMAT_VERSION=2`.

clang/include/clang/Driver/OffloadBundler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class CompressedOffloadBundle {
136136

137137
static inline const llvm::StringRef MagicNumber = "CCOB";
138138

139-
static inline const uint16_t DefaultVersion = 2;
139+
static inline const uint16_t DefaultVersion = 3;
140140

141141
// Helper method to get header size based on version
142142
static size_t getHeaderSize(uint16_t Version) {

clang/test/Driver/clang-offload-bundler-zlib.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,30 @@
6666
// NOHOST-V3-DAG: hip-amdgcn-amd-amdhsa--gfx900
6767
// NOHOST-V3-DAG: hip-amdgcn-amd-amdhsa--gfx906
6868

69+
// Check compression/decompression of offload bundle using version 2 format.
70+
//
71+
// RUN: env OFFLOAD_BUNDLER_COMPRESS=1 OFFLOAD_BUNDLER_VERBOSE=1 COMPRESSED_BUNDLE_FORMAT_VERSION=2 \
72+
// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
73+
// RUN: -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc 2>&1 | \
74+
// RUN: FileCheck -check-prefix=COMPRESS-V2 %s
75+
// RUN: clang-offload-bundler -type=bc -list -input=%t.hip.bundle.bc | FileCheck -check-prefix=NOHOST-V2 %s
76+
// RUN: env OFFLOAD_BUNDLER_VERBOSE=1 \
77+
// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \
78+
// RUN: -output=%t.res.tgt1 -output=%t.res.tgt2 -input=%t.hip.bundle.bc -unbundle 2>&1 | \
79+
// RUN: FileCheck -check-prefix=DECOMPRESS-V2 %s
80+
// RUN: diff %t.tgt1 %t.res.tgt1
81+
// RUN: diff %t.tgt2 %t.res.tgt2
82+
//
83+
// COMPRESS-V2: Compressed bundle format version: 2
84+
// COMPRESS-V2: Compression method used: zlib
85+
// COMPRESS-V2: Compression level: 6
86+
// DECOMPRESS-V2: Compressed bundle format version: 2
87+
// DECOMPRESS-V2: Decompression method: zlib
88+
// DECOMPRESS-V2: Hashes match: Yes
89+
// NOHOST-V2-NOT: host-
90+
// NOHOST-V2-DAG: hip-amdgcn-amd-amdhsa--gfx900
91+
// NOHOST-V2-DAG: hip-amdgcn-amd-amdhsa--gfx906
92+
6993
// Check -compression-level= option
7094

7195
// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx900,hip-amdgcn-amd-amdhsa--gfx906 \

clang/test/Driver/clang-offload-bundler-zstd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
// RUN: diff %t.tgt1 %t.res.tgt1
3030
// RUN: diff %t.tgt2 %t.res.tgt2
3131
//
32-
// CHECK: Compressed bundle format version: 2
32+
// CHECK: Compressed bundle format version: 3
3333
// CHECK: Total file size (including headers): [[SIZE:[0-9]*]] bytes
3434
// CHECK: Compression method used: zstd
3535
// CHECK: Compression level: 3
36-
// CHECK: Compressed bundle format version: 2
36+
// CHECK: Compressed bundle format version: 3
3737
// CHECK: Total file size (from header): [[SIZE]] bytes
3838
// CHECK: Decompression method: zstd
3939
// CHECK: Hashes match: Yes

0 commit comments

Comments
 (0)