|
| 1 | +// Check that, when linking with a static library, SYCL_EXTERNAL device code |
| 2 | +// is preserved despite optimizations. |
| 3 | +// RUN: %{build} -O3 -DSOURCE1 -c -o %t1.o |
| 4 | +// RUN: %{build} -O3 -DSOURCE2 -c -o %t2.o |
| 5 | +// RUN: %{build} -O3 -DSOURCE3 -c -o %t3.o |
| 6 | +// RUN: rm -f %t.a |
| 7 | +// RUN: llvm-ar crv %t.a %t1.o %t2.o |
| 8 | +// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} -O3 %t3.o %t.a -o %t1.exe |
| 9 | +// RUN: %{run} %t1.exe |
| 10 | + |
| 11 | +// Check the repacked case as it can behave differently. |
| 12 | +// RUN: echo create %t_repacked.a > %t.txt |
| 13 | +// RUN: echo addlib %t.a >> %t.txt |
| 14 | +// RUN: echo save >> %t.txt |
| 15 | +// RUN: cat %t.txt | llvm-ar -M |
| 16 | +// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} -O3 %t3.o %t_repacked.a -o %t2.exe |
| 17 | +// RUN: %{run} %t2.exe |
| 18 | + |
| 19 | +#include <iostream> |
| 20 | +#include <sycl/detail/core.hpp> |
| 21 | + |
| 22 | +#ifdef SOURCE1 |
| 23 | +int local_f2(int b); |
| 24 | + |
| 25 | +SYCL_EXTERNAL |
| 26 | +int external_f1(int a, int b) { return a + local_f2(b); } |
| 27 | + |
| 28 | +int local_f2(int b) { return b + 5; } |
| 29 | +#endif // SOURCE1 |
| 30 | + |
| 31 | +#ifdef SOURCE2 |
| 32 | +SYCL_EXTERNAL |
| 33 | +int external_f1(int A, int B); |
| 34 | + |
| 35 | +void hostf(unsigned Size, sycl::buffer<int, 1> &bufA, |
| 36 | + sycl::buffer<int, 1> &bufB, sycl::buffer<int, 1> &bufC) { |
| 37 | + sycl::range<1> range{Size}; |
| 38 | + sycl::queue().submit([&](sycl::handler &cgh) { |
| 39 | + auto accA = bufA.get_access<sycl::access::mode::read>(cgh); |
| 40 | + auto accB = bufB.get_access<sycl::access::mode::read>(cgh); |
| 41 | + auto accC = bufC.get_access<sycl::access::mode::write>(cgh); |
| 42 | + |
| 43 | + cgh.parallel_for<class Test>(range, [=](sycl::id<1> ID) { |
| 44 | + accC[ID] = external_f1(accA[ID], accB[ID]); |
| 45 | + }); |
| 46 | + }); |
| 47 | +} |
| 48 | +#endif |
| 49 | + |
| 50 | +#ifdef SOURCE3 |
| 51 | +extern void hostf(unsigned Size, sycl::buffer<int, 1> &bufA, |
| 52 | + sycl::buffer<int, 1> &bufB, sycl::buffer<int, 1> &c); |
| 53 | +int ref(int a, int b) { return a + b + 5; } |
| 54 | + |
| 55 | +int main(void) { |
| 56 | + constexpr unsigned Size = 4; |
| 57 | + int A[Size] = {1, 2, 3, 4}; |
| 58 | + int B[Size] = {1, 2, 3, 4}; |
| 59 | + int C[Size]; |
| 60 | + |
| 61 | + { |
| 62 | + sycl::range<1> range{Size}; |
| 63 | + sycl::buffer<int, 1> bufA(A, range); |
| 64 | + sycl::buffer<int, 1> bufB(B, range); |
| 65 | + sycl::buffer<int, 1> bufC(C, range); |
| 66 | + hostf(Size, bufA, bufB, bufC); |
| 67 | + } |
| 68 | + for (unsigned I = 0; I < Size; ++I) { |
| 69 | + int Ref = ref(A[I], B[I]); |
| 70 | + if (C[I] != Ref) { |
| 71 | + std::cout << "fail: [" << I << "] == " << C[I] << ", expected " << Ref |
| 72 | + << "\n"; |
| 73 | + return 1; |
| 74 | + } |
| 75 | + } |
| 76 | + std::cout << "pass\n"; |
| 77 | + return 0; |
| 78 | +} |
| 79 | +#endif // SOURCE3 |
0 commit comments