Skip to content

Commit 457f307

Browse files
committed
Test for inlining
1 parent c96eca6 commit 457f307

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/***************************************************************************
2+
*
3+
* Copyright (C) Codeplay Software Ltd.
4+
*
5+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM
6+
* Exceptions. See https://llvm.org/LICENSE.txt for license information.
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* SYCLcompat API
16+
*
17+
* launch_inlining.cpp
18+
*
19+
* Description:
20+
* Ensure kernels are fully inlined
21+
**************************************************************************/
22+
23+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -fgpu-inline-threshold=0 %if cl_options %{/clang:-S /clang:-emit-llvm%} %else %{-S -emit-llvm%} %s -o - | FileCheck %s
24+
//TODO(joe): update_cc_test_checks.py
25+
#include <sycl/detail/core.hpp>
26+
#include <sycl/group_barrier.hpp>
27+
#include <syclcompat/launch.hpp>
28+
#include <syclcompat/memory.hpp>
29+
30+
namespace compat_exp = syclcompat::experimental;
31+
namespace sycl_exp = sycl::ext::oneapi::experimental;
32+
namespace sycl_intel_exp = sycl::ext::intel::experimental;
33+
34+
static constexpr int LOCAL_MEM_SIZE = 1024;
35+
36+
template <typename T>
37+
T dummy_fn(T input){
38+
return -input;
39+
}
40+
41+
// CHECK: define {{.*}}spir_kernel{{.*}}write_mem_kernel{{.*}} {
42+
// CHECK-NOT: call {{.*}}write_mem_kernel
43+
// CHECK-NOT: call {{.*}}dummy_fn
44+
// CHECK: }
45+
46+
template <typename T> void write_mem_kernel(T *data, int num_elements) {
47+
const int id =
48+
sycl::ext::oneapi::this_work_item::get_nd_item<1>().get_global_id(0);
49+
if (id < num_elements) {
50+
data[id] = dummy_fn(static_cast<T>(id));
51+
}
52+
};
53+
54+
// CHECK: define {{.*}}spir_kernel{{.*}}dynamic_local_mem_typed_kernel{{.*}} {
55+
// CHECK-NOT: call {{.*}}dynamic_local_mem_typed_kernel
56+
// CHECK-NOT: call {{.*}}dummy_fn
57+
// CHECK: }
58+
template <typename T>
59+
void dynamic_local_mem_typed_kernel(T *data, char *local_mem) {
60+
constexpr size_t num_elements = LOCAL_MEM_SIZE / sizeof(T);
61+
T *typed_local_mem = reinterpret_cast<T *>(local_mem);
62+
63+
const int id =
64+
sycl::ext::oneapi::this_work_item::get_nd_item<1>().get_global_id(0);
65+
if (id < num_elements) {
66+
typed_local_mem[id] = static_cast<T>(id);
67+
}
68+
sycl::group_barrier(sycl::ext::oneapi::this_work_item::get_work_group<1>());
69+
if (id < num_elements) {
70+
data[id] = dummy_fn(typed_local_mem[num_elements - id - 1]);
71+
}
72+
};
73+
74+
int test_write_mem() {
75+
compat_exp::launch_policy my_dim3_config(syclcompat::dim3{32});
76+
77+
const int memsize = 1024;
78+
int *d_a = (int *)syclcompat::malloc(memsize);
79+
compat_exp::launch<write_mem_kernel<int>>(my_dim3_config, d_a,
80+
memsize / sizeof(int))
81+
.wait();
82+
83+
syclcompat::free(d_a);
84+
return 0;
85+
}
86+
87+
int test_lmem_launch() {
88+
using T = int;
89+
// A property constructed at runtime:
90+
sycl_intel_exp::cache_config my_cache_config{sycl_intel_exp::large_slm};
91+
92+
int local_mem_size = LOCAL_MEM_SIZE; // rt value
93+
94+
size_t num_elements = local_mem_size / sizeof(T);
95+
T *d_a = (T *)syclcompat::malloc(local_mem_size);
96+
97+
compat_exp::launch_policy my_config(
98+
sycl::nd_range<1>{{256}, {256}},
99+
compat_exp::local_mem_size(local_mem_size));
100+
101+
compat_exp::launch<dynamic_local_mem_typed_kernel<int>>(my_config, d_a)
102+
.wait();
103+
104+
syclcompat::free(d_a);
105+
106+
return 0;
107+
}
108+

0 commit comments

Comments
 (0)