mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-14 12:46:00 +08:00
Fixed the partial evaluation of non vectorizable tensor subexpressions
This commit is contained in:
parent
fd9401f260
commit
4a164d2c46
@ -95,7 +95,7 @@ struct TensorEvaluator<const TensorEvalToOp<ArgType>, Device>
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
IsAligned = true,
|
IsAligned = true,
|
||||||
PacketAccess = true,
|
PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
|
||||||
Layout = TensorEvaluator<ArgType, Device>::Layout,
|
Layout = TensorEvaluator<ArgType, Device>::Layout,
|
||||||
CoordAccess = false, // to be implemented
|
CoordAccess = false, // to be implemented
|
||||||
RawAccess = true
|
RawAccess = true
|
||||||
|
@ -90,7 +90,7 @@ struct TensorEvaluator<const TensorForcedEvalOp<ArgType>, Device>
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
IsAligned = true,
|
IsAligned = true,
|
||||||
PacketAccess = (internal::packet_traits<Scalar>::size > 1),
|
PacketAccess = (PacketSize > 1),
|
||||||
Layout = TensorEvaluator<ArgType, Device>::Layout,
|
Layout = TensorEvaluator<ArgType, Device>::Layout,
|
||||||
RawAccess = true
|
RawAccess = true
|
||||||
};
|
};
|
||||||
|
@ -228,6 +228,42 @@ void test_cuda_reductions() {
|
|||||||
gpu_device.deallocate(d_res_float);
|
gpu_device.deallocate(d_res_float);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_cuda_forced_evals() {
|
||||||
|
|
||||||
|
Eigen::CudaStreamDevice stream;
|
||||||
|
Eigen::GpuDevice gpu_device(&stream);
|
||||||
|
int num_elem = 101;
|
||||||
|
|
||||||
|
float* d_float = (float*)gpu_device.allocate(num_elem * sizeof(float));
|
||||||
|
float* d_res_half = (float*)gpu_device.allocate(num_elem * sizeof(float));
|
||||||
|
float* d_res_float = (float*)gpu_device.allocate(num_elem * sizeof(float));
|
||||||
|
|
||||||
|
Eigen::TensorMap<Eigen::Tensor<float, 1>, Eigen::Aligned> gpu_float(
|
||||||
|
d_float, num_elem);
|
||||||
|
Eigen::TensorMap<Eigen::Tensor<float, 1>, Eigen::Aligned> gpu_res_half(
|
||||||
|
d_res_half, num_elem);
|
||||||
|
Eigen::TensorMap<Eigen::Tensor<float, 1>, Eigen::Aligned> gpu_res_float(
|
||||||
|
d_res_float, num_elem);
|
||||||
|
|
||||||
|
gpu_float.device(gpu_device) = gpu_float.random() - gpu_float.constant(0.5f);
|
||||||
|
gpu_res_float.device(gpu_device) = gpu_float.abs();
|
||||||
|
gpu_res_half.device(gpu_device) = gpu_float.cast<Eigen::half>().abs().eval().cast<float>();
|
||||||
|
|
||||||
|
Tensor<float, 1> half_prec(num_elem);
|
||||||
|
Tensor<float, 1> full_prec(num_elem);
|
||||||
|
gpu_device.memcpyDeviceToHost(half_prec.data(), d_res_half, num_elem*sizeof(float));
|
||||||
|
gpu_device.memcpyDeviceToHost(full_prec.data(), d_res_float, num_elem*sizeof(float));
|
||||||
|
gpu_device.synchronize();
|
||||||
|
|
||||||
|
for (int i = 0; i < num_elem; ++i) {
|
||||||
|
std::cout << "Checking unary " << i << std::endl;
|
||||||
|
VERIFY_IS_APPROX(full_prec(i), half_prec(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
gpu_device.deallocate(d_float);
|
||||||
|
gpu_device.deallocate(d_res_half);
|
||||||
|
gpu_device.deallocate(d_res_float);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -246,6 +282,7 @@ void test_cxx11_tensor_of_float16_cuda()
|
|||||||
CALL_SUBTEST_1(test_cuda_elementwise());
|
CALL_SUBTEST_1(test_cuda_elementwise());
|
||||||
CALL_SUBTEST_2(test_cuda_contractions());
|
CALL_SUBTEST_2(test_cuda_contractions());
|
||||||
CALL_SUBTEST_3(test_cuda_reductions());
|
CALL_SUBTEST_3(test_cuda_reductions());
|
||||||
|
CALL_SUBTEST_4(test_cuda_forced_evals());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "Half floats require compute capability of at least 5.3. This device only supports " << device.majorDeviceVersion() << "." << device.minorDeviceVersion() << ". Skipping the test" << std::endl;
|
std::cout << "Half floats require compute capability of at least 5.3. This device only supports " << device.majorDeviceVersion() << "." << device.minorDeviceVersion() << ". Skipping the test" << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user