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

[ESIMD] Add infra to support half, bfloat, etc, support sycl::half. #5123

Merged
merged 9 commits into from Dec 28, 2021

Conversation

kbobrovs
Copy link
Contributor

@kbobrovs kbobrovs commented Dec 11, 2021

  • implement infrastructure for non-standard element type support
    to support a new type, the following must be implemented:
    • element type traits for the new type
    • scalar and vector conversions to/from selected std C++ type
    • std operations (or default with promotion to std C++ type can be used)
  • esimd::simd<sycl::half, N> can now be used on host and device
    • most of the operations, except extended math are supported for half

Complementary E2E tests update - intel/llvm-test-suite#640

@kbobrovs kbobrovs changed the title [WIP][ESIMD] Support sycl::half in device code. [ESIMD] Add infra for half, bfloat, etc. support, support sycl::half. Dec 20, 2021
@kbobrovs kbobrovs changed the title [ESIMD] Add infra for half, bfloat, etc. support, support sycl::half. [ESIMD] Add infra to support half, bfloat, etc, support sycl::half. Dec 20, 2021
@kbobrovs kbobrovs marked this pull request as ready for review December 23, 2021 03:59
Copy link
Contributor

@sndmitriev sndmitriev left a comment

Choose a reason for hiding this comment

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

Is there any document which describes the concept of supporting non-standard types which you have implemented here? If not you should probably create one. That will greatly simplify things for maintainers of this code in future:)

Comment on lines 17 to 22
namespace sycl {
namespace ext {
namespace intel {
namespace experimental {
namespace esimd {
namespace detail {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these namespaces can be collapsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 329 to 332
// template <typename To, typename From, int N>
// vector_type_t<To, N> convert(vector_type_t<From, N> Val) {
// return convert<vector_type_t<To, N>>(Val);
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this commented code can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 24 to 29
namespace sycl {
namespace ext {
namespace intel {
namespace experimental {
namespace esimd {
namespace detail {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these namespaces can be collapsed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

namespace esimd {
namespace detail {

enum class BinOp {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you forgot to add corresponding infra for unary ops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, will add

Comment on lines 501 to 505
#ifdef __SYCL_DEVICE_ONLY__
using half = _Float16;
#else
using half = uint16_t;
#endif // __SYCL_DEVICE_ONLY__
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like these definitions are not used and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right

ESIMD_INLINE DstWrapperTy convert_scalar(SrcWrapperTy Val) {
if constexpr (std::is_same_v<SrcWrapperTy, DstWrapperTy>) {
return Val;
} else if constexpr (!detail::is_wrapper_elem_type_v<SrcWrapperTy> &&
Copy link
Contributor

Choose a reason for hiding this comment

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

detail:: can be removed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 174 to 175
} else if constexpr (!detail::is_wrapper_elem_type_v<SrcWrapperTy> &&
!detail::is_wrapper_elem_type_v<DstWrapperTy>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

detail:: can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok


template <class T> using __st = element_storage_t<T>;

#if 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this code under #if 0 is not needed anymore and thus need to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, thanks for the catch

template <class T, class SFINAE> struct element_type_traits {
// The raw element type of the underlying clang vector used as a
// storage.
using StorageT = invalid_storage_element_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably rename StorageT to shorter RawT as you have used word 'raw' in many other places to describe storage type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@kbobrovs
Copy link
Contributor Author

Is there any document which describes the concept of supporting non-standard types which you have implemented here? If not you should probably create one. That will greatly simplify things for maintainers of this code in future:)

ok, will do

@kbobrovs
Copy link
Contributor Author

@sndmitriev, all comments are fixed - please review

@kbobrovs
Copy link
Contributor Author

@AlexeySachkov, please review sycl/include/CL/sycl/half_type.hpp

// Meta-functions to compute compile-time element type of a simd_view resulting
// from format operations.
//===----------------------------------------------------------------------===//

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Content of this file was moved from types.hpp, mostly verbatim. The changes are noted below.

template <typename, int> class SimdT>
struct compute_format_type<SimdT<Ty, N>, EltTy>
: compute_format_type_impl<Ty, N, EltTy> {};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

specialization for <simd_obj_impl<Ty, N, SimdT>, EltTy> was removed - not supposed to be used as argument

template <typename, int> class SimdT>
struct compute_format_type_2d<SimdT<Ty, N>, EltTy, Height, Width>
: compute_format_type_2d_impl<Ty, N, EltTy, Height, Width> {};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

specialization for <simd_obj_impl<Ty, N, SimdT>, EltTy> was removed - not supposed to be used as argument

using simd_mask_storage_t = vector_type_t<simd_mask_elem_type, N>;
// @{
// Checks if given type T derives from simd_obj_impl or is equal to it.
template <typename T>
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 around the file due to factoring out some parts of types.hpp


// must match simd_mask<N>::element_type
template <int N>
using simd_mask_storage_t = vector_type_t<simd_mask_elem_type, N>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No functional changes in the code above (moved here from different part and renamed template parameter)

struct computation_type<
T1, T2, std::enable_if_t<is_vectorizable_v<T1> && is_vectorizable_v<T2>>> {
using type = decltype(std::declval<T1>() + std::declval<T2>());
// Determine element type of simd_obj_impl's Derived type w/o having to have
Copy link
Contributor Author

Choose a reason for hiding this comment

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

314-331 is new code

@kbobrovs
Copy link
Contributor Author

Unrelated failures from SYCL / Default Linux / OCL x64 Test Suite (pull_request):
SYCL :: XPTI/buffer/sub_buffer.cpp

terminate called after throwing an instance of 'cl::sycl::invalid_object_error'
what(): Specified offset of the sub-buffer being constructed is not a multiple of the memory base address alignment -30 (CL_INVALID_VALUE)

Unrelated failures from SYCL / Default Linux / HIP AMD GPU Test Suite (pull_request):
SYCL :: Printf/char.cpp
SYCL :: Printf/float.cpp
SYCL :: Printf/int.cpp
SYCL :: Printf/long.cpp
SYCL :: Printf/mixed-address-space.cpp
SYCL :: Printf/percent-symbol.cpp

all like this:

/__w/llvm/llvm/toolchain/bin/../include/sycl/ext/oneapi/experimental/builtins.hpp:71:36: error: SYCL kernel cannot call a variadic function
return ::printf(__format, args...);

sndmitriev
sndmitriev previously approved these changes Dec 28, 2021
Copy link
Contributor

@sndmitriev sndmitriev left a comment

Choose a reason for hiding this comment

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

Looks good.

@bader
Copy link
Contributor

bader commented Dec 28, 2021

Unrelated failures from SYCL / Default Linux / OCL x64 Test Suite (pull_request): SYCL :: XPTI/buffer/sub_buffer.cpp

terminate called after throwing an instance of 'cl::sycl::invalid_object_error'
what(): Specified offset of the sub-buffer being constructed is not a multiple of the memory base address alignment -30 (CL_INVALID_VALUE)

Unrelated failures from SYCL / Default Linux / HIP AMD GPU Test Suite (pull_request): SYCL :: Printf/char.cpp SYCL :: Printf/float.cpp SYCL :: Printf/int.cpp SYCL :: Printf/long.cpp SYCL :: Printf/mixed-address-space.cpp SYCL :: Printf/percent-symbol.cpp

all like this:

/__w/llvm/llvm/toolchain/bin/../include/sycl/ext/oneapi/experimental/builtins.hpp:71:36: error: SYCL kernel cannot call a variadic function
return ::printf(__format, args...);

printf issues are fixed by intel/llvm-test-suite#685

I think SYCL / Default Linux / OCL x64 Test Suite (pull_request): SYCL :: XPTI/buffer/sub_buffer.cpp fails because your branch doesn't have 8f9d0d2. Please, merge sycl branch to your private branch.
@vladimirlaz, am I right?

@kbobrovs
Copy link
Contributor Author

printf issues are fixed by intel/llvm-test-suite#685

what should I do then - ignore the failures?

I think SYCL / Default Linux / OCL x64 Test Suite (pull_request): SYCL :: XPTI/buffer/sub_buffer.cpp fails because your branch doesn't have 8f9d0d2. Please, merge sycl branch to your private branch.

ok, thanks

- implement infrastructure for non-standard element type support
  to support a new type, the following must be implemented:
  * element type traits for the new type
  * scalar and vector conversions to/from selected std C++ type
  * std operations (or default with promotion to std C++ type can be used)
- esimd::simd<sycl::half, N> can now be used on host and device
  * most of the operations, except extended math are supported for half

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
- fix vector conversion not to use CommonT - should result in fewer
  conversions and more in accordance to C++
- computation_type_t will now return sycl::half instead of _Float16
- Fix bug in simd(const SimdT &RHS) constructor
- atomics are checked based on user type, not raw
- EnclosingCppT for sycl::half is now _Float16 in device compiler
- Few review comments addressed.

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
- Add description of the non-std type support infra
- Support unary ops in the infra
- rename storage_type to raw_type
- remove user_element_type - use element_type and raw_element_type instead of
  element_type and user_element_type

Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
@bader
Copy link
Contributor

bader commented Dec 28, 2021

what should I do then - ignore the failures?

When you merge with the sycl branch, tests will be ran again and these tests should be skipped.

AlexeySachkov
AlexeySachkov previously approved these changes Dec 28, 2021
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.

half_type.hpp changes LGTM

@kbobrovs
Copy link
Contributor Author

@dm-vodopyanov, @s-kanaev, @againull, @v-klochkov, @smaslov-intel - could you folks please review the only non-ESIMD change in the patch - sycl/include/CL/sycl/half_type.hpp - on behalf of llvm-reviewers-runtime?

@kbobrovs
Copy link
Contributor Author

had to rebase and force-push to fix test failures (no code changes)

@againull againull merged commit f34ba2c into intel:sycl Dec 28, 2021
@kbobrovs kbobrovs deleted the half branch December 28, 2021 20:44
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.

None yet

5 participants