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

Commit 6912242

Browse files
authored
[SYCL][ESIMD] Tests on Spec_Const feature for all basic types (#135)
1 parent 1a3071e commit 6912242

12 files changed

+423
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//==--------------- spec_const_common.h - DPC++ ESIMD on-device test -----===//
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+
// The test checks that ESIMD kernels support specialization constants for all
9+
// basic types, particularly a specialization constant can be redifined and
10+
// correct new value is used after redefinition.
11+
12+
#include "esimd_test_utils.hpp"
13+
14+
#include <CL/sycl.hpp>
15+
#include <CL/sycl/INTEL/esimd.hpp>
16+
17+
#include <iostream>
18+
#include <vector>
19+
20+
using namespace cl::sycl;
21+
22+
template <typename AccessorTy>
23+
ESIMD_INLINE void do_store(AccessorTy acc, int i, spec_const_t val) {
24+
using namespace sycl::INTEL::gpu;
25+
// scatter function, that is used in scalar_store, can only process types
26+
// whose size is no more than 4 bytes.
27+
#if (STORE == 0)
28+
// bool
29+
scalar_store(acc, i, val ? 1 : 0);
30+
#elif (STORE == 1)
31+
// block
32+
block_store(acc, i, simd<spec_const_t, 2>{val});
33+
#else
34+
static_assert(STORE == 2, "Unspecified store");
35+
// scalar
36+
scalar_store(acc, i, val);
37+
#endif
38+
}
39+
40+
class ConstID;
41+
class TestKernel;
42+
43+
int main(int argc, char **argv) {
44+
queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());
45+
46+
auto dev = q.get_device();
47+
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";
48+
49+
std::vector<container_t> etalon = {DEF_VAL, REDEF_VAL};
50+
const size_t n_times = etalon.size();
51+
std::vector<container_t> output(n_times);
52+
53+
bool passed = true;
54+
for (int i = 0; i < n_times; i++) {
55+
try {
56+
sycl::program prg(q.get_context());
57+
58+
// Checking that already initialized constant can be overwritten.
59+
// According to standards proposals:
60+
// A cl::sycl::experimental::spec_constant object is considered
61+
// initialized once the result of a cl::sycl::program::set_spec_constant
62+
// is assigned to it.
63+
// A specialization constant value can be overwritten if the program was
64+
// not built before by recalling set_spec_constant with the same ID and
65+
// the new value. Although the type T of the specialization constant
66+
// must remain the same.
67+
auto spec_const = prg.set_spec_constant<ConstID>((spec_const_t)DEF_VAL);
68+
if (i % 2 != 0)
69+
spec_const = prg.set_spec_constant<ConstID>((spec_const_t)REDEF_VAL);
70+
71+
prg.build_with_kernel_type<TestKernel>();
72+
73+
sycl::buffer<container_t, 1> buf(output.data(), output.size());
74+
75+
q.submit([&](sycl::handler &cgh) {
76+
auto acc = buf.get_access<sycl::access::mode::write>(cgh);
77+
cgh.single_task<TestKernel>(
78+
prg.get_kernel<TestKernel>(),
79+
[=]() SYCL_ESIMD_KERNEL { do_store(acc, i, spec_const.get()); });
80+
});
81+
} catch (cl::sycl::exception const &e) {
82+
std::cout << "SYCL exception caught: " << e.what() << '\n';
83+
return e.get_cl_code();
84+
}
85+
86+
if (output[i] != etalon[i]) {
87+
passed = false;
88+
std::cout << "comparison error -- case #" << i << " -- ";
89+
std::cout << "output: " << output[i] << ", ";
90+
std::cout << "etalon: " << etalon[i] << std::endl;
91+
}
92+
}
93+
94+
if (passed) {
95+
std::cout << "passed" << std::endl;
96+
return 0;
97+
}
98+
99+
std::cout << "FAILED" << std::endl;
100+
return 1;
101+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//==--------------- spec_const_bool.cpp - DPC++ ESIMD on-device test -----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL true
22+
#define REDEF_VAL false
23+
#define STORE 0
24+
25+
// In this case container type is set to unsigned char to be able to use
26+
// esimd memory interfaces to pollute container.
27+
using spec_const_t = bool;
28+
using container_t = uint8_t;
29+
30+
#include "Inputs/spec_const_common.hpp"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//==--------------- spec_const_char.cpp - DPC++ ESIMD on-device test -----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// Linux Level Zero fail with assertion in SPIRV about specialization constant
16+
// type size.
17+
// XFAIL: level_zero
18+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
19+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
20+
// UNSUPPORTED: cuda
21+
22+
#include <cstdint>
23+
24+
#define DEF_VAL -22
25+
#define REDEF_VAL 33
26+
#define STORE 2
27+
28+
using spec_const_t = int8_t;
29+
using container_t = int8_t;
30+
31+
#include "Inputs/spec_const_common.hpp"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==--------------- spec_const_double.cpp - DPC++ ESIMD on-device test ---===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL 9.1029384756e+11
22+
#define REDEF_VAL -1.4432211654e-10
23+
#define STORE 1
24+
25+
using spec_const_t = double;
26+
using container_t = double;
27+
28+
#include "Inputs/spec_const_common.hpp"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==--------------- spec_const_float.cpp - DPC++ ESIMD on-device test ----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL -1.456789e-5
22+
#define REDEF_VAL 2.9865432e+5
23+
#define STORE 2
24+
25+
using spec_const_t = float;
26+
using container_t = float;
27+
28+
#include "Inputs/spec_const_common.hpp"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==--------------- spec_const_int.cpp - DPC++ ESIMD on-device test ------===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL 100500
22+
#define REDEF_VAL -44556677
23+
#define STORE 2
24+
25+
using spec_const_t = int32_t;
26+
using container_t = int32_t;
27+
28+
#include "Inputs/spec_const_common.hpp"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==-------------- spec_const_int64.cpp - DPC++ ESIMD on-device test -----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL -99776644220011ll
22+
#define REDEF_VAL 22001144668855ll
23+
#define STORE 1
24+
25+
using spec_const_t = int64_t;
26+
using container_t = int64_t;
27+
28+
#include "Inputs/spec_const_common.hpp"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//==--------------- spec_const_short.cpp - DPC++ ESIMD on-device test ----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// Linux Level Zero fail with assertion in SPIRV about specialization constant
16+
// type size.
17+
// XFAIL: level_zero
18+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
19+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
20+
// UNSUPPORTED: cuda
21+
22+
#include <cstdint>
23+
24+
#define DEF_VAL -30572
25+
#define REDEF_VAL 24794
26+
#define STORE 2
27+
28+
using spec_const_t = int16_t;
29+
using container_t = int16_t;
30+
31+
#include "Inputs/spec_const_common.hpp"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//==--------------- spec_const_uchar.cpp - DPC++ ESIMD on-device test ----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// Linux Level Zero fail with assertion in SPIRV about specialization constant
16+
// type size.
17+
// XFAIL: level_zero
18+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
19+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
20+
// UNSUPPORTED: cuda
21+
22+
#include <cstdint>
23+
24+
#define DEF_VAL 128
25+
#define REDEF_VAL 33
26+
#define STORE 2
27+
28+
using spec_const_t = uint8_t;
29+
using container_t = uint8_t;
30+
31+
#include "Inputs/spec_const_common.hpp"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//==--------------- spec_const_uint.cpp - DPC++ ESIMD on-device test -----===//
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+
// REQUIRES: gpu
9+
// On Windows vector compute backend (as a part of IGC) uses llvm-7 and llvm-7
10+
// based spirv translator. This translator doesn't have the ability to overwrite
11+
// the default specialization constant value. That is why the support in Windows
12+
// driver is disabled at all. This feature will start working on Windows when
13+
// the llvm version is switched to 9.
14+
// UNSUPPORTED: windows
15+
// RUN: %clangxx-esimd -fsycl -I%S/.. %s -o %t.out
16+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
17+
// UNSUPPORTED: cuda
18+
19+
#include <cstdint>
20+
21+
#define DEF_VAL 0xdeadcafe
22+
#define REDEF_VAL 0x4badbeaf
23+
#define STORE 2
24+
25+
using spec_const_t = uint32_t;
26+
using container_t = uint32_t;
27+
28+
#include "Inputs/spec_const_common.hpp"

0 commit comments

Comments
 (0)