-
Notifications
You must be signed in to change notification settings - Fork 751
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
bader
merged 7 commits into
intel:sycl
from
codeplaysoftware:Alex/spirv-builtin-definitions
Apr 9, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f34bcd
[SYCL] Ensure proper definition of spirv builtins for SYCL
377bb1b
[SYCL] Format spirv_vars.hpp
f124161
Merge remote-tracking branch 'intel-public/sycl' into Alex/spirv-buil…
91b92ed
[SYCL] Remove downstream changes from llvm-spirv
41ea7ab
[SYCL] Implement required builtins for libdevice
253d28a
[SYCL] Reinclude spirv_vars in libdevice
09930df
Move include within header definition guard
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 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 |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
#ifndef __LIBDEVICE_DEVICE_H__ | ||
#define __LIBDEVICE_DEVICE_H__ | ||
|
||
// We need the following header to ensure the definition of all spirv variables | ||
// required by the wrapper libraries. | ||
#include "spirv_vars.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this include below the guard. |
||
|
||
#ifdef __cplusplus | ||
#define EXTERN_C extern "C" | ||
#else // __cplusplus | ||
|
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,102 @@ | ||
//==---------- spirv_vars.hpp --- SPIRV variables -------------------------==// | ||
// | ||
// 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 <cstddef> | ||
#include <cstdint> | ||
|
||
#ifdef __SYCL_DEVICE_ONLY__ | ||
|
||
#ifdef __SYCL_NVPTX__ | ||
|
||
SYCL_EXTERNAL size_t __spirv_GlobalInvocationId_x(); | ||
SYCL_EXTERNAL size_t __spirv_GlobalInvocationId_y(); | ||
SYCL_EXTERNAL size_t __spirv_GlobalInvocationId_z(); | ||
|
||
SYCL_EXTERNAL size_t __spirv_LocalInvocationId_x(); | ||
SYCL_EXTERNAL size_t __spirv_LocalInvocationId_y(); | ||
SYCL_EXTERNAL size_t __spirv_LocalInvocationId_z(); | ||
|
||
#else // __SYCL_NVPTX__ | ||
|
||
typedef size_t size_t_vec __attribute__((ext_vector_type(3))); | ||
extern "C" const __attribute__((opencl_constant)) | ||
size_t_vec __spirv_BuiltInGlobalInvocationId; | ||
extern "C" const __attribute__((opencl_constant)) | ||
size_t_vec __spirv_BuiltInLocalInvocationId; | ||
|
||
SYCL_EXTERNAL inline size_t __spirv_GlobalInvocationId_x() { | ||
return __spirv_BuiltInGlobalInvocationId.x; | ||
} | ||
SYCL_EXTERNAL inline size_t __spirv_GlobalInvocationId_y() { | ||
return __spirv_BuiltInGlobalInvocationId.y; | ||
} | ||
SYCL_EXTERNAL inline size_t __spirv_GlobalInvocationId_z() { | ||
return __spirv_BuiltInGlobalInvocationId.z; | ||
} | ||
|
||
SYCL_EXTERNAL inline size_t __spirv_LocalInvocationId_x() { | ||
return __spirv_BuiltInLocalInvocationId.x; | ||
} | ||
SYCL_EXTERNAL inline size_t __spirv_LocalInvocationId_y() { | ||
return __spirv_BuiltInLocalInvocationId.y; | ||
} | ||
SYCL_EXTERNAL inline size_t __spirv_LocalInvocationId_z() { | ||
return __spirv_BuiltInLocalInvocationId.z; | ||
} | ||
|
||
#endif // __SYCL_NVPTX__ | ||
|
||
#define DEFINE_FUNC_ID_TO_XYZ_CONVERTER(POSTFIX) \ | ||
template <int ID> static inline size_t get##POSTFIX(); \ | ||
template <> size_t get##POSTFIX<0>() { return __spirv_##POSTFIX##_x(); } \ | ||
template <> size_t get##POSTFIX<1>() { return __spirv_##POSTFIX##_y(); } \ | ||
template <> size_t get##POSTFIX<2>() { return __spirv_##POSTFIX##_z(); } | ||
|
||
namespace __spirv { | ||
|
||
DEFINE_FUNC_ID_TO_XYZ_CONVERTER(GlobalInvocationId); | ||
DEFINE_FUNC_ID_TO_XYZ_CONVERTER(LocalInvocationId); | ||
|
||
} // namespace __spirv | ||
|
||
#undef DEFINE_FUNC_ID_TO_XYZ_CONVERTER | ||
|
||
#define DEFINE_INIT_SIZES(POSTFIX) \ | ||
\ | ||
template <int Dim, class DstT> struct InitSizesST##POSTFIX; \ | ||
\ | ||
template <class DstT> struct InitSizesST##POSTFIX<1, DstT> { \ | ||
static DstT initSize() { return {get##POSTFIX<0>()}; } \ | ||
}; \ | ||
\ | ||
template <class DstT> struct InitSizesST##POSTFIX<2, DstT> { \ | ||
static DstT initSize() { return {get##POSTFIX<1>(), get##POSTFIX<0>()}; } \ | ||
}; \ | ||
\ | ||
template <class DstT> struct InitSizesST##POSTFIX<3, DstT> { \ | ||
static DstT initSize() { \ | ||
return {get##POSTFIX<2>(), get##POSTFIX<1>(), get##POSTFIX<0>()}; \ | ||
} \ | ||
}; \ | ||
\ | ||
template <int Dims, class DstT> static DstT init##POSTFIX() { \ | ||
return InitSizesST##POSTFIX<Dims, DstT>::initSize(); \ | ||
} | ||
|
||
namespace __spirv { | ||
|
||
DEFINE_INIT_SIZES(GlobalInvocationId) | ||
DEFINE_INIT_SIZES(LocalInvocationId) | ||
|
||
} // namespace __spirv | ||
|
||
#undef DEFINE_INIT_SIZES | ||
|
||
#endif // __SYCL_DEVICE_ONLY__ |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
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.
There was a problem hiding this comment.
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 includesycl
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
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.