alpaka
Abstraction Library for Parallel Kernel Acceleration
IntrinsicGenericSycl.hpp
Go to the documentation of this file.
1 /* Copyright 2022 Jan Stephan
2  * SPDX-License-Identifier: MPL-2.0
3  */
4 
5 #pragma once
6 
9 
10 #include <cstdint>
11 
12 #ifdef ALPAKA_ACC_SYCL_ENABLED
13 
14 # include <sycl/sycl.hpp>
15 
16 namespace alpaka
17 {
18  //! The SYCL intrinsic.
19  class IntrinsicGenericSycl : public concepts::Implements<ConceptIntrinsic, IntrinsicGenericSycl>
20  {
21  };
22 } // namespace alpaka
23 
24 namespace alpaka::trait
25 {
26  template<>
27  struct Popcount<IntrinsicGenericSycl>
28  {
29  static auto popcount(IntrinsicGenericSycl const&, std::uint32_t value) -> std::int32_t
30  {
31  return static_cast<std::int32_t>(sycl::popcount(value));
32  }
33 
34  static auto popcount(IntrinsicGenericSycl const&, std::uint64_t value) -> std::int32_t
35  {
36  return static_cast<std::int32_t>(sycl::popcount(value));
37  }
38  };
39 
40  template<>
41  struct Ffs<IntrinsicGenericSycl>
42  {
43  static auto ffs(IntrinsicGenericSycl const&, std::int32_t value) -> std::int32_t
44  {
45  // There is no FFS operation in SYCL but we can emulate it using popcount.
46  return (value == 0) ? 0 : sycl::popcount(value ^ ~(-value));
47  }
48 
49  static auto ffs(IntrinsicGenericSycl const&, std::int64_t value) -> std::int32_t
50  {
51  // There is no FFS operation in SYCL but we can emulate it using popcount.
52  return (value == 0l) ? 0 : static_cast<std::int32_t>(sycl::popcount(value ^ ~(-value)));
53  }
54  };
55 } // namespace alpaka::trait
56 
57 #endif
The accelerator traits.
The alpaka accelerator library.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto ffs(TIntrinsic const &intrinsic, std::int32_t value) -> std::int32_t
Returns the 1-based position of the least significant bit set to 1 in the given 32-bit value....
Definition: Traits.hpp:65
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto popcount(TIntrinsic const &intrinsic, std::uint32_t value) -> std::int32_t
Returns the number of 1 bits in the given 32-bit value.
Definition: Traits.hpp:38