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] Implement SYCL part of sycl_ext_oneapi_prefetch #11458

Merged
merged 26 commits into from
Oct 16, 2023

Conversation

KornevNikita
Copy link
Contributor

Spec: https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_prefetch.asciidoc

The joint_prefetch functions will be done is a separate patch.

This implementation also requires a patch for llvm-spirv translator. SPIRVWriter should handle these new annotations and create the appropriate decorations in spv representation.

@KornevNikita KornevNikita requested review from a team as code owners October 6, 2023 16:15
llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp Outdated Show resolved Hide resolved
llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/properties/properties.hpp Outdated Show resolved Hide resolved

char data[] = {0, 1, 2, 3};

// CHECK: [[PREFETCH_STR:@.*]] = private unnamed_addr addrspace(1) constant [19 x i8] c"sycl-prefetch-hint\00", section "llvm.metadata"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these manually written? If so, do we have an utility script to generate them automatically? If yes, one might need to disable instrumentation/use -O1 to get a more readable IR.

namespace syclex = sycl::ext::oneapi::experimental;
sycl::queue q;
void *dataPtr = &data;
q.parallel_for(1, [=](sycl::id<1> idx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can be single_task. I'd also want to see an E2E test with this used in non-uniform control flow (I don't think the spec prohibits that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to single task - 7afe1c9. I'm going to add E2E tests a bit later when the whole feature (incl. llvm-spirv translator part) is done. Not sure what do you mean by "non-uniform control". Could you please explain a bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

if (id.get_global_id(0) % 3 == 0))
  syclex::prefetch(p);

Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you've added joint_prefetch that just delegates to the per-WI one, I'm even more concerned about non-uniform control flow scenario...

@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 9, 2023 14:44 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 9, 2023 15:33 — with GitHub Actions Inactive
auto DecorIt = SpirvDecorMap.find(*Property.first);
// Leave these annotations as is. They will be processed by SPIRVWriter.
if (first == "sycl-prefetch-hint" || first == "sycl-prefetch-hint-nt") {
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't feel right to me, but it's outside of SYCL RT...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like currently it's the only way to transform these properties into spirv decorations for this pointer. I tried to create spirv.Decorations metadata instead, but the compiler eliminates them with optimization flags.
Annotation also may be eliminated, but it's much less likely.

sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 10, 2023 09:16 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 10, 2023 10:10 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 10, 2023 15:01 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 10, 2023 15:48 — with GitHub Actions Inactive
sycl/include/sycl/ext/oneapi/prefetch.hpp Outdated Show resolved Hide resolved
prefetch(
accessor<DataT, Dimensions, AccessMode, target::device, IsPlaceholder> acc,
size_t offset, size_t count, Properties properties = {}) {
prefetch((void *)&acc[offset], count * sizeof(DataT), properties);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know for sure that count elements are consecutive in memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. @Pennycook I'm not sure how it's intended to work in case of N-dim offset. Should we call the __spirv_ocl_prefetch spirv instruction several times for different memory segments in such case or there should be some constraint?

Copy link
Contributor

Choose a reason for hiding this comment

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

We struggled a bit with multi-dimensional prefetches (see the issues).

Where we landed (for now) is that the block being prefetched is assumed to be contiguous, and only the offset itself is multi-dimensional. It's effectively a shorthand to avoid computing the linear offset from the start of the buffer. Note that the specification says for the multi-dimensional cases:

Effects: Equivalent to prefetch((void*) &acc[offset], sizeof(DataT), properties).
Effects: Equivalent to prefetch((void*) &acc[offset], count, properties).

If somebody requests a multi-dimensional prefetch later, we can describe it with a range parameter in place of a size_t count, and implement it the way you suggested (by calling the instruction multiple times).

@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 11, 2023 08:49 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 11, 2023 09:32 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 12, 2023 12:18 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 12, 2023 13:11 — with GitHub Actions Inactive
@bader
Copy link
Contributor

bader commented Oct 12, 2023

@intel/dpcpp-tools-reviewers, please, take a look. The compiler change is non-functional, so should be a no brainer.

@bader bader changed the title [SYCL] Implement sycl part of sycl_ext_oneapi_prefetch [SYCL] Implement SYCL part of sycl_ext_oneapi_prefetch Oct 12, 2023
Copy link
Contributor

@asudarsa asudarsa left a comment

Choose a reason for hiding this comment

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

SYCLLowerIR changes look good to me, as they are NFC. Just a quick request about variable name. Also, I just noticed there is no test added.

Thanks

@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 13, 2023 16:07 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 13, 2023 16:24 — with GitHub Actions Inactive
@KornevNikita KornevNikita temporarily deployed to WindowsCILock October 13, 2023 17:18 — with GitHub Actions Inactive
@AlexeySachkov
Copy link
Contributor

Pre-commit failure doesn't seem related, it is covered by #11549

@AlexeySachkov AlexeySachkov merged commit e7139b0 into intel:sycl Oct 16, 2023
KornevNikita added a commit to KornevNikita/llvm that referenced this pull request Oct 19, 2023
The first part: intel#11458

Adjust the CompileTimePropertiesPass so it can convert new properties into
spirv decorations.
KornevNikita added a commit to KornevNikita/SPIRV-LLVM-Translator that referenced this pull request Oct 19, 2023
SYCL part: intel/llvm#11458
intel/llvm#11597

Handle new properties and decorate prefetch's arg.
MrSidims pushed a commit to KhronosGroup/SPIRV-LLVM-Translator that referenced this pull request Oct 26, 2023
SYCL part: intel/llvm#11458
intel/llvm#11597

Handle new properties and decorate prefetch's arg.
againull pushed a commit that referenced this pull request Oct 27, 2023
…11597)

The first part: #11458

Adjust the CompileTimePropertiesPass so it can convert new properties
into spirv decorations.
jsji pushed a commit that referenced this pull request Nov 2, 2023
SYCL part: #11458
#11597

Handle new properties and decorate prefetch's arg.

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@a76f24e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants