-
Notifications
You must be signed in to change notification settings - Fork 729
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NATIVECPU] Fix local scope module variables for native cpu
Although local scope variables inside the kernel are less common in SYCL, they can happen with hierarchical. This fixes the problem by adding a pass to replace the local scope variables which start life as globals with a struct which is allocated on the stack. Additionally, this required updating of the code which renames and removes kernel based on wrappers and vecz success. To simplify this we run the OCK utility pass TransferKernelMetadata which adds metadata to store the original kernel name. This in turn simplifies this code significantly.
- Loading branch information
Showing
3 changed files
with
75 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
sycl/test/check_device_code/native_cpu/local_module_scope.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
// | ||
// SYCL 2020 Conformance Test Suite | ||
// | ||
// Copyright (c) 2023 The Khronos Group Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
*******************************************************************************/ | ||
|
||
#include "sycl.hpp" | ||
|
||
// RUN: %clangxx -fsycl -fsycl-targets=native_cpu -Xclang -sycl-std=2020 -mllvm -sycl-opt -mllvm -inline-threshold=500 -mllvm -sycl-native-cpu-no-vecz -mllvm -sycl-native-dump-device-ir %s | FileCheck %s | ||
|
||
// Check that local types is created and place on the stack | ||
// We also check that the attribute mux-orig-fn is created as this is needed to | ||
// find the original function after this pass is run | ||
|
||
// CHECK: %localVarTypes = type { ptr addrspace(1) } | ||
// CHECK: define void @_ZTS25kernel_separate_lambda_wgILi1ELi4EiE.NativeCPUKernel{{.*}} #[[ATTR:[0-9]*]] | ||
// CHECK: alloca %localVarTypes | ||
// CHECK: attributes #[[ATTR]] = {{.*}} "mux-orig-fn"="_ZTS25kernel_separate_lambda_wgILi1ELi4EiE" | ||
template <int dims, int size, typename T = int> | ||
struct kernel_separate_lambda_wg; | ||
|
||
int main() { | ||
sycl::queue queue; | ||
|
||
constexpr int dims = 1; | ||
constexpr int size = 4; | ||
|
||
std::array<int, size> data; | ||
|
||
const auto range = sycl::range<dims>(size); | ||
const auto range_wg = sycl::range<dims>(1); | ||
{ | ||
sycl::buffer<int, dims> buf(data.data(), range); | ||
|
||
queue.submit([&](sycl::handler& cgh) { | ||
auto acc = sycl::accessor(buf, cgh, sycl::write_only); | ||
cgh.parallel_for_work_group<kernel_separate_lambda_wg<dims, size>>( | ||
range, range_wg, | ||
[=](auto group) { | ||
acc[group.get_group_id()] = 42; | ||
}); | ||
}); | ||
queue.wait_and_throw(); | ||
} | ||
return 0; | ||
} |