Eigen-unsupported  5.0.1-dev+284dcc12
 
Loading...
Searching...
No Matches
TensorDeviceDefault.h
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
16namespace Eigen {
17
18// Default device for the machine (typically a single cpu core)
19struct DefaultDevice {
20 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
21 return internal::aligned_malloc(num_bytes);
22 }
23 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void* buffer) const { internal::aligned_free(buffer); }
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>
48 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Type get(Type data) const {
49 return data;
50 }
51
52 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const {
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
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const {
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
78 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const {
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
91 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void synchronize() const {
92 // Nothing. Default device operations are synchronous.
93 }
94
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const {
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
Namespace containing all symbols from the Eigen library.
std::ptrdiff_t l1CacheSize()
std::ptrdiff_t l3CacheSize()