TensorDeviceDefault.h
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
00011 #define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
00012 
00013 
00014 namespace Eigen {
00015 
00016 // Default device for the machine (typically a single cpu core)
00017 struct DefaultDevice {
00018   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
00019     return internal::aligned_malloc(num_bytes);
00020   }
00021   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void* buffer) const {
00022     internal::aligned_free(buffer);
00023   }
00024   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const {
00025     ::memcpy(dst, src, n);
00026   }
00027   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const {
00028     memcpy(dst, src, n);
00029   }
00030   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const {
00031     memcpy(dst, src, n);
00032   }
00033   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const {
00034     ::memset(buffer, c, n);
00035   }
00036 
00037   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const {
00038 #ifndef __CUDA_ARCH__
00039     // Running on the host CPU
00040     return 1;
00041 #else
00042     // Running on a CUDA device
00043     return 32;
00044 #endif
00045   }
00046 
00047   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const {
00048 #ifndef __CUDA_ARCH__
00049     // Running on the host CPU
00050     return l1CacheSize();
00051 #else
00052     // Running on a CUDA device, return the amount of shared memory available.
00053     return 48*1024;
00054 #endif
00055   }
00056 
00057   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const {
00058 #ifndef __CUDA_ARCH__
00059     // Running single threaded on the host CPU
00060     return l3CacheSize();
00061 #else
00062     // Running on a CUDA device
00063     return firstLevelCacheSize();
00064 #endif
00065   }
00066 
00067   EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const {
00068 #ifndef __CUDA_ARCH__
00069     // Running single threaded on the host CPU
00070     // Should return an enum that encodes the ISA supported by the CPU
00071     return 1;
00072 #else
00073     // Running on a CUDA device
00074     return __CUDA_ARCH__ / 100;
00075 #endif
00076   }
00077 };
00078 
00079 }  // namespace Eigen
00080 
00081 #endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
 All Classes Functions Variables Typedefs Enumerator