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] Ensure proper definition of spirv builtins for SYCL #1393

Merged
merged 7 commits into from
Apr 9, 2020

Conversation

Alexander-Johnston
Copy link
Contributor

Currently the spirv_vars header only ensures proper definition of the required spirv builtin vars for NVPTX. This patch ensures proper definitions are also available to other compilation targets by implementing the functions in the header in terms of the spirv builtin when not compiling for NVPTX.

Signed-off-by: Alexander Johnston alexander@codeplay.com

Alexander Johnston added 2 commits March 25, 2020 14:04
Ensures proper definition of SPIRV global and workgroup builtin variables
for both SYCL compilation with both NVPTX and SPIRV.

Signed-off-by: Alexander Johnston <alexander@codeplay.com>
Signed-off-by: Alexander Johnston <alexander@codeplay.com>
@Alexander-Johnston
Copy link
Contributor Author

This patch will allow us to avoid the changes to the spirv translator mentioned here #1166

Another commit will come soon with the changes removed from llvm-spirv

@Alexander-Johnston Alexander-Johnston changed the title [SYCL] Ensure proper definition of spirv builtins for SYCL [WIP][SYCL] Ensure proper definition of spirv builtins for SYCL Mar 25, 2020
Alexander Johnston added 2 commits March 26, 2020 09:23
Removes the downstream changes from llvm-spirv, instead opting to implement
the required spirv vars in the spirv_vars.hpp header.
Due to the removal of the llvm-spirv changes, the libdevice library now
requires access to spirv_vars.hpp to get all required spirv vars.

Signed-off-by: Alexander Johnston <alexander@codeplay.com>
@Alexander-Johnston Alexander-Johnston changed the title [WIP][SYCL] Ensure proper definition of spirv builtins for SYCL [SYCL] Ensure proper definition of spirv builtins for SYCL Mar 26, 2020
@@ -9,6 +9,10 @@
#ifndef __LIBDEVICE_DEVICE_H__
#define __LIBDEVICE_DEVICE_H__

// We need the following header provided by the sycl project to ensure
// definition of all spirv variables required by the wrapper libraries.
#include "spirv_vars.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a broken design.
libdevice should not include sycl library headers.
@vzakhari, recently moved this library out of the sycl project to make them independent (i.e. we should be able to one w/o the other).

Doesn't #1384 help to have all needed definitions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that #1384 removed all _spirv* declarations from libdevice/device_math.h, and I do not understand how it passed the testing. @bader, do you know?

I agree that devicelib must not depend on any headers from SYCL project. We are building devicelib in a fork without SYCL support, so I'd rather keep devicelib self-contained.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that #1384 removed all _spirv* declarations from libdevice/device_math.h, and I do not understand how it passed the testing. @bader, do you know?

I agree that devicelib must not depend on any headers from SYCL project. We are building devicelib in a fork without SYCL support, so I'd rather keep devicelib self-contained.

With this change SPIR-V built-ins are "clang" built-ins i.e. they are recognized by clang w/o forward declarations as they are declared by clang itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! I will have to use -fdeclare-spirv-builtins for non-SYCL builds of libdevice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks like a broken design.
libdevice should not include sycl library headers.
@vzakhari, recently moved this library out of the sycl project to make them independent (i.e. we should be able to one w/o the other).

Doesn't #1384 help to have all needed definitions?

This is required because the _devicelib_assert_fail calls in glibc_wrapper.cpp and msvc_wrapper.cpp both require the global and local invocation IDs.

  __devicelib_assert_fail(
      expr, file, line, func, __spirv_GlobalInvocationId_x(),
      __spirv_GlobalInvocationId_y(), __spirv_GlobalInvocationId_z(),
      __spirv_LocalInvocationId_x(), __spirv_LocalInvocationId_y(),
      __spirv_LocalInvocationId_z());

The upstream llvm-spirv translator doesn't implement these, so we implemented them in a somewhat broken way in the llvm-spirv translator, see #1166. This patch is triyng to avoid upstreaming the broken changes to the translator by implementing the invocation ID functions (among some others) for non NVPTX inside spirv_vars.hpp, which is why the devicelib has a requirement on the SYCL header.

If you'd prefer, an alternative to the header dependency would be to have another header in the devicelib which implements only the required invocation ID functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please make the implementation in a devicelib header. Not that I like it, but I want devicelib to be self-contained, and do not see a better way now.

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, @Alexander-Johnston! LGTM for libdevice.

Rather than have a dependency on SYCL headers in libdevice, implement the
required spirv builtins in the libdevice project.

Signed-off-by: Alexander Johnston <alexander@codeplay.com>
bader
bader previously approved these changes Mar 31, 2020
Accidentally removed the inclusion of spirv_vars.hpp in device.h in 41ea7ab.
Reinclude it here.

Signed-off-by: Alexander Johnston <alexander@codeplay.com>
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

LGTM, just one minor comment.

@@ -6,6 +6,10 @@
//
//===----------------------------------------------------------------------===//

// We need the following header to ensure the definition of all spirv variables
// required by the wrapper libraries.
#include "spirv_vars.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this include below the guard.

Signed-off-by: Alexander Johnston <alexander@codeplay.com>
@bader
Copy link
Contributor

bader commented Apr 7, 2020

@AlexeySachkov, @AlexeySotkin, @asavonic, and/or @vzakhari, your approval is required to merge this PR.

@bader
Copy link
Contributor

bader commented Apr 9, 2020

@AlexeySachkov, @AlexeySotkin, ping.

Copy link
Contributor

@AlexeySachkov AlexeySachkov left a comment

Choose a reason for hiding this comment

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

+1 for revert of #1166

@bader bader merged commit c7afc22 into intel:sycl Apr 9, 2020
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request Apr 15, 2020
…duler_docs

* origin/sycl:
  [SYCL][PI][CUDA] Implements get_native interoperability (intel#1332)
  [SYCL] Fix check-sycl test suite on systems w/o OpenCL (intel#1503)
  [SYCL][Doc] Update ExtendedAtomics documentation (intel#1487)
  [SYCL][CUDA] Expose context extended deleters on PI API (intel#1483)
  [SYCL][NFC] Remove a dropped environment variable from a test (intel#1506)
  [SYCL] Add opencl-aot to sycl-toolchain target (intel#1504)
  [SYCL] Allow to run deploy LIT tests from particular directory
  [SYCL][CUDA] Fix LIT testing with CUDA devices (intel#1300)
  [SYCL] Remove operator name keywords (intel#1501)
  [Driver][SYCL] Consider .lo files as static archives (intel#1500)
  [SYCL-PTX] Update the compiler design to describe the CUDA target (intel#1408)
  [SYCL] Fix library build on Windows (intel#1499)
  [SYCL][NFC] Refactor lit.cfg.py (intel#1452)
  [SYCL] Fixed sub-buffer memory allocation update (intel#1486)
  [SYCL] Ensure proper definition of spirv builtins for SYCL (intel#1393)
  [SYCL][CUDA] LIT XFAIL/UNSUPPORTED (intel#1303)
  [SYCL][Doc] Function-type kernel attribute extension (intel#1494)
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.

4 participants