Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit c1d0c1c

Browse files
authored
[SYCL] Add tests from intel/llvm (#50)
The end to end tests with OpenCL/CUDA/Level_Zero dependencies are moved out in-source LIT tests.
1 parent db39e47 commit c1d0c1c

File tree

146 files changed

+9440
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+9440
-772
lines changed

SYCL/Basic/aot/Inputs/aot.cpp renamed to SYCL/AOT/Inputs/aot.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//==----- aot.cpp - Simple vector addition (AOT compilation example) --------==//
1+
//==--- aot.cpp - Simple vector addition (AOT compilation example) --------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
//===------------------------------------------------------------------------===//
7+
//===---------------------------------------------------------------------===//
88

99
#include <CL/sycl.hpp>
1010

@@ -14,8 +14,7 @@
1414
constexpr cl::sycl::access::mode sycl_read = cl::sycl::access::mode::read;
1515
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write;
1616

17-
template <typename T>
18-
class SimpleVadd;
17+
template <typename T> class SimpleVadd;
1918

2019
template <typename T, size_t N>
2120
void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,

SYCL/Basic/aot/accelerator.cpp renamed to SYCL/AOT/accelerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//==----- accelerator.cpp - AOT compilation for fpga devices using aoc ------==//
1+
//==--- accelerator.cpp - AOT compilation for fpga devices using aoc ------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
//===------------------------------------------------------------------------===//
7+
//===---------------------------------------------------------------------===//
88

99
// REQUIRES: aoc, accelerator
1010

SYCL/Basic/aot/cpu.cpp renamed to SYCL/AOT/cpu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//==----- cpu.cpp - AOT compilation for cpu devices using opencl-aot --------==//
1+
//==--- cpu.cpp - AOT compilation for cpu devices using opencl-aot --------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
//===------------------------------------------------------------------------===//
7+
//===---------------------------------------------------------------------===//
88

99
// REQUIRES: opencl-aot, cpu
1010

SYCL/Basic/aot/gpu.cpp renamed to SYCL/AOT/gpu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//==----- gpu.cpp - AOT compilation for gen devices using GEN compiler ------==//
1+
//==--- gpu.cpp - AOT compilation for gen devices using GEN compiler ------==//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
7-
//===------------------------------------------------------------------------===//
7+
//===---------------------------------------------------------------------===//
88

99
// REQUIRES: ocloc, gpu
1010
// UNSUPPORTED: cuda

SYCL/AOT/multiple-devices.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//==-- multiple-devices.cpp - Appropriate AOT-compiled image selection -----==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: opencl-aot, ocloc, aoc, cpu, gpu, accelerator
10+
// UNSUPPORTED: cuda
11+
// CUDA is not compatible with SPIR.
12+
13+
// 1-command compilation case
14+
// Targeting CPU, GPU, FPGA
15+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice,spir64_gen-unknown-unknown-sycldevice,spir64_fpga-unknown-unknown-sycldevice -Xsycl-target-backend=spir64_gen-unknown-unknown-sycldevice "-device *" %S/Inputs/aot.cpp -o %t_all.out
16+
// RUN: %HOST_RUN_PLACEHOLDER %t_all.out
17+
// RUN: %CPU_RUN_PLACEHOLDER %t_all.out
18+
// RUN: %GPU_RUN_PLACEHOLDER %t_all.out
19+
// RUN: %ACC_RUN_PLACEHOLDER %t_all.out
20+
21+
// Produce object file, spirv, device images to combine these differently
22+
// at link-time, thus testing various AOT-compiled images configurations
23+
// RUN: %clangxx -fsycl %S/Inputs/aot.cpp -c -o %t.o
24+
// RUN: %clangxx -fsycl -fsycl-link-targets=spir64-unknown-unknown-sycldevice %t.o -o %t.spv
25+
// AOT-compile device binary images
26+
// RUN: opencl-aot %t.spv -o=%t_cpu.ir --device=cpu
27+
// RUN: ocloc -file %t.spv -spirv_input -output %t_gen.out -output_no_suffix -device cfl
28+
// RUN: aoc %t.spv -o %t_fpga.aocx -sycl -dep-files=%t.d
29+
30+
// CPU, GPU
31+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64_x86_64:%t_cpu.ir,spir64_gen:%t_gen.out %t.o -o %t_cpu_gpu.out
32+
// RUN: %HOST_RUN_PLACEHOLDER %t_cpu_gpu.out
33+
// RUN: %CPU_RUN_PLACEHOLDER %t_cpu_gpu.out
34+
// RUN: %GPU_RUN_PLACEHOLDER %t_cpu_gpu.out
35+
36+
// CPU, FPGA
37+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64_x86_64:%t_cpu.ir,spir64_fpga:%t_fpga.aocx %t.o -o %t_cpu_fpga.out
38+
// RUN: %HOST_RUN_PLACEHOLDER %t_cpu_fpga.out
39+
// RUN: %CPU_RUN_PLACEHOLDER %t_cpu_fpga.out
40+
// RUN: %ACC_RUN_PLACEHOLDER %t_cpu_fpga.out
41+
42+
// GPU, FPGA
43+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64_gen:%t_gen.out,spir64_fpga:%t_fpga.aocx %t.o -o %t_gpu_fpga.out
44+
// RUN: %HOST_RUN_PLACEHOLDER %t_gpu_fpga.out
45+
// RUN: %GPU_RUN_PLACEHOLDER %t_gpu_fpga.out
46+
// RUN: %ACC_RUN_PLACEHOLDER %t_gpu_fpga.out
47+
48+
// No AOT-compiled image for CPU
49+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64:%t.spv,spir64_gen:%t_gen.out,spir64_fpga:%t_fpga.aocx %t.o -o %t_spv_gpu_fpga.out
50+
// RUN: %CPU_RUN_PLACEHOLDER %t_spv_gpu_fpga.out
51+
// Check that execution on AOT-compatible devices is unaffected
52+
// RUN: %GPU_RUN_PLACEHOLDER %t_spv_gpu_fpga.out
53+
// RUN: %ACC_RUN_PLACEHOLDER %t_spv_gpu_fpga.out
54+
55+
// No AOT-compiled image for GPU
56+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64:%t.spv,spir64_x86_64:%t_cpu.ir,spir64_fpga:%t_fpga.aocx %t.o -o %t_spv_cpu_fpga.out
57+
// RUN: %GPU_RUN_PLACEHOLDER %t_spv_cpu_fpga.out
58+
// Check that execution on AOT-compatible devices is unaffected
59+
// RUN: %CPU_RUN_PLACEHOLDER %t_spv_cpu_fpga.out
60+
// RUN: %ACC_RUN_PLACEHOLDER %t_spv_cpu_fpga.out
61+
62+
// No AOT-compiled image for FPGA
63+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64:%t.spv,spir64_x86_64:%t_cpu.ir,spir64_gen:%t_gen.out %t.o -o %t_spv_cpu_gpu.out
64+
// RUN: %ACC_RUN_PLACEHOLDER %t_spv_cpu_gpu.out
65+
// Check that execution on AOT-compatible devices is unaffected
66+
// RUN: %CPU_RUN_PLACEHOLDER %t_spv_cpu_gpu.out
67+
// RUN: %GPU_RUN_PLACEHOLDER %t_spv_cpu_gpu.out

SYCL/AOT/spec_const_aot.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// REQUIRES: opencl-aot, cpu
2+
//
3+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice %s -o %t.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
5+
//
6+
// The test checks that the specialization constant feature works with ahead
7+
// of time compilation.
8+
9+
#include <CL/sycl.hpp>
10+
11+
#include <iostream>
12+
#include <vector>
13+
14+
class MyInt32Const;
15+
16+
using namespace sycl;
17+
18+
class Kernel;
19+
20+
int main(int argc, char **argv) {
21+
cl::sycl::queue q(default_selector{}, [](exception_list l) {
22+
for (auto ep : l) {
23+
try {
24+
std::rethrow_exception(ep);
25+
} catch (cl::sycl::exception &e0) {
26+
std::cout << e0.what();
27+
} catch (std::exception &e1) {
28+
std::cout << e1.what();
29+
} catch (...) {
30+
std::cout << "*** catch (...)\n";
31+
}
32+
}
33+
});
34+
35+
std::cout << "Running on " << q.get_device().get_info<info::device::name>()
36+
<< "\n";
37+
cl::sycl::program prog(q.get_context());
38+
39+
cl::sycl::ONEAPI::experimental::spec_constant<int32_t, MyInt32Const> i32 =
40+
prog.set_spec_constant<MyInt32Const>(10);
41+
42+
prog.build_with_kernel_type<Kernel>();
43+
44+
std::vector<int> vec(1);
45+
{
46+
cl::sycl::buffer<int, 1> buf(vec.data(), vec.size());
47+
48+
q.submit([&](cl::sycl::handler &cgh) {
49+
auto acc = buf.get_access<cl::sycl::access::mode::write>(cgh);
50+
cgh.single_task<Kernel>(prog.get_kernel<Kernel>(),
51+
[=]() { acc[0] = i32.get(); });
52+
});
53+
}
54+
bool passed = true;
55+
int val = vec[0];
56+
int gold = 0; // with AOT, spec constant is set to C++ default for the type
57+
58+
if (val != gold) {
59+
std::cout << "*** ERROR: " << val << " != " << gold << "(gold)\n";
60+
passed = false;
61+
}
62+
std::cout << (passed ? "passed\n" : "FAILED\n");
63+
return passed ? 0 : 1;
64+
}
File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "split-per-source.h"
2+
3+
void runKernelsFromFile2() {
4+
cl::sycl::queue Q;
5+
int Data = 0;
6+
{
7+
cl::sycl::program Prg(Q.get_context());
8+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
9+
Prg.build_with_kernel_type<File2Kern1>();
10+
cl::sycl::kernel Krn = Prg.get_kernel<File2Kern1>();
11+
12+
assert(!Prg.has_kernel<File1Kern1>());
13+
assert(!Prg.has_kernel<File1Kern2>());
14+
15+
Q.submit([&](cl::sycl::handler &Cgh) {
16+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
17+
Cgh.single_task<File2Kern1>(Krn, [=]() { Acc[0] = 3; });
18+
});
19+
}
20+
assert(Data == 3);
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <CL/sycl.hpp>
2+
3+
class File1Kern1;
4+
class File1Kern2;
5+
class File2Kern1;
6+
7+
void runKernelsFromFile2();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// REQUIRES: aoc, accelerator
2+
3+
// RUN: %clangxx -fsycl -fsycl-device-code-split=per_source -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice -I %S/Inputs -o %t.out %S/split-per-source-main.cpp %S/Inputs/split-per-source-second-file.cpp
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// REQUIRES: opencl-aot, cpu
2+
3+
// RUN: %clangxx -fsycl -fsycl-device-code-split=per_source -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice -I %S/Inputs -o %t.out %S/split-per-source-main.cpp %S/Inputs/split-per-source-second-file.cpp
4+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: ocloc, gpu
2+
// UNSUPPORTED: cuda
3+
// CUDA does neither support device code splitting nor SPIR.
4+
//
5+
// RUN: %clangxx -fsycl -fsycl-device-code-split=per_source \
6+
// RUN: -fsycl-targets=spir64_gen-unknown-unknown-sycldevice \
7+
// RUN: -Xsycl-target-backend=spir64_gen-unknown-unknown-sycldevice \
8+
// RUN: "-device *" -I %S/Inputs -o %t.out \
9+
// RUN: %S/split-per-source-main.cpp \
10+
// RUN: %S/Inputs/split-per-source-second-file.cpp
11+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// UNSUPPORTED: cuda
2+
// CUDA does not support device code splitting.
3+
//
4+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_kernel -o %t.out %s
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
7+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
8+
9+
#include <CL/sycl.hpp>
10+
11+
class Kern1;
12+
class Kern2;
13+
class Kern3;
14+
15+
int main() {
16+
cl::sycl::queue Q;
17+
int Data = 0;
18+
{
19+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
20+
cl::sycl::program Prg(Q.get_context());
21+
Prg.build_with_kernel_type<Kern1>();
22+
cl::sycl::kernel Krn = Prg.get_kernel<Kern1>();
23+
24+
assert(!Prg.has_kernel<Kern2>());
25+
assert(!Prg.has_kernel<Kern3>());
26+
27+
Q.submit([&](cl::sycl::handler &Cgh) {
28+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
29+
Cgh.single_task<Kern1>(Krn, [=]() { Acc[0] = 1; });
30+
});
31+
}
32+
assert(Data == 1);
33+
34+
{
35+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
36+
cl::sycl::program Prg(Q.get_context());
37+
Prg.build_with_kernel_type<Kern2>();
38+
cl::sycl::kernel Krn = Prg.get_kernel<Kern2>();
39+
40+
assert(!Prg.has_kernel<Kern1>());
41+
assert(!Prg.has_kernel<Kern3>());
42+
43+
Q.submit([&](cl::sycl::handler &Cgh) {
44+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
45+
Cgh.single_task<Kern2>(Krn, [=]() { Acc[0] = 2; });
46+
});
47+
}
48+
assert(Data == 2);
49+
50+
{
51+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
52+
cl::sycl::program Prg(Q.get_context());
53+
Prg.build_with_kernel_type<Kern3>();
54+
cl::sycl::kernel Krn = Prg.get_kernel<Kern3>();
55+
56+
assert(!Prg.has_kernel<Kern1>());
57+
assert(!Prg.has_kernel<Kern2>());
58+
59+
Q.submit([&](cl::sycl::handler &Cgh) {
60+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
61+
Cgh.single_task<Kern3>(Krn, [=]() { Acc[0] = 3; });
62+
});
63+
}
64+
assert(Data == 3);
65+
66+
return 0;
67+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// UNSUPPORTED: cuda
2+
// CUDA does not support device code splitting.
3+
//
4+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fsycl-device-code-split=per_source -I %S/Inputs -o %t.out %s %S/Inputs/split-per-source-second-file.cpp
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
7+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
8+
9+
#include "Inputs/split-per-source.h"
10+
11+
int main() {
12+
cl::sycl::queue Q;
13+
int Data = 0;
14+
{
15+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
16+
cl::sycl::program Prg(Q.get_context());
17+
Prg.build_with_kernel_type<File1Kern1>();
18+
cl::sycl::kernel Krn = Prg.get_kernel<File1Kern1>();
19+
20+
assert(Prg.has_kernel<File1Kern2>());
21+
// TODO uncomment once the KernelInfo in multiple translation units
22+
// bug is fixed.
23+
// assert(!Prg.has_kernel<File2Kern1>());
24+
25+
Q.submit([&](cl::sycl::handler &Cgh) {
26+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
27+
Cgh.single_task<File1Kern1>(/*Krn,*/ [=]() { Acc[0] = 1; });
28+
});
29+
}
30+
assert(Data == 1);
31+
32+
{
33+
cl::sycl::buffer<int, 1> Buf(&Data, cl::sycl::range<1>(1));
34+
cl::sycl::program Prg(Q.get_context());
35+
Prg.build_with_kernel_type<File1Kern2>();
36+
cl::sycl::kernel Krn = Prg.get_kernel<File1Kern2>();
37+
38+
assert(Prg.has_kernel<File1Kern1>());
39+
// TODO uncomment once the KernelInfo in multiple translation units
40+
// bug is fixed.
41+
// assert(!Prg.has_kernel<File2Kern1>());
42+
43+
Q.submit([&](cl::sycl::handler &Cgh) {
44+
auto Acc = Buf.get_access<cl::sycl::access::mode::read_write>(Cgh);
45+
Cgh.single_task<File1Kern2>(/*Krn,*/ [=]() { Acc[0] = 2; });
46+
});
47+
}
48+
assert(Data == 2);
49+
50+
runKernelsFromFile2();
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)