DPC++ Runtime
Runtime libraries for oneAPI DPC++
type_format.hpp
Go to the documentation of this file.
1 //==-------------- types.hpp - DPC++ Explicit SIMD API ---------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // Meta-functions to compute compile-time element type of a simd_view resulting
9 // from format operations.
10 //===----------------------------------------------------------------------===//
11 
12 #pragma once
13 
15 
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace ext::intel::esimd::detail {
21 
22 template <typename BaseTy, typename EltTy> struct compute_format_type;
23 
24 template <typename Ty, int N, typename EltTy> struct compute_format_type_impl {
25  static constexpr int Size = sizeof(Ty) * N / sizeof(EltTy);
26  static constexpr int Stride = 1;
27  using type = region1d_t<EltTy, Size, Stride>;
28 };
29 
30 template <typename Ty, int N, typename EltTy,
31  template <typename, int> class SimdT>
32 struct compute_format_type<SimdT<Ty, N>, EltTy>
33  : compute_format_type_impl<Ty, N, EltTy> {};
34 
35 template <typename BaseTy, typename RegionTy, typename EltTy>
36 struct compute_format_type<simd_view<BaseTy, RegionTy>, EltTy> {
37  using ShapeTy = typename shape_type<RegionTy>::type;
38  static constexpr int Size = ShapeTy::Size_in_bytes / sizeof(EltTy);
39  static constexpr int Stride = 1;
40  using type = region1d_t<EltTy, Size, Stride>;
41 };
42 
43 template <typename Ty, typename EltTy>
44 using compute_format_type_t = typename compute_format_type<Ty, EltTy>::type;
45 
46 // Compute the simd_view type of a 2D format operation.
47 template <typename BaseTy, typename EltTy, int Height, int Width>
48 struct compute_format_type_2d;
49 
50 template <typename Ty, int N, typename EltTy, int Height, int Width>
51 struct compute_format_type_2d_impl {
52  static constexpr int Prod = sizeof(Ty) * N / sizeof(EltTy);
53  static_assert(Prod == Width * Height, "size mismatch");
54 
55  static constexpr int SizeX = Width;
56  static constexpr int StrideX = 1;
57  static constexpr int SizeY = Height;
58  static constexpr int StrideY = 1;
59  using type = region2d_t<EltTy, SizeY, StrideY, SizeX, StrideX>;
60 };
61 
62 template <typename Ty, int N, typename EltTy, int Height, int Width,
63  template <typename, int> class SimdT>
64 struct compute_format_type_2d<SimdT<Ty, N>, EltTy, Height, Width>
65  : compute_format_type_2d_impl<Ty, N, EltTy, Height, Width> {};
66 
67 template <typename BaseTy, typename RegionTy, typename EltTy, int Height,
68  int Width>
69 struct compute_format_type_2d<simd_view<BaseTy, RegionTy>, EltTy, Height,
70  Width> {
71  using ShapeTy = typename shape_type<RegionTy>::type;
72  static constexpr int Prod = ShapeTy::Size_in_bytes / sizeof(EltTy);
73  static_assert(Prod == Width * Height, "size mismatch");
74 
75  static constexpr int SizeX = Width;
76  static constexpr int StrideX = 1;
77  static constexpr int SizeY = Height;
78  static constexpr int StrideY = 1;
79  using type = region2d_t<EltTy, SizeY, StrideY, SizeX, StrideX>;
80 };
81 
82 template <typename Ty, typename EltTy, int Height, int Width>
83 using compute_format_type_2d_t =
84  typename compute_format_type_2d<Ty, EltTy, Height, Width>::type;
85 
86 } // namespace ext::intel::esimd::detail
87 } // namespace _V1
88 } // namespace sycl
89 
Definition: access.hpp:18