-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Implement the sycl_oneapi_raw_kernel_arg extension #14335
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
Merged
steffenlarsen
merged 13 commits into
intel:sycl
from
steffenlarsen:steffen/raw_kernel_arg_impl
Jul 3, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7c336e
[SYCL] Implement the sycl_oneapi_raw_kernel_arg extension
steffenlarsen ac2f4a6
Fix formatting
steffenlarsen 54991ae
Add work-around for pointer arguments in OpenCL
steffenlarsen 3258742
Revert "Add work-around for pointer arguments in OpenCL"
steffenlarsen e1e9aac
Move extension and make it experimental
steffenlarsen e375ede
Add test for testing different combinations of args at different indices
steffenlarsen e7479bd
Add windows symbols
steffenlarsen 4bf32ed
Merge branch 'sycl' into steffen/raw_kernel_arg_impl
steffenlarsen 1193412
Add backend support section and effect
steffenlarsen 7b8253d
Move definition to experimental namespace
steffenlarsen 83777c8
Merge branch 'sycl' into steffen/raw_kernel_arg_impl
steffenlarsen 4dfc86f
Update sycl.hpp
steffenlarsen f138550
Update sycl_symbols_windows.dump
steffenlarsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
sycl/include/sycl/ext/oneapi/experimental/raw_kernel_arg.hpp
This file contains hidden or 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,34 @@ | ||
//==--- raw_kernel_arg.hpp --- SYCL extension for raw kernel args ----------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <stddef.h> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
|
||
class handler; | ||
|
||
namespace ext::oneapi::experimental { | ||
|
||
class raw_kernel_arg { | ||
public: | ||
raw_kernel_arg(const void *bytes, size_t count) | ||
: MArgData(bytes), MArgSize(count) {} | ||
|
||
private: | ||
const void *MArgData; | ||
size_t MArgSize; | ||
|
||
friend class sycl::handler; | ||
}; | ||
|
||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
// REQUIRES: aspect-usm_shared_allocations | ||
// REQUIRES: ocloc && level_zero | ||
|
||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Tests raw_kernel_arg in different combinations. | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
constexpr size_t NumArgs = 4; | ||
|
||
auto constexpr CLSource = R"===( | ||
__kernel void Kernel(int in1, char in2, __global float *out, float in3) { | ||
out[0] = (float)in1 + (float)in2 + in3; | ||
} | ||
)==="; | ||
|
||
template <typename T> | ||
void SetArg(sycl::handler &CGH, T &&Arg, size_t Index, size_t Iteration) { | ||
// Pick how we set the arg based on the bit at Index in Iteration. | ||
if (Iteration & (1 << Index)) | ||
CGH.set_arg(Index, sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&Arg, sizeof(T))); | ||
else | ||
CGH.set_arg(Index, Arg); | ||
} | ||
|
||
int main() { | ||
sycl::queue Q; | ||
|
||
auto SourceKB = | ||
sycl::ext::oneapi::experimental::create_kernel_bundle_from_source( | ||
Q.get_context(), | ||
sycl::ext::oneapi::experimental::source_language::opencl, CLSource); | ||
auto ExecKB = sycl::ext::oneapi::experimental::build(SourceKB); | ||
|
||
int Failed = 0; | ||
|
||
float *Out = sycl::malloc_shared<float>(1, Q); | ||
int32_t IntVal = 42; | ||
char CharVal = 100; | ||
float FloatVal = 1.23; | ||
|
||
float Expected = | ||
static_cast<float>(IntVal) + static_cast<float>(CharVal) + FloatVal; | ||
for (size_t I = 0; I < (2 >> (NumArgs - 1)); ++I) { | ||
Out[0] = 0.0f; | ||
Q.submit([&](sycl::handler &CGH) { | ||
SetArg(CGH, IntVal, 0, I); | ||
SetArg(CGH, CharVal, 1, I); | ||
SetArg(CGH, Out, 2, I); | ||
SetArg(CGH, FloatVal, 3, I); | ||
CGH.single_task(ExecKB.ext_oneapi_get_kernel("Kernel")); | ||
}).wait(); | ||
|
||
if (Out[0] != Expected) { | ||
std::cout << "Failed for iteration " << I << ": " << Out[0] | ||
<< " != " << Expected << std::endl; | ||
++Failed; | ||
} | ||
} | ||
|
||
sycl::free(Out, Q); | ||
return Failed; | ||
} |
This file contains hidden or 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,63 @@ | ||
// REQUIRES: aspect-usm_shared_allocations | ||
// REQUIRES: ocloc && level_zero | ||
|
||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Tests raw_kernel_arg with pointers and scalars to different types with | ||
// different sizes. | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
auto constexpr CLSource = R"===( | ||
__kernel void Kernel1(int in, __global int *out) { | ||
out[0] = in; | ||
} | ||
|
||
__kernel void Kernel2(short in, __global short *out) { | ||
out[0] = in; | ||
} | ||
)==="; | ||
|
||
int main() { | ||
sycl::queue Q; | ||
|
||
auto SourceKB = | ||
sycl::ext::oneapi::experimental::create_kernel_bundle_from_source( | ||
Q.get_context(), | ||
sycl::ext::oneapi::experimental::source_language::opencl, CLSource); | ||
auto ExecKB = sycl::ext::oneapi::experimental::build(SourceKB); | ||
|
||
int32_t *IntOut = sycl::malloc_shared<int32_t>(1, Q); | ||
int16_t *ShortOut = sycl::malloc_shared<int16_t>(1, Q); | ||
int32_t IntVal = 42; | ||
int16_t ShortVal = 24; | ||
|
||
for (size_t I = 0; I < 2; ++I) { | ||
std::string KernelName = I == 0 ? "Kernel1" : "Kernel2"; | ||
Q.submit([&](sycl::handler &CGH) { | ||
sycl::ext::oneapi::experimental::raw_kernel_arg KernelArg0 = | ||
I == 0 ? sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&IntVal, sizeof(int32_t)) | ||
: sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&ShortVal, sizeof(int16_t)); | ||
sycl::ext::oneapi::experimental::raw_kernel_arg KernelArg1 = | ||
I == 0 ? sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&IntOut, sizeof(int32_t *)) | ||
: sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&ShortOut, sizeof(int16_t *)); | ||
|
||
CGH.set_arg(0, KernelArg0); | ||
CGH.set_arg(1, KernelArg1); | ||
CGH.single_task(ExecKB.ext_oneapi_get_kernel(KernelName)); | ||
}).wait(); | ||
} | ||
|
||
assert(IntOut[0] == IntVal); | ||
assert(ShortOut[0] == ShortVal); | ||
|
||
sycl::free(IntOut, Q); | ||
sycl::free(ShortOut, Q); | ||
return 0; | ||
} |
This file contains hidden or 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,62 @@ | ||
// REQUIRES: aspect-usm_shared_allocations | ||
// REQUIRES: ocloc && level_zero | ||
|
||
// RUN: %{build} -o %t.out | ||
// RUN: %{run} %t.out | ||
|
||
// Tests raw_kernel_arg with pointers and scalars to different 32-bit types. | ||
|
||
#include <sycl/detail/core.hpp> | ||
#include <sycl/usm.hpp> | ||
|
||
auto constexpr CLSource = R"===( | ||
__kernel void Kernel1(int in, __global int *out) { | ||
out[0] = in; | ||
} | ||
|
||
__kernel void Kernel2(float in, __global float *out) { | ||
out[0] = in; | ||
} | ||
)==="; | ||
|
||
int main() { | ||
sycl::queue Q; | ||
|
||
auto SourceKB = | ||
sycl::ext::oneapi::experimental::create_kernel_bundle_from_source( | ||
Q.get_context(), | ||
sycl::ext::oneapi::experimental::source_language::opencl, CLSource); | ||
auto ExecKB = sycl::ext::oneapi::experimental::build(SourceKB); | ||
|
||
int32_t *IntOut = sycl::malloc_shared<int32_t>(1, Q); | ||
float *FloatOut = sycl::malloc_shared<float>(1, Q); | ||
int32_t IntVal = 42; | ||
float FloatVal = 3.12f; | ||
|
||
for (size_t I = 0; I < 2; ++I) { | ||
std::string KernelName = I == 0 ? "Kernel1" : "Kernel2"; | ||
Q.submit([&](sycl::handler &CGH) { | ||
sycl::ext::oneapi::experimental::raw_kernel_arg KernelArg0 = | ||
I == 0 ? sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&IntVal, sizeof(int32_t)) | ||
: sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&FloatVal, sizeof(float)); | ||
sycl::ext::oneapi::experimental::raw_kernel_arg KernelArg1 = | ||
I == 0 ? sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&IntOut, sizeof(int32_t *)) | ||
: sycl::ext::oneapi::experimental::raw_kernel_arg( | ||
&FloatOut, sizeof(float *)); | ||
|
||
CGH.set_arg(0, KernelArg0); | ||
CGH.set_arg(1, KernelArg1); | ||
CGH.single_task(ExecKB.ext_oneapi_get_kernel(KernelName)); | ||
}).wait(); | ||
} | ||
|
||
assert(IntOut[0] == IntVal); | ||
assert(FloatOut[0] == FloatVal); | ||
|
||
sycl::free(IntOut, Q); | ||
sycl::free(FloatOut, Q); | ||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.