Skip to content

Commit e87838c

Browse files
kbobrovsbader
authored andcommitted
[SYCL] Support partially linked fat objects in the bundler.
Signed-off-by: Konstantin Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent 62866cd commit e87838c

File tree

4 files changed

+408
-72
lines changed

4 files changed

+408
-72
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//
55
// Generate all the types of files we can bundle.
66
//
7+
// generate the emulated fat object:
8+
// RUN: %clangxx -O0 -target powerpc64le-ibm-linux-gnu -DEMULATE_FAT_OBJ %s -c -o %s.o
9+
//
710
// RUN: %clang -O0 -target powerpc64le-ibm-linux-gnu %s -E -o %t.i
811
// RUN: %clangxx -O0 -target powerpc64le-ibm-linux-gnu -x c++ %s -E -o %t.ii
912
// RUN: %clang -O0 -target powerpc64le-ibm-linux-gnu %s -S -emit-llvm -o %t.ll
@@ -253,8 +256,32 @@
253256
// RUN: diff %t.empty %t.res.tgt1
254257
// RUN: diff %t.empty %t.res.tgt2
255258

259+
#ifdef EMULATE_FAT_OBJ
260+
#define BUNDLE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE__"
261+
#define BUNDLE_SIZE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE_SIZE__"
262+
263+
#define TARGET_HOST "host-powerpc64le-ibm-linux-gnu"
264+
#define TARGET1 "openmp-powerpc64le-ibm-linux-gnu"
265+
#define TARGET2 "openmp-x86_64-pc-linux-gnu"
266+
267+
// not to rely on <cstdint>:
268+
typedef long long int64_t;
269+
270+
// Populate sections with special names recognized by the unbundler;
271+
// this emulates a fat object created by the bundler
272+
char str0[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET_HOST))) = { 0 };
273+
int64_t size0[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET_HOST))) = { 1 };
274+
275+
char str1[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET1))) = { "Content of device file 1\n" };
276+
int64_t size1[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET1))) = { 25 };
277+
278+
char str2[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET2))) = { "Content of device file 2\n" };
279+
int64_t size2[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET2))) = { 25 };
280+
#endif // EMULATE_FAT_OBJ
281+
256282
// Some code so that we can create a binary out of this file.
257283
int A = 0;
258284
void test_func(void) {
259285
++A;
260286
}
287+
-1.88 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// REQUIRES: x86-registered-target
2+
// RUN: %clangxx -c %s -o %t_fat.o
3+
// RUN: %clangxx %t_fat.o -o %t.exe
4+
// RUN: clang-offload-bundler -type=oo -targets=host-x86_64-unknown-linux-gnu,sycl-x86_64-unknown-linux-gnu -outputs=%t.o,%t_list.txt -inputs=%t_fat.o -unbundle
5+
// RUN: %t.exe %t_list.txt | FileCheck %s
6+
// CHECK:11
7+
// CHECK:222
8+
// CHECK:3333
9+
10+
#include <cstdint>
11+
#include <iostream>
12+
#include <fstream>
13+
#include <string>
14+
#include <vector>
15+
using namespace std;
16+
17+
#define BUNDLE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE__"
18+
#define BUNDLE_SIZE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE_SIZE__"
19+
20+
#define TARGET0 "host-x86_64-unknown-linux-gnu"
21+
#define TARGET1 "sycl-x86_64-unknown-linux-gnu"
22+
23+
// Populate section with special names recognized by the bundler;
24+
// this emulates fat object partially linked from 3 other fat objects.
25+
// The test uses the bundler to split the bundle into 3 objects and then prints
26+
// their contents to stdout.
27+
char str0[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET0))) = { 0, 0, 0 };
28+
int64_t size0[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET0))) = { 1, 1, 1 };
29+
30+
char str1[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET1))) = { "11\n222\n3333\n" };
31+
int64_t size1[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET1))) = { 3, 4, 5 };
32+
33+
void cat(const string& File) {
34+
string Line;
35+
ifstream F(File);
36+
if (F.is_open()) {
37+
while (getline(F, Line)) {
38+
cout << Line << '\n';
39+
}
40+
F.close();
41+
}
42+
else cout << "Unable to open file " << File;
43+
}
44+
45+
// main is invoked with the bundler output file as argument -
46+
// read this file and print their contents to stdout.
47+
int main(int argc, char **argv) {
48+
string ListFile(argv[1]);
49+
string Line;
50+
ifstream F(ListFile);
51+
vector<string> OutFiles;
52+
53+
if (F.is_open()) {
54+
while (getline(F, Line)) {
55+
OutFiles.push_back(Line);
56+
}
57+
F.close();
58+
}
59+
else {
60+
cout << "Unable to open file " << ListFile;
61+
return 1;
62+
}
63+
64+
for (const auto &File : OutFiles) {
65+
cat(File);
66+
}
67+
return 0;
68+
}
69+

0 commit comments

Comments
 (0)