Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Add support for JIT-ing in AMD and NVIDIA backends #14280

Merged
merged 31 commits into from
Jul 25, 2024
Merged
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4158578
[SYCL] Introduce SYCL_JIT_KERNELS env var
jchlanda Mar 15, 2024
9bf827f
[SYCL] Extend kernel fusion with JIT-ing
jchlanda Mar 15, 2024
0bc1146
[SYCL] Define JIT pipeline and introduce materializer pass
jchlanda Mar 15, 2024
1aaf3e5
[SYCL] Add functionality to create/cache/retrieve materialized kernels
jchlanda Jun 20, 2024
8221f0f
[SYCL] Introduce SYCL_JIT_TARGET_{CPU,FEATURES} env variables
jchlanda Jun 24, 2024
434bc9f
[SYCL] Document SYCL_JIT_{KERNELS,TARGET_CPU,TARGET_FEATURES} env vars
jchlanda Jun 27, 2024
c3c9abc
PR feedback
jchlanda Jul 5, 2024
df9133f
PR feedback 2
jchlanda Jul 10, 2024
b725f00
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 10, 2024
c23a986
Merge fixes
jchlanda Jul 10, 2024
bb1e3f9
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 10, 2024
93b07a7
Merge fixes
jchlanda Jul 11, 2024
cf4ec36
Debug printout fix
jchlanda Jul 11, 2024
f86d998
PR feedback 3
jchlanda Jul 11, 2024
e6169ce
Correct assert
jchlanda Jul 12, 2024
5385ad5
strstr returns a pointer on success
jchlanda Jul 12, 2024
0a3ecf1
Use default pipeline
jchlanda Jul 15, 2024
1bc67ce
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 15, 2024
8bef1d4
Docs tidy-up
jchlanda Jul 16, 2024
681da06
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 16, 2024
391ce43
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 16, 2024
1fb459a
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 22, 2024
5f3d2c9
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 22, 2024
94b5ad5
Constexpr debug output in program manager
jchlanda Jul 24, 2024
a876daa
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 24, 2024
21c814f
build fix
jchlanda Jul 24, 2024
87f1a87
orfer of includes
jchlanda Jul 24, 2024
509e3e6
JIT e2e test
jchlanda Jul 24, 2024
d8c6499
clang format the test
jchlanda Jul 24, 2024
66bd110
include fix in the test
jchlanda Jul 24, 2024
a403149
Merge remote-tracking branch 'upstream/sycl' into jakub/jit_spec_const
jchlanda Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions sycl/test-e2e/AmdNvidiaJIT/kernel_and_bundle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// REQUIRES: cuda || hip

// RUN: %{build} -fsycl-embed-ir -o %t.out
// RUN: env SYCL_JIT_AMDGCN_PTX_KERNELS=1 env SYCL_JIT_COMPILER_DEBUG="sycl-spec-const-materializer" %{run} %t.out &> %t.txt ; FileCheck %s --input-file %t.txt

#include <sycl/sycl.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sycl/sycl.hpp is not permitted in E2E tests. You want sycl/detail/core.hpp and then probably some other headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


constexpr size_t Size = 16;
constexpr int SeedKernel = 3;
constexpr int SeedKernelBundle = 5;

constexpr int ValInt = 11;
constexpr std::array<int, 2> ValArr{13, 17};
const static sycl::specialization_id<int> SpecConstInt;
const static sycl::specialization_id<std::array<int, 2>> SpecConstArr;

int validate(int Seed, std::vector<int> &Input, std::vector<int> &Output) {
for (int i = 0; i < Size; ++i) {
int Expected = ValInt + ValArr[0] + ValArr[1] + Input[i] + Seed;
if (Expected != Output[i]) {
return -1;
}
}
return 0;
}

// CHECK: Working on function:
// CHECK: ==================
// CHECK: _ZTSZ15runKernelBundleN4sycl3_V15queueERSt6vectorIiSaIiEES5_E10WoofBundle
int runKernelBundle(sycl::queue Queue, std::vector<int> &Input,
std::vector<int> &Output) {
for (int i = 0; i < Size; ++i) {
Output[i] = 42;
Input[i] = i * i;
}

sycl::device Device;
sycl::context Context = Queue.get_context();

auto InputBundle =
sycl::get_kernel_bundle<class WoofBundle, sycl::bundle_state::input>(
Context, {Device});
InputBundle.set_specialization_constant<SpecConstInt>(ValInt);
InputBundle.set_specialization_constant<SpecConstArr>(ValArr);

auto ExecBundle = sycl::build(InputBundle);

{
sycl::buffer<int> OutBuff(Output.data(), Output.size());
sycl::buffer<int> InBuff(Input.data(), Input.size());
Queue.submit([&](sycl::handler &cgh) {
sycl::accessor OutAcc(OutBuff, cgh, sycl::write_only);
sycl::accessor InAcc(InBuff, cgh, sycl::read_only);
cgh.use_kernel_bundle(ExecBundle);
cgh.template parallel_for<class WoofBundle>(
sycl::range<1>{Size}, [=](sycl::id<1> i, sycl::kernel_handler kh) {
const auto KernelSpecConst =
kh.get_specialization_constant<SpecConstInt>();
const auto KernelSpecConstArr =
kh.get_specialization_constant<SpecConstArr>();
OutAcc[i] = KernelSpecConst + KernelSpecConstArr[0] +
KernelSpecConstArr[1] + InAcc[i] + SeedKernelBundle;
});
});
Queue.wait_and_throw();
}

return validate(SeedKernelBundle, Input, Output);
}

// CHECK: Working on function:
// CHECK: ==================
// CHECK: _ZTSZZ9runKernelN4sycl3_V15queueERSt6vectorIiSaIiEES5_ENKUlRT_E_clINS0_7handlerEEEDaS7_E10WoofKernel
int runKernel(sycl::queue Queue, std::vector<int> &Input,
std::vector<int> &Output) {
for (int i = 0; i < Size; ++i) {
Output[i] = 42;
Input[i] = i * i;
}
{
sycl::buffer<int> OutBuff(Output.data(), Output.size());
sycl::buffer<int> InBuff(Input.data(), Input.size());
Queue.submit([&](auto &CGH) {
sycl::accessor OutAcc(OutBuff, CGH, sycl::write_only);
sycl::accessor InAcc(InBuff, CGH, sycl::read_only);
CGH.template set_specialization_constant<SpecConstInt>(ValInt);
CGH.template set_specialization_constant<SpecConstArr>(ValArr);
CGH.template parallel_for<class WoofKernel>(
sycl::range<1>{Size}, [=](sycl::id<1> i, sycl::kernel_handler KH) {
const auto KernelSpecConst =
KH.get_specialization_constant<SpecConstInt>();
const auto KernelSpecConstArr =
KH.get_specialization_constant<SpecConstArr>();
OutAcc[i] = KernelSpecConst + KernelSpecConstArr[0] +
KernelSpecConstArr[1] + InAcc[i] + SeedKernel;
});
});
Queue.wait_and_throw();
}

return validate(SeedKernel, Input, Output);
}

int main() {
std::vector<int> Input(Size);
std::vector<int> Output(Size);
sycl::queue Queue;
return runKernel(Queue, Input, Output) |
runKernelBundle(Queue, Input, Output);
}
Loading