Skip to content

[SYCL] Support partially linked fat objects in the bundler. #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions clang/test/Driver/clang-offload-bundler.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
//
// Generate all the types of files we can bundle.
//
// generate the emulated fat object:
// RUN: %clangxx -O0 -target powerpc64le-ibm-linux-gnu -DEMULATE_FAT_OBJ %s -c -o %s.o
//
// RUN: %clang -O0 -target powerpc64le-ibm-linux-gnu %s -E -o %t.i
// RUN: %clangxx -O0 -target powerpc64le-ibm-linux-gnu -x c++ %s -E -o %t.ii
// RUN: %clang -O0 -target powerpc64le-ibm-linux-gnu %s -S -emit-llvm -o %t.ll
Expand Down Expand Up @@ -253,8 +256,32 @@
// RUN: diff %t.empty %t.res.tgt1
// RUN: diff %t.empty %t.res.tgt2

#ifdef EMULATE_FAT_OBJ
#define BUNDLE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE__"
#define BUNDLE_SIZE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE_SIZE__"

#define TARGET_HOST "host-powerpc64le-ibm-linux-gnu"
#define TARGET1 "openmp-powerpc64le-ibm-linux-gnu"
#define TARGET2 "openmp-x86_64-pc-linux-gnu"

// not to rely on <cstdint>:
typedef long long int64_t;

// Populate sections with special names recognized by the unbundler;
// this emulates a fat object created by the bundler
char str0[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET_HOST))) = { 0 };
int64_t size0[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET_HOST))) = { 1 };

char str1[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET1))) = { "Content of device file 1\n" };
int64_t size1[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET1))) = { 25 };

char str2[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET2))) = { "Content of device file 2\n" };
int64_t size2[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET2))) = { 25 };
#endif // EMULATE_FAT_OBJ

// Some code so that we can create a binary out of this file.
int A = 0;
void test_func(void) {
++A;
}

Binary file removed clang/test/Driver/clang-offload-bundler.c.o
Binary file not shown.
69 changes: 69 additions & 0 deletions clang/test/Driver/clang-offload-bundler1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// REQUIRES: x86-registered-target
// RUN: %clangxx -c %s -o %t_fat.o
// RUN: %clangxx %t_fat.o -o %t.exe
// 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
// RUN: %t.exe %t_list.txt | FileCheck %s
// CHECK:11
// CHECK:222
// CHECK:3333

#include <cstdint>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

#define BUNDLE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE__"
#define BUNDLE_SIZE_SECTION_PREFIX "__CLANG_OFFLOAD_BUNDLE_SIZE__"

#define TARGET0 "host-x86_64-unknown-linux-gnu"
#define TARGET1 "sycl-x86_64-unknown-linux-gnu"

// Populate section with special names recognized by the bundler;
// this emulates fat object partially linked from 3 other fat objects.
// The test uses the bundler to split the bundle into 3 objects and then prints
// their contents to stdout.
char str0[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET0))) = { 0, 0, 0 };
int64_t size0[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET0))) = { 1, 1, 1 };

char str1[] __attribute__((section(BUNDLE_SECTION_PREFIX TARGET1))) = { "11\n222\n3333\n" };
int64_t size1[] __attribute__((section(BUNDLE_SIZE_SECTION_PREFIX TARGET1))) = { 3, 4, 5 };

void cat(const string& File) {
string Line;
ifstream F(File);
if (F.is_open()) {
while (getline(F, Line)) {
cout << Line << '\n';
}
F.close();
}
else cout << "Unable to open file " << File;
}

// main is invoked with the bundler output file as argument -
// read this file and print their contents to stdout.
int main(int argc, char **argv) {
string ListFile(argv[1]);
string Line;
ifstream F(ListFile);
vector<string> OutFiles;

if (F.is_open()) {
while (getline(F, Line)) {
OutFiles.push_back(Line);
}
F.close();
}
else {
cout << "Unable to open file " << ListFile;
return 1;
}

for (const auto &File : OutFiles) {
cat(File);
}
return 0;
}

Loading