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 
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 int majorDeviceVersion() const {
48 #ifndef __CUDA_ARCH__
49  // Running single threaded on the host CPU
50  // Should return an enum that encodes the ISA supported by the CPU
51  return 1;
52 #else
53  // Running on a CUDA device
54  return __CUDA_ARCH__ / 100;
55 #endif
56  }
57 };
58 
59 } // namespace Eigen
60 
61 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13