Skip to content

Commit 3a7f64c

Browse files
committed
[Review] Add lit unbundle test
1 parent 2df06ba commit 3a7f64c

File tree

4 files changed

+175
-0
lines changed

4 files changed

+175
-0
lines changed

amd/comgr/test-lit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ add_comgr_lit_binary(source-to-bc-with-dev-libs c)
4242
add_comgr_lit_binary(spirv-translator c)
4343
add_comgr_lit_binary(compile-minimal-test c)
4444
add_comgr_lit_binary(spirv-to-reloc c)
45+
add_comgr_lit_binary(unbundle c)
4546

4647
add_dependencies(check-comgr test-lit)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
******************************************************************************/
35+
36+
#include "amd_comgr.h"
37+
#include "common.h"
38+
39+
int main(int argc, char *argv[]) {
40+
char *BundleData;
41+
size_t BundleSize;
42+
43+
if (argc < 4) {
44+
printf("Usage: %s <bc bundle> <arch> <bc output>\n", argv[0]);
45+
return -1;
46+
}
47+
48+
const char *BundlePath = argv[1];
49+
const char *Arch = argv[2];
50+
const char *BitcodePath = argv[3];
51+
52+
amd_comgr_data_t OneBundle;
53+
amd_comgr_data_set_t InputBundles;
54+
55+
BundleSize = setBuf(BundlePath, &BundleData);
56+
57+
amd_comgr_(create_data_set(&InputBundles));
58+
amd_comgr_(create_data(AMD_COMGR_DATA_KIND_BC_BUNDLE, &OneBundle));
59+
amd_comgr_(set_data(OneBundle, BundleSize, BundleData));
60+
amd_comgr_(set_data_name(OneBundle, "bundle.bc"));
61+
amd_comgr_(data_set_add(InputBundles, OneBundle));
62+
63+
amd_comgr_data_set_t OutputBitcode;
64+
amd_comgr_(create_data_set(&OutputBitcode));
65+
66+
amd_comgr_action_info_t DataAction;
67+
amd_comgr_(create_action_info(&DataAction));
68+
69+
const char *AllArch[] = {Arch};
70+
amd_comgr_(action_info_set_bundle_entry_ids(DataAction, AllArch, 1));
71+
amd_comgr_(do_action(AMD_COMGR_ACTION_UNBUNDLE, DataAction, InputBundles,
72+
OutputBitcode));
73+
74+
size_t Count;
75+
amd_comgr_(action_data_count(OutputBitcode, AMD_COMGR_DATA_KIND_BC, &Count));
76+
77+
if (Count != 1) {
78+
printf("AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC Failed: "
79+
"produced %zu BC objects (expected 1)\n",
80+
Count);
81+
exit(1);
82+
}
83+
84+
amd_comgr_data_t OneBitcode;
85+
amd_comgr_(action_data_get_data(OutputBitcode, AMD_COMGR_DATA_KIND_BC, 0,
86+
&OneBitcode));
87+
88+
size_t BufferSize;
89+
amd_comgr_(get_data(OneBitcode, &BufferSize, 0x0));
90+
char *Buffer = (char *)malloc(BufferSize);
91+
amd_comgr_(get_data(OneBitcode, &BufferSize, Buffer));
92+
93+
FILE *BitcodeFile = fopen(BitcodePath, "wb");
94+
fwrite(Buffer, 1, BufferSize, BitcodeFile);
95+
fclose(BitcodeFile);
96+
97+
free(Buffer);
98+
amd_comgr_(release_data(OneBitcode));
99+
amd_comgr_(release_data(OneBundle));
100+
amd_comgr_(destroy_action_info(DataAction));
101+
amd_comgr_(destroy_data_set(OutputBitcode));
102+
amd_comgr_(destroy_data_set(InputBundles));
103+
104+
return 0;
105+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Create compressed bitcode bundle (add --offload-compress flag)
2+
// RUN: clang -c -x hip --offload-arch=gfx900 --offload-arch=gfx1030 \
3+
// RUN: -nogpulib -nogpuinc \
4+
// RUN: --gpu-bundle-output --offload-device-only \
5+
// RUN: -fgpu-rdc \
6+
// RUN: --offload-compress \
7+
// RUN: %s -o %t.compressed-bundle.bc
8+
//
9+
// Clean the cache
10+
// RUN: rm -fr %t.cache
11+
//
12+
// With the cache enabled, test that we write one file to the cache
13+
// RUN: export AMD_COMGR_CACHE=1
14+
// RUN: export AMD_COMGR_CACHE_DIR=%t.cache
15+
// RUN: unbundle %t.compressed-bundle.bc hip-amdgcn-amd-amdhsa-unknown-gfx900 %t.cache_1.bc
16+
// RUN: llvm-dis %t.cache_1.bc -o - | FileCheck --check-prefixes=BOTH,GFX9 %s
17+
// RUN: COUNT=$(ls "%t.cache" | wc -l)
18+
// RUN: [ 2 -eq $COUNT ]
19+
//
20+
// If there is a re-run, the cache contents remain the same
21+
// RUN: unbundle %t.compressed-bundle.bc hip-amdgcn-amd-amdhsa-unknown-gfx900 %t.cache_2.bc
22+
// RUN: llvm-dis %t.cache_2.bc -o - | FileCheck --check-prefixes=BOTH,GFX9 %s
23+
// RUN: COUNT=$(ls "%t.cache" | wc -l)
24+
// RUN: [ 2 -eq $COUNT ]
25+
//
26+
// A run with different input options results in new contents in the cache
27+
// RUN: unbundle %t.compressed-bundle.bc hip-amdgcn-amd-amdhsa-unknown-gfx1030 %t.cache_3.bc
28+
// RUN: llvm-dis %t.cache_3.bc -o - | FileCheck --check-prefixes=BOTH,GFX10 %s
29+
// RUN: COUNT=$(ls "%t.cache" | wc -l)
30+
// RUN: [ 3 -eq $COUNT ]
31+
32+
// BOTH: target triple = "amdgcn-amd-amdhsa"
33+
// GFX9: "target-cpu"="gfx900"
34+
// GFX10: "target-cpu"="gfx1030"
35+
36+
__attribute__((device))
37+
void add_value(float* a, float* b, float* res) {
38+
*res = *a + *b;
39+
}

amd/comgr/test-lit/unbundle-test.hip

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Create bitcode bundle
2+
// RUN: clang -c -x hip --offload-arch=gfx900 --offload-arch=gfx1030 \
3+
// RUN: -nogpulib -nogpuinc \
4+
// RUN: --gpu-bundle-output --offload-device-only \
5+
// RUN: -fgpu-rdc \
6+
// RUN: %s -o %t.bundle.bc
7+
//
8+
// Create compressed bitcode bundle (add --offload-compress flag)
9+
// RUN: clang -c -x hip --offload-arch=gfx900 --offload-arch=gfx1030 \
10+
// RUN: -nogpulib -nogpuinc \
11+
// RUN: --gpu-bundle-output --offload-device-only \
12+
// RUN: -fgpu-rdc \
13+
// RUN: --offload-compress \
14+
// RUN: %s -o %t.compressed-bundle.bc
15+
//
16+
// Extract using Comgr
17+
// RUN: unbundle %t.bundle.bc hip-amdgcn-amd-amdhsa-unknown-gfx900 %t.gfx900.bc
18+
// RUN: llvm-dis %t.gfx900.bc -o - | FileCheck --check-prefixes=BOTH,GFX9 %s
19+
//
20+
// RUN: unbundle %t.compressed-bundle.bc hip-amdgcn-amd-amdhsa-unknown-gfx1030 %t.compressed.gfx1030.bc
21+
// RUN: llvm-dis %t.compressed.gfx1030.bc -o - | FileCheck --check-prefixes=BOTH,GFX10 %s
22+
//
23+
// BOTH: target triple = "amdgcn-amd-amdhsa"
24+
// GFX9: "target-cpu"="gfx900"
25+
// GFX10: "target-cpu"="gfx1030"
26+
27+
__attribute__((device))
28+
void add_value(float* a, float* b, float* res) {
29+
*res = *a + *b;
30+
}

0 commit comments

Comments
 (0)