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 
14 namespace Eigen {
15 
16 // Default device for the machine (typically a single cpu core)
17 struct DefaultDevice {
18  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
19  return internal::aligned_malloc(num_bytes);
20  }
21  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void* buffer) const {
22  internal::aligned_free(buffer);
23  }
24  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const {
25  ::memcpy(dst, src, n);
26  }
27  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const {
28  memcpy(dst, src, n);
29  }
30  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const {
31  memcpy(dst, src, n);
32  }
33  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const {
34  ::memset(buffer, c, n);
35  }
36 
37  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const {
38 #ifndef __CUDA_ARCH__
39  // Running on the host CPU
40  return 1;
41 #else
42  // Running on a CUDA device
43  return 32;
44 #endif
45  }
46 
47  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const {
48 #ifndef __CUDA_ARCH__
49  // Running on the host CPU
50  return l1CacheSize();
51 #else
52  // Running on a CUDA device, return the amount of shared memory available.
53  return 48*1024;
54 #endif
55  }
56 
57  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const {
58 #ifndef __CUDA_ARCH__
59  // Running single threaded on the host CPU
60  return l3CacheSize();
61 #else
62  // Running on a CUDA device
63  return firstLevelCacheSize();
64 #endif
65  }
66 
67  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const {
68 #ifndef __CUDA_ARCH__
69  // Running single threaded on the host CPU
70  // Should return an enum that encodes the ISA supported by the CPU
71  return 1;
72 #else
73  // Running on a CUDA device
74  return __CUDA_ARCH__ / 100;
75 #endif
76  }
77 };
78 
79 } // namespace Eigen
80 
81 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void *buffer) const
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
EIGEN_DEVICE_FUNC void * aligned_malloc(std::size_t size)
Definition: Memory.h:153
Definition: LDLT.h:16
std::ptrdiff_t l3CacheSize()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const
EIGEN_DEVICE_FUNC void aligned_free(void *ptr)
Definition: Memory.h:174
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void *buffer, int c, size_t n) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void *dst, const void *src, size_t n) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void *dst, const void *src, size_t n) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void *dst, const void *src, size_t n) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void * allocate(size_t num_bytes) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const
std::ptrdiff_t l1CacheSize()


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:09:16