TensorDeviceDefault.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_DEVICE_DEFAULT_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 // Default device for the machine (typically a single cpu core)
19 struct DefaultDevice {
20  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
21  return internal::aligned_malloc(num_bytes);
22  }
24  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate_temp(size_t num_bytes) const { return allocate(num_bytes); }
25  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate_temp(void* buffer) const { deallocate(buffer); }
26  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const {
27  ::memcpy(dst, src, n);
28  }
29  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const {
30  memcpy(dst, src, n);
31  }
32  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const {
33  memcpy(dst, src, n);
34  }
35  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const { ::memset(buffer, c, n); }
36  template <typename T>
37  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void fill(T* begin, T* end, const T& value) const {
38 #ifdef EIGEN_GPU_COMPILE_PHASE
39  // std::fill is not a device function, so resort to simple loop.
40  for (T* it = begin; it != end; ++it) {
41  *it = value;
42  }
43 #else
44  std::fill(begin, end, value);
45 #endif
46  }
47  template <typename Type>
49  return data;
50  }
51 
53 #if !defined(EIGEN_GPU_COMPILE_PHASE)
54  // Running on the host CPU
55  return 1;
56 #elif defined(EIGEN_HIP_DEVICE_COMPILE)
57  // Running on a HIP device
58  return 64;
59 #else
60  // Running on a CUDA device
61  return 32;
62 #endif
63  }
64 
66 #if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(SYCL_DEVICE_ONLY)
67  // Running on the host CPU
68  return l1CacheSize();
69 #elif defined(EIGEN_HIP_DEVICE_COMPILE)
70  // Running on a HIP device
71  return 48 * 1024; // FIXME : update this number for HIP
72 #else
73  // Running on a CUDA device, return the amount of shared memory available.
74  return 48 * 1024;
75 #endif
76  }
77 
79 #if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(SYCL_DEVICE_ONLY)
80  // Running single threaded on the host CPU
81  return l3CacheSize();
82 #elif defined(EIGEN_HIP_DEVICE_COMPILE)
83  // Running on a HIP device
84  return firstLevelCacheSize(); // FIXME : update this number for HIP
85 #else
86  // Running on a CUDA device
87  return firstLevelCacheSize();
88 #endif
89  }
90 
92  // Nothing. Default device operations are synchronous.
93  }
94 
96 #if !defined(EIGEN_GPU_COMPILE_PHASE)
97  // Running single threaded on the host CPU
98  // Should return an enum that encodes the ISA supported by the CPU
99  return 1;
100 #elif defined(EIGEN_HIP_DEVICE_COMPILE)
101  // Running on a HIP device
102  // return 1 as major for HIP
103  return 1;
104 #else
105  // Running on a CUDA device
106  return EIGEN_CUDA_ARCH / 100;
107 #endif
108  }
109 };
110 
111 } // namespace Eigen
112 
113 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
int data[]
Definition: Map_placement_new.cpp:1
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
EIGEN_DEVICE_FUNC void * aligned_malloc(std::size_t size)
Definition: Memory.h:199
EIGEN_DEVICE_FUNC void aligned_free(void *ptr)
Definition: Memory.h:224
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
std::ptrdiff_t l1CacheSize()
Definition: products/GeneralBlockPanelKernel.h:3119
std::ptrdiff_t l3CacheSize()
Definition: products/GeneralBlockPanelKernel.h:3135
int c
Definition: calibrate.py:100
Type
Type of JSON value.
Definition: rapidjson.h:513
Definition: TensorDeviceDefault.h:19
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void fill(T *begin, T *end, const T &value) const
Definition: TensorDeviceDefault.h:37
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void *buffer, int c, size_t n) const
Definition: TensorDeviceDefault.h:35
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const
Definition: TensorDeviceDefault.h:48
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void *buffer) const
Definition: TensorDeviceDefault.h:23
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void *dst, const void *src, size_t n) const
Definition: TensorDeviceDefault.h:32
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void * allocate(size_t num_bytes) const
Definition: TensorDeviceDefault.h:20
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void *dst, const void *src, size_t n) const
Definition: TensorDeviceDefault.h:26
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const
Definition: TensorDeviceDefault.h:95
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const
Definition: TensorDeviceDefault.h:65
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const
Definition: TensorDeviceDefault.h:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate_temp(void *buffer) const
Definition: TensorDeviceDefault.h:25
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void *dst, const void *src, size_t n) const
Definition: TensorDeviceDefault.h:29
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const
Definition: TensorDeviceDefault.h:78
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void * allocate_temp(size_t num_bytes) const
Definition: TensorDeviceDefault.h:24
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void synchronize() const
Definition: TensorDeviceDefault.h:91