Skip to content

Commit

Permalink
[SYCL] add extra tests (intel#37)
Browse files Browse the repository at this point in the history
- add tests from intel/llvm;
- make SYCL/ESIMD/mandelbrot tests generate data files in build directory and remove data file from GIT;
- rename regression directory to match llvm-test-suite naming (Regression);
- fix clang-format issues.
  • Loading branch information
vladimirlaz authored Oct 20, 2020
1 parent a750778 commit c9eb12f
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions SYCL/SeparateCompile/sycl-external.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Test1 - check that kernel can call a SYCL_EXTERNAL function defined in a
// different object file.
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DSOURCE1 -c %s -o %t1.o
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -DSOURCE2 -c %s -o %t2.o
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %t1.o %t2.o -o %t.exe
// RUN: %CPU_RUN_PLACEHOLDER %t.exe
// RUN: %GPU_RUN_PLACEHOLDER %t.exe
// RUN: %ACC_RUN_PLACEHOLDER %t.exe
//
// Test2 - check that kernel can call a SYCL_EXTERNAL function defined in a
// static library.
// RUN: rm -f %t.a
// RUN: llvm-ar crv %t.a %t1.o
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %t2.o -foffload-static-lib=%t.a -o %t.exe
// RUN: %CPU_RUN_PLACEHOLDER %t.exe
// RUN: %GPU_RUN_PLACEHOLDER %t.exe
// RUN: %ACC_RUN_PLACEHOLDER %t.exe

#include <CL/sycl.hpp>
#include <iostream>

#ifdef SOURCE1
int bar(int b);

SYCL_EXTERNAL
int foo(int a, int b) { return a + bar(b); }

int bar(int b) { return b + 5; }
#endif // SOURCE1

#ifdef SOURCE2
SYCL_EXTERNAL
int foo(int A, int B);

int main(void) {
constexpr unsigned Size = 4;
int A[Size] = {1, 2, 3, 4};
int B[Size] = {1, 2, 3, 4};
int C[Size];

{
cl::sycl::range<1> range{Size};
cl::sycl::buffer<int, 1> bufA(A, range);
cl::sycl::buffer<int, 1> bufB(B, range);
cl::sycl::buffer<int, 1> bufC(C, range);

cl::sycl::queue().submit([&](cl::sycl::handler &cgh) {
auto accA = bufA.get_access<cl::sycl::access::mode::read>(cgh);
auto accB = bufB.get_access<cl::sycl::access::mode::read>(cgh);
auto accC = bufC.get_access<cl::sycl::access::mode::write>(cgh);

cgh.parallel_for<class Test>(range, [=](cl::sycl::id<1> ID) {
accC[ID] = foo(accA[ID], accB[ID]);
});
});
}

for (unsigned I = 0; I < Size; ++I) {
int Ref = foo(A[I], B[I]);
if (C[I] != Ref) {
std::cout << "fail: [" << I << "] == " << C[I] << ", expected " << Ref
<< "\n";
return 1;
}
}
std::cout << "pass\n";
return 0;
}
#endif // SOURCE2

0 comments on commit c9eb12f

Please sign in to comment.