mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Merged eigen/eigen into default
This commit is contained in:
@@ -61,7 +61,7 @@ template<typename _Scalar> class AlignedVector3
|
||||
Scalar* data() { return m_coeffs.data(); }
|
||||
const Scalar* data() const { return m_coeffs.data(); }
|
||||
Index innerStride() const { return 1; }
|
||||
Index outerStride() const { return m_coeffs.outerStride(); }
|
||||
Index outerStride() const { return 3; }
|
||||
|
||||
inline const Scalar& coeff(Index row, Index col) const
|
||||
{ return m_coeffs.coeff(row, col); }
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include <cstring>
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
|
||||
@@ -124,7 +124,8 @@ template <typename T> struct SumReducer
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return saccum + predux(vaccum);
|
||||
internal::scalar_sum_op<T> sum_op;
|
||||
return sum_op(saccum, predux(vaccum));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,7 +174,8 @@ template <typename T> struct MeanReducer
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return (saccum + predux(vaccum)) / (scalarCount_ + packetCount_ * unpacket_traits<Packet>::size);
|
||||
internal::scalar_sum_op<T> sum_op;
|
||||
return sum_op(saccum, predux(vaccum)) / (scalarCount_ + packetCount_ * unpacket_traits<Packet>::size);
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -304,7 +306,8 @@ template <typename T> struct ProdReducer
|
||||
static const bool IsStateful = false;
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const {
|
||||
(*accum) *= t;
|
||||
internal::scalar_product_op<T> prod_op;
|
||||
(*accum) = prod_op(*accum, t);
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const {
|
||||
@@ -328,7 +331,8 @@ template <typename T> struct ProdReducer
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return saccum * predux_mul(vaccum);
|
||||
internal::scalar_product_op<T> prod_op;
|
||||
return prod_op(saccum, predux_mul(vaccum));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -116,10 +116,10 @@ void test_cuda_argmax_dim()
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor_arg.dimensions().TotalSize(),
|
||||
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||
size_t(2*3*5*7 / tensor.dimension(dim)));
|
||||
|
||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
||||
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||
// Expect max to be in the first index of the reduced dimension
|
||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
||||
}
|
||||
@@ -144,7 +144,7 @@ void test_cuda_argmax_dim()
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
|
||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
||||
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||
// Expect max to be in the last index of the reduced dimension
|
||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
||||
}
|
||||
@@ -205,10 +205,10 @@ void test_cuda_argmin_dim()
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor_arg.dimensions().TotalSize(),
|
||||
size_t(2*3*5*7 / tensor.dimension(dim)));
|
||||
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||
2*3*5*7 / tensor.dimension(dim));
|
||||
|
||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
||||
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||
// Expect min to be in the first index of the reduced dimension
|
||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ void test_cuda_argmin_dim()
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
|
||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
||||
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||
// Expect max to be in the last index of the reduced dimension
|
||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
||||
}
|
||||
|
||||
@@ -108,8 +108,46 @@ static void test_cuda_sum_reductions() {
|
||||
}
|
||||
|
||||
|
||||
static void test_cuda_product_reductions() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||
const int num_cols = internal::random<int>(1024, 5*1024);
|
||||
|
||||
Tensor<std::complex<float>, 2> in(num_rows, num_cols);
|
||||
in.setRandom();
|
||||
|
||||
Tensor<std::complex<float>, 0> full_redux;
|
||||
full_redux = in.prod();
|
||||
|
||||
std::size_t in_bytes = in.size() * sizeof(std::complex<float>);
|
||||
std::size_t out_bytes = full_redux.size() * sizeof(std::complex<float>);
|
||||
std::complex<float>* gpu_in_ptr = static_cast<std::complex<float>*>(gpu_device.allocate(in_bytes));
|
||||
std::complex<float>* gpu_out_ptr = static_cast<std::complex<float>*>(gpu_device.allocate(out_bytes));
|
||||
gpu_device.memcpyHostToDevice(gpu_in_ptr, in.data(), in_bytes);
|
||||
|
||||
TensorMap<Tensor<std::complex<float>, 2> > in_gpu(gpu_in_ptr, num_rows, num_cols);
|
||||
TensorMap<Tensor<std::complex<float>, 0> > out_gpu(gpu_out_ptr);
|
||||
|
||||
out_gpu.device(gpu_device) = in_gpu.prod();
|
||||
|
||||
Tensor<std::complex<float>, 0> full_redux_gpu;
|
||||
gpu_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_ptr, out_bytes);
|
||||
gpu_device.synchronize();
|
||||
|
||||
// Check that the CPU and GPU reductions return the same result.
|
||||
VERIFY_IS_APPROX(full_redux(), full_redux_gpu());
|
||||
|
||||
gpu_device.deallocate(gpu_in_ptr);
|
||||
gpu_device.deallocate(gpu_out_ptr);
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_complex()
|
||||
{
|
||||
CALL_SUBTEST(test_cuda_nullary());
|
||||
CALL_SUBTEST(test_cuda_sum_reductions());
|
||||
CALL_SUBTEST(test_cuda_product_reductions());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user