TensorContractionBlocking.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H
12 
13 
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 namespace internal {
18 
19 enum {
21  ShardByCol = 1
22 };
23 
24 
25 // Default Blocking Strategy
26 template<typename ResScalar, typename LhsScalar, typename RhsScalar, typename StorageIndex, int ShardingType = ShardByCol>
27 class TensorContractionBlocking {
28  public:
29 
30  /*
31  adding EIGEN_DEVICE_FUNC unconditionally to 'TensorContractionBlocking' constructor in `TensorContractionBlocking.h`
32  requires adding EIGEN_DEVICE_FUNC to `computeProductBlockingSizes` in `GeneralBlockPanelKernel.h`
33  which in turn, requires adding EIGEN_DEVICE_FUNC to `evaluateProductBlockingSizesHeuristic` in `GeneralBlockPanelKernel.h`
34  which in turn, requires adding EIGEN_DEVICE_FUNC to `manage_caching_sizes` in `GeneralBlockPanelKernel.h`
35  (else HIPCC will error out)
36 
37  However adding EIGEN_DEVICE_FUNC to `manage_caching_sizes` in `GeneralBlockPanelKernel.h`
38  results in NVCC erroring out with the following error
39 
40  ../Eigen/src/Core/products/GeneralBlockPanelKernel.h(57): error #2901:
41  dynamic initialization is not supported for function-scope static variables within a __device__/__global__ function
42  */
43 
44  #if !defined(EIGEN_HIPCC)
46  #endif
47  TensorContractionBlocking(StorageIndex k, StorageIndex m, StorageIndex n, StorageIndex num_threads = 1) :
48  kc_(k), mc_(m), nc_(n)
49  {
50  if (ShardingType == ShardByCol) {
51  computeProductBlockingSizes<LhsScalar, RhsScalar, 1>(kc_, mc_, nc_, num_threads);
52  }
53  else {
54  computeProductBlockingSizes<LhsScalar, RhsScalar, 1>(kc_, nc_, mc_, num_threads);
55  }
56 
57  const int rhs_packet_size = internal::packet_traits<RhsScalar>::size;
58  kc_ = (rhs_packet_size <= 8 || kc_ <= rhs_packet_size) ?
59  kc_ : (kc_ / rhs_packet_size) * rhs_packet_size;
60  }
61 
62  EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex kc() const { return kc_; }
63  EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex mc() const { return mc_; }
64  EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE StorageIndex nc() const { return nc_; }
65 
66  private:
67  StorageIndex kc_;
68  StorageIndex mc_;
69  StorageIndex nc_;
70 };
71 
72 } // end namespace internal
73 } // end namespace Eigen
74 
75 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONTRACTION_BLOCKING_H
Matrix3f m
int n
#define EIGEN_ALWAYS_INLINE
#define EIGEN_DEVICE_FUNC
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend