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

Commit ad00dbf

Browse files
committed
[SYCL] dpc++ tests
1 parent 2c3c4a6 commit ad00dbf

File tree

140 files changed

+14289
-0
lines changed

Some content is hidden

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

140 files changed

+14289
-0
lines changed

SYCL/Basic/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(LLVM_TOOLS_DIR "${LLVM_BINARY_DIR}/bin/")
2+
3+
#get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)
4+
5+
set(SYCL_INCLUDE "${SYCL_INCLUDE_BUILD_DIR}")
6+
set(SYCL_TOOLS_SRC_DIR "${PROJECT_SOURCE_DIR}/tools/")
7+
set(LLVM_BUILD_BINARY_DIRS "${LLVM_BINARY_DIR}/bin/")
8+
set(LLVM_BUILD_LIBRARY_DIRS "${LLVM_BINARY_DIR}/lib/")
9+
10+
set(RT_TEST_ARGS ${RT_TEST_ARGS} "-v")
11+
set(DEPLOY_RT_TEST_ARGS ${DEPLOY_RT_TEST_ARGS} "-v -D SYCL_TOOLS_DIR=${CMAKE_INSTALL_PREFIX}/bin -D SYCL_LIBS_DIR=${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX} -D SYCL_INCLUDE=${SYCL_INCLUDE_DEPLOY_DIR}")
12+
13+
find_package(Threads REQUIRED)
14+
set(SYCL_THREADS_LIB ${CMAKE_THREAD_LIBS_INIT})
15+
16+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in" "${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg")

SYCL/Basic/README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Overview
2+
SYCL related test based on SYCL-LIT. These tests support
3+
execution on all supported devices and SYCL backends.
4+
5+
# Table of contents
6+
* [Execution](#execution)
7+
* [Main parameters](#main-parameters)
8+
* [LIT features which can be used to configure test execution](#lit-features-which-can-be-used-to-configure-test-execution)
9+
10+
# Execution
11+
```
12+
git clone <GIT_REPO> # e.g. https://github.com/vladimirlaz/llvm-test-suite
13+
cd llvm-test-suite
14+
mkdir build
15+
cd build
16+
# configuring test execution (selecting compiler version, target BE and target device)
17+
cmake -G Ninja -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=<SYCL_BE> -DSYCL_TARGET_DEVICES=<TARGET_DEVICES> -C<CMAKE_CHASHED_CONFIG> ..
18+
# Building full list of tests in subdir
19+
ninja check
20+
# or
21+
llvm-lit .
22+
# Get list of available tests
23+
llvm-lit . --show-tests
24+
# Run specific test
25+
llvm-lit <path_to_test>
26+
```
27+
28+
Notes:
29+
- it is assumed that LIT framework, FileCheck and other LIT dependencies are available in the same directory with llvm-lit.
30+
- compiler variant as well as compile/link options are defined in cashed cmake configurations:
31+
- [dpcpp.cmake](../../cmake/caches/dpcpp.cmake)
32+
- [clang_fsycl.cmake](../../cmake/cashes/clang_fsycl.cmake)
33+
- [clang_fsycl_cuda.cmake](../../cmake/cashes/clang_fsycl_cuda.cmake)
34+
- compiler is taken from environment.
35+
36+
# Main parameters
37+
It is possible to change tets scope my specifying test directory/file in first
38+
argument to for thelit-runner.py script.
39+
40+
***SYCL_TARGET_DEVICES*** should point to the directory containing DPCPP compiler
41+
42+
***SYCL_TARGET_DEVICES*** defines comma separated target device types (default value is
43+
cpu,gpu,acc,host). Supported target_devices values are:
44+
- **cpu** - CPU device available in OpenCL backend only;
45+
- **gpu** - GPU device available in OpenCL, Level Zero and CUDA backends;
46+
- **acc** - FPGA emulator device available in OpenCL backend only;
47+
- **host** - SYCL Host device availabel with all backends.
48+
49+
***SYCL_BE*** defined SYCL backend to be used for testing (default is PI_OPENCL).
50+
Supported sycl_be values:
51+
- PI_OPENCL - for OpenCL backend;
52+
- PI_CUDA - for CUDA backend;
53+
- PI_LEVEL0 - Level Zero backend.
54+
55+
It is asssumed that all dependencies (OpenCL runtimes,
56+
CUDA SDK, AOT compilers, etc) are available in the system.
57+
58+
See examples below for configuring tests targetting different devices:
59+
- SYCL host:
60+
```
61+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_OPENCL -DSYCL_TARGET_DEVICES="host" -C../cmake/caches/clang_fsycl.cmake ..
62+
```
63+
- OpenCL GPU
64+
```
65+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_OPENCL -DSYCL_TARGET_DEVICES="gpu" -C../cmake/caches/clang_fsycl.cmake ..
66+
```
67+
- OpenCL CPU
68+
```
69+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_OPENCL -DSYCL_TARGET_DEVICES="gpu" -C../cmake/caches/clang_fsycl.cmake ..
70+
```
71+
- OpenCL FPGA emulator
72+
```
73+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_OPENCL -DSYCL_TARGET_DEVICES="gpu" -C../cmake/caches/clang_fsycl.cmake ..
74+
```
75+
- CUDA GPU
76+
```
77+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_CUDA -DSYCL_TARGET_DEVICES="gpu" -C../cmake/caches/clang_fsycl_cuda.cmake ..
78+
```
79+
- Level Zero GPU
80+
```
81+
cmake -G Ninja -DTEST_SUITE_COLLECT_CODE_SIZE=OFF -DTEST_SUITE_COLLECT_COMPILE_TIME=OFF -DTEST_SUITE_SUBDIRS=SYCL -DTEST_SUITE_LIT=<PATH_TO_llvm-lit> -DSYCL_BE=PI_LEVEL0 -DSYCL_TARGET_DEVICES="gpu" -C../cmake/caches/clang_fsycl.cmake ..
82+
```
83+
84+
# LIT features which can be used to configure test execution:
85+
- **windows**, **linux** - host OS;
86+
- **cpu**, **gpu**, **host**, **acc** - target devices;
87+
- **cuda**, **opencl**, **level0** - target backend;
88+
- **sycl-ls** - sycl-ls tool is available;
89+
- **dump_ir**: is set to true if compiler supports dumiping IR. Can be set by setting DUMP_IR_SUPPORTED in cmake. Default is false.
90+

SYCL/Basic/aot/Inputs/aot.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//==----- aot.cpp - Simple vector addition (AOT compilation example) --------==//
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+
#include <CL/sycl.hpp>
10+
11+
#include <array>
12+
#include <iostream>
13+
14+
constexpr cl::sycl::access::mode sycl_read = cl::sycl::access::mode::read;
15+
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write;
16+
17+
template <typename T>
18+
class SimpleVadd;
19+
20+
template <typename T, size_t N>
21+
void simple_vadd(const std::array<T, N> &VA, const std::array<T, N> &VB,
22+
std::array<T, N> &VC) {
23+
cl::sycl::queue deviceQueue([](cl::sycl::exception_list ExceptionList) {
24+
for (cl::sycl::exception_ptr_class ExceptionPtr : ExceptionList) {
25+
try {
26+
std::rethrow_exception(ExceptionPtr);
27+
} catch (cl::sycl::exception &E) {
28+
std::cerr << E.what();
29+
} catch (...) {
30+
std::cerr << "Unknown async exception was caught." << std::endl;
31+
}
32+
}
33+
});
34+
35+
cl::sycl::range<1> numOfItems{N};
36+
cl::sycl::buffer<T, 1> bufferA(VA.data(), numOfItems);
37+
cl::sycl::buffer<T, 1> bufferB(VB.data(), numOfItems);
38+
cl::sycl::buffer<T, 1> bufferC(VC.data(), numOfItems);
39+
40+
deviceQueue.submit([&](cl::sycl::handler &cgh) {
41+
auto accessorA = bufferA.template get_access<sycl_read>(cgh);
42+
auto accessorB = bufferB.template get_access<sycl_read>(cgh);
43+
auto accessorC = bufferC.template get_access<sycl_write>(cgh);
44+
45+
cgh.parallel_for<class SimpleVadd<T>>(numOfItems,
46+
[=](cl::sycl::id<1> wiID) {
47+
accessorC[wiID] = accessorA[wiID] + accessorB[wiID];
48+
});
49+
});
50+
51+
deviceQueue.wait_and_throw();
52+
}
53+
54+
int main() {
55+
const size_t array_size = 4;
56+
std::array<cl::sycl::cl_int, array_size> A = {{1, 2, 3, 4}},
57+
B = {{1, 2, 3, 4}}, C;
58+
std::array<cl::sycl::cl_float, array_size> D = {{1.f, 2.f, 3.f, 4.f}},
59+
E = {{1.f, 2.f, 3.f, 4.f}}, F;
60+
simple_vadd(A, B, C);
61+
simple_vadd(D, E, F);
62+
for (unsigned int i = 0; i < array_size; i++) {
63+
if (C[i] != A[i] + B[i]) {
64+
std::cout << "The results are incorrect (element " << i << " is " << C[i]
65+
<< "!\n";
66+
return 1;
67+
}
68+
if (F[i] != D[i] + E[i]) {
69+
std::cout << "The results are incorrect (element " << i << " is " << F[i]
70+
<< "!\n";
71+
return 1;
72+
}
73+
}
74+
std::cout << "The results are correct!\n";
75+
return 0;
76+
}

SYCL/Basic/aot/accelerator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//==----- accelerator.cpp - AOT compilation for fpga devices using aoc ------==//
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: aoc, accelerator
10+
11+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %S/Inputs/aot.cpp -o %t.out
12+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
13+
// XFAIL: *

SYCL/Basic/aot/cpu.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//==----- cpu.cpp - AOT compilation for cpu devices using opencl-aot --------==//
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, cpu
10+
11+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice %S/Inputs/aot.cpp -o %t.out
12+
// RUN: %CPU_RUN_PLACEHOLDER %t.out

SYCL/Basic/aot/gpu.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//==----- gpu.cpp - AOT compilation for gen devices using GEN compiler ------==//
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: ocloc, gpu
10+
// UNSUPPORTED: cuda
11+
// CUDA is not compatible with SPIR.
12+
13+
// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen-unknown-unknown-sycldevice -Xsycl-target-backend=spir64_gen-unknown-unknown-sycldevice "-device skl" %S/Inputs/aot.cpp -o %t.out
14+
// RUN: %GPU_RUN_PLACEHOLDER %t.out

SYCL/Basic/aot/spec_const_aot.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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>() << "\n";
36+
cl::sycl::program prog(q.get_context());
37+
38+
cl::sycl::experimental::spec_constant<int32_t, MyInt32Const> i32 =
39+
prog.set_spec_constant<MyInt32Const>(10);
40+
41+
prog.build_with_kernel_type<Kernel>();
42+
43+
std::vector<int> vec(1);
44+
{
45+
cl::sycl::buffer<int, 1> buf(vec.data(), vec.size());
46+
47+
q.submit([&](cl::sycl::handler &cgh) {
48+
auto acc = buf.get_access<cl::sycl::access::mode::write>(cgh);
49+
cgh.single_task<Kernel>(
50+
prog.get_kernel<Kernel>(),
51+
[=]() {
52+
acc[0] = i32.get();
53+
});
54+
});
55+
}
56+
bool passed = true;
57+
int val = vec[0];
58+
int gold = 0; // with AOT, spec constant is set to C++ default for the type
59+
60+
if (val != gold) {
61+
std::cout << "*** ERROR: " << val << " != " << gold << "(gold)\n";
62+
passed = false;
63+
}
64+
std::cout << (passed ? "passed\n" : "FAILED\n");
65+
return passed ? 0 : 1;
66+
}

SYCL/Basic/aot/with-llvm-bc.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//==----- with-llvm-bc.cpp - SYCL kernel with LLVM IR bitcode as binary ----==//
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: cpu, dump_ir
10+
11+
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown-sycldevice -c %S/Inputs/aot.cpp -o %t.o
12+
// RUN: %clangxx -fsycl -fsycl-link-targets=spir64-unknown-unknown-sycldevice %t.o -o %t.spv
13+
// RUN: llvm-spirv -r %t.spv -o %t.bc
14+
// RUN: %clangxx -fsycl -fsycl-add-targets=spir64:%t.bc %t.o -o %t.out
15+
//
16+
// Only CPU supports LLVM IR bitcode as a binary
17+
// RUN: %CPU_RUN_PLACEHOLDER %t.out

SYCL/Basic/bit_cast/bit_cast.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
#include <CL/sycl.hpp>
8+
9+
#include <iostream>
10+
#include <math.h>
11+
#include <type_traits>
12+
13+
constexpr cl::sycl::access::mode sycl_write = cl::sycl::access::mode::write;
14+
15+
template <typename To, typename From>
16+
class BitCastKernel;
17+
18+
template <typename To, typename From>
19+
To doBitCast(const From &ValueToConvert) {
20+
std::vector<To> Vec(1);
21+
{
22+
sycl::buffer<To, 1> Buf(Vec.data(), 1);
23+
sycl::queue Queue;
24+
Queue.submit([&](sycl::handler &cgh) {
25+
auto acc = Buf.template get_access<sycl_write>(cgh);
26+
cgh.single_task<class BitCastKernel<To, From>>([=]() {
27+
// TODO: change to sycl::bit_cast in the future
28+
acc[0] = sycl::detail::bit_cast<To>(ValueToConvert);
29+
});
30+
});
31+
}
32+
return Vec[0];
33+
}
34+
35+
template <typename To, typename From>
36+
int test(const From &Value) {
37+
auto ValueConvertedTwoTimes = doBitCast<From>(doBitCast<To>(Value));
38+
bool isOriginalValueEqualsToConvertedTwoTimes = false;
39+
if (std::is_integral<From>::value) {
40+
isOriginalValueEqualsToConvertedTwoTimes = Value == ValueConvertedTwoTimes;
41+
} else if ((std::is_floating_point<From>::value) || std::is_same<From, cl::sycl::half>::value) {
42+
static const float Epsilon = 0.0000001f;
43+
isOriginalValueEqualsToConvertedTwoTimes = fabs(Value - ValueConvertedTwoTimes) < Epsilon;
44+
} else {
45+
std::cerr << "Type " << typeid(From).name() << " neither integral nor floating point nor cl::sycl::half\n";
46+
return 1;
47+
}
48+
if (!isOriginalValueEqualsToConvertedTwoTimes) {
49+
std::cerr << "FAIL: Original value which is " << Value << " != value converted two times which is " << ValueConvertedTwoTimes << "\n";
50+
return 1;
51+
}
52+
std::cout << "PASS\n";
53+
return 0;
54+
}
55+
56+
int main() {
57+
int ReturnCode = 0;
58+
59+
std::cout << "cl::sycl::half to unsigned short ...\n";
60+
ReturnCode += test<unsigned short>(cl::sycl::half(1.0f));
61+
62+
std::cout << "unsigned short to cl::sycl::half ...\n";
63+
ReturnCode += test<cl::sycl::half>(static_cast<unsigned short>(16384));
64+
65+
std::cout << "cl::sycl::half to short ...\n";
66+
ReturnCode += test<short>(cl::sycl::half(1.0f));
67+
68+
std::cout << "short to cl::sycl::half ...\n";
69+
ReturnCode += test<cl::sycl::half>(static_cast<short>(16384));
70+
71+
std::cout << "int to float ...\n";
72+
ReturnCode += test<float>(static_cast<int>(2));
73+
74+
std::cout << "float to int ...\n";
75+
ReturnCode += test<int>(static_cast<float>(-2.4f));
76+
77+
std::cout << "unsigned int to float ...\n";
78+
ReturnCode += test<float>(static_cast<unsigned int>(6));
79+
80+
std::cout << "float to unsigned int ...\n";
81+
ReturnCode += test<unsigned int>(static_cast<float>(-2.4f));
82+
83+
return ReturnCode;
84+
}

0 commit comments

Comments
 (0)