mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
There are two major changes (and a few minor ones which are not listed here...see PR discussion for details) 1. Eigen::half implementations for HIP and CUDA have been merged. This means that - `CUDA/Half.h` and `HIP/hcc/Half.h` got merged to a new file `GPU/Half.h` - `CUDA/PacketMathHalf.h` and `HIP/hcc/PacketMathHalf.h` got merged to a new file `GPU/PacketMathHalf.h` - `CUDA/TypeCasting.h` and `HIP/hcc/TypeCasting.h` got merged to a new file `GPU/TypeCasting.h` After this change the `HIP/hcc` directory only contains one file `math_constants.h`. That will go away too once that file becomes a part of the HIP install. 2. new macros EIGEN_GPUCC, EIGEN_GPU_COMPILE_PHASE and EIGEN_HAS_GPU_FP16 have been added and the code has been updated to use them where appropriate. - `EIGEN_GPUCC` is the same as `(EIGEN_CUDACC || EIGEN_HIPCC)` - `EIGEN_GPU_DEVICE_COMPILE` is the same as `(EIGEN_CUDA_ARCH || EIGEN_HIP_DEVICE_COMPILE)` - `EIGEN_HAS_GPU_FP16` is the same as `(EIGEN_HAS_CUDA_FP16 or EIGEN_HAS_HIP_FP16)`
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
// This file is part of Eigen, a lightweight C++ template library
|
|
// for linear algebra.
|
|
//
|
|
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#ifndef EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
|
|
#define EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
|
|
|
|
|
|
namespace Eigen {
|
|
|
|
// Default device for the machine (typically a single cpu core)
|
|
struct DefaultDevice {
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const {
|
|
return internal::aligned_malloc(num_bytes);
|
|
}
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void deallocate(void* buffer) const {
|
|
internal::aligned_free(buffer);
|
|
}
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpy(void* dst, const void* src, size_t n) const {
|
|
::memcpy(dst, src, n);
|
|
}
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyHostToDevice(void* dst, const void* src, size_t n) const {
|
|
memcpy(dst, src, n);
|
|
}
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memcpyDeviceToHost(void* dst, const void* src, size_t n) const {
|
|
memcpy(dst, src, n);
|
|
}
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void memset(void* buffer, int c, size_t n) const {
|
|
::memset(buffer, c, n);
|
|
}
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t numThreads() const {
|
|
#if !defined(EIGEN_GPU_COMPILE_PHASE)
|
|
// Running on the host CPU
|
|
return 1;
|
|
#elif defined(EIGEN_HIP_DEVICE_COMPILE)
|
|
// Running on a HIP device
|
|
return 64;
|
|
#else
|
|
// Running on a CUDA device
|
|
return 32;
|
|
#endif
|
|
}
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t firstLevelCacheSize() const {
|
|
#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(__SYCL_DEVICE_ONLY__)
|
|
// Running on the host CPU
|
|
return l1CacheSize();
|
|
#elif defined(EIGEN_HIP_DEVICE_COMPILE)
|
|
// Running on a HIP device
|
|
return 48*1024; // FIXME : update this number for HIP
|
|
#else
|
|
// Running on a CUDA device, return the amount of shared memory available.
|
|
return 48*1024;
|
|
#endif
|
|
}
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE size_t lastLevelCacheSize() const {
|
|
#if !defined(EIGEN_GPU_COMPILE_PHASE) && !defined(__SYCL_DEVICE_ONLY__)
|
|
// Running single threaded on the host CPU
|
|
return l3CacheSize();
|
|
#elif defined(EIGEN_HIP_DEVICE_COMPILE)
|
|
// Running on a HIP device
|
|
return firstLevelCacheSize(); // FIXME : update this number for HIP
|
|
#else
|
|
// Running on a CUDA device
|
|
return firstLevelCacheSize();
|
|
#endif
|
|
}
|
|
|
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE int majorDeviceVersion() const {
|
|
#if !defined(EIGEN_GPU_COMPILE_PHASE)
|
|
// Running single threaded on the host CPU
|
|
// Should return an enum that encodes the ISA supported by the CPU
|
|
return 1;
|
|
#elif defined(EIGEN_HIP_DEVICE_COMPILE)
|
|
// Running on a HIP device
|
|
// return 1 as major for HIP
|
|
return 1;
|
|
#else
|
|
// Running on a CUDA device
|
|
return EIGEN_CUDA_ARCH / 100;
|
|
#endif
|
|
}
|
|
};
|
|
|
|
} // namespace Eigen
|
|
|
|
#endif // EIGEN_CXX11_TENSOR_TENSOR_DEVICE_DEFAULT_H
|