mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
merging the CUDA and HIP implementation for the Tensor directory and the unit tests
This commit is contained in:
@@ -274,24 +274,24 @@ if(CUDA_FOUND AND EIGEN_TEST_CUDA)
|
||||
cuda_include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}/include")
|
||||
set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu")
|
||||
|
||||
ei_add_test(cxx11_tensor_complex_cuda)
|
||||
ei_add_test(cxx11_tensor_complex_cwise_ops_cuda)
|
||||
ei_add_test(cxx11_tensor_reduction_cuda)
|
||||
ei_add_test(cxx11_tensor_argmax_cuda)
|
||||
ei_add_test(cxx11_tensor_cast_float16_cuda)
|
||||
ei_add_test(cxx11_tensor_scan_cuda)
|
||||
ei_add_test(cxx11_tensor_complex_gpu)
|
||||
ei_add_test(cxx11_tensor_complex_cwise_ops_gpu)
|
||||
ei_add_test(cxx11_tensor_reduction_gpu)
|
||||
ei_add_test(cxx11_tensor_argmax_gpu)
|
||||
ei_add_test(cxx11_tensor_cast_float16_gpu)
|
||||
ei_add_test(cxx11_tensor_scan_gpu)
|
||||
|
||||
# Contractions require arch 3.0 or higher
|
||||
if (${EIGEN_CUDA_COMPUTE_ARCH} GREATER 29)
|
||||
ei_add_test(cxx11_tensor_device)
|
||||
ei_add_test(cxx11_tensor_cuda)
|
||||
ei_add_test(cxx11_tensor_contract_cuda)
|
||||
ei_add_test(cxx11_tensor_of_float16_cuda)
|
||||
ei_add_test(cxx11_tensor_gpu)
|
||||
ei_add_test(cxx11_tensor_contract_gpu)
|
||||
ei_add_test(cxx11_tensor_of_float16_gpu)
|
||||
endif()
|
||||
|
||||
# The random number generation code requires arch 3.5 or greater.
|
||||
if (${EIGEN_CUDA_COMPUTE_ARCH} GREATER 34)
|
||||
ei_add_test(cxx11_tensor_random_cuda)
|
||||
ei_add_test(cxx11_tensor_random_gpu)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -318,18 +318,23 @@ if (EIGEN_TEST_HIP)
|
||||
include_directories(${HIP_PATH}/include)
|
||||
|
||||
set(EIGEN_ADD_TEST_FILENAME_EXTENSION "cu")
|
||||
#
|
||||
# complex datatype is not yet supported by HIP
|
||||
# so leaving out those tests for now
|
||||
#
|
||||
# ei_add_test(cxx11_tensor_complex_gpu)
|
||||
# ei_add_test(cxx11_tensor_complex_cwise_ops_gpu)
|
||||
#
|
||||
ei_add_test(cxx11_tensor_reduction_gpu)
|
||||
ei_add_test(cxx11_tensor_argmax_gpu)
|
||||
ei_add_test(cxx11_tensor_cast_float16_gpu)
|
||||
ei_add_test(cxx11_tensor_scan_gpu)
|
||||
ei_add_test(cxx11_tensor_device)
|
||||
|
||||
# ei_add_test(cxx11_tensor_complex_hip)
|
||||
# ei_add_test(cxx11_tensor_complex_cwise_ops_hip)
|
||||
ei_add_test(cxx11_tensor_reduction_hip)
|
||||
ei_add_test(cxx11_tensor_argmax_hip)
|
||||
ei_add_test(cxx11_tensor_cast_float16_hip)
|
||||
ei_add_test(cxx11_tensor_scan_hip)
|
||||
ei_add_test(cxx11_tensor_device_hip)
|
||||
ei_add_test(cxx11_tensor_hip)
|
||||
ei_add_test(cxx11_tensor_contract_hip)
|
||||
ei_add_test(cxx11_tensor_of_float16_hip)
|
||||
ei_add_test(cxx11_tensor_random_hip)
|
||||
ei_add_test(cxx11_tensor_gpu)
|
||||
ei_add_test(cxx11_tensor_contract_gpu)
|
||||
ei_add_test(cxx11_tensor_of_float16_gpu)
|
||||
ei_add_test(cxx11_tensor_random_gpu)
|
||||
|
||||
unset(EIGEN_ADD_TEST_FILENAME_EXTENSION)
|
||||
|
||||
|
||||
@@ -9,16 +9,18 @@
|
||||
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_gpu
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
#include <unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h>
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
template <int Layout>
|
||||
void test_cuda_simple_argmax()
|
||||
void test_gpu_simple_argmax()
|
||||
{
|
||||
Tensor<double, 3, Layout> in(Eigen::array<DenseIndex, 3>(72,53,97));
|
||||
Tensor<DenseIndex, 1, Layout> out_max(Eigen::array<DenseIndex, 1>(1));
|
||||
@@ -34,13 +36,13 @@ void test_cuda_simple_argmax()
|
||||
double* d_in;
|
||||
DenseIndex* d_out_max;
|
||||
DenseIndex* d_out_min;
|
||||
cudaMalloc((void**)(&d_in), in_bytes);
|
||||
cudaMalloc((void**)(&d_out_max), out_bytes);
|
||||
cudaMalloc((void**)(&d_out_min), out_bytes);
|
||||
gpuMalloc((void**)(&d_in), in_bytes);
|
||||
gpuMalloc((void**)(&d_out_max), out_bytes);
|
||||
gpuMalloc((void**)(&d_out_min), out_bytes);
|
||||
|
||||
cudaMemcpy(d_in, in.data(), in_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in, in.data(), in_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<double, 3, Layout>, Aligned > gpu_in(d_in, Eigen::array<DenseIndex, 3>(72,53,97));
|
||||
@@ -50,20 +52,20 @@ void test_cuda_simple_argmax()
|
||||
gpu_out_max.device(gpu_device) = gpu_in.argmax();
|
||||
gpu_out_min.device(gpu_device) = gpu_in.argmin();
|
||||
|
||||
assert(cudaMemcpyAsync(out_max.data(), d_out_max, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaMemcpyAsync(out_min.data(), d_out_min, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out_max.data(), d_out_max, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuMemcpyAsync(out_min.data(), d_out_min, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
VERIFY_IS_EQUAL(out_max(Eigen::array<DenseIndex, 1>(0)), 72*53*97 - 1);
|
||||
VERIFY_IS_EQUAL(out_min(Eigen::array<DenseIndex, 1>(0)), 0);
|
||||
|
||||
cudaFree(d_in);
|
||||
cudaFree(d_out_max);
|
||||
cudaFree(d_out_min);
|
||||
gpuFree(d_in);
|
||||
gpuFree(d_out_max);
|
||||
gpuFree(d_out_min);
|
||||
}
|
||||
|
||||
template <int DataLayout>
|
||||
void test_cuda_argmax_dim()
|
||||
void test_gpu_argmax_dim()
|
||||
{
|
||||
Tensor<float, 4, DataLayout> tensor(2,3,5,7);
|
||||
std::vector<int> dims;
|
||||
@@ -97,12 +99,12 @@ void test_cuda_argmax_dim()
|
||||
|
||||
float* d_in;
|
||||
DenseIndex* d_out;
|
||||
cudaMalloc((void**)(&d_in), in_bytes);
|
||||
cudaMalloc((void**)(&d_out), out_bytes);
|
||||
gpuMalloc((void**)(&d_in), in_bytes);
|
||||
gpuMalloc((void**)(&d_out), out_bytes);
|
||||
|
||||
cudaMemcpy(d_in, tensor.data(), in_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in, tensor.data(), in_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 4, DataLayout>, Aligned > gpu_in(d_in, Eigen::array<DenseIndex, 4>(2, 3, 5, 7));
|
||||
@@ -110,8 +112,8 @@ void test_cuda_argmax_dim()
|
||||
|
||||
gpu_out.device(gpu_device) = gpu_in.argmax(dim);
|
||||
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(tensor_arg.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||
size_t(2*3*5*7 / tensor.dimension(dim)));
|
||||
@@ -134,25 +136,25 @@ void test_cuda_argmax_dim()
|
||||
}
|
||||
}
|
||||
|
||||
cudaMemcpy(d_in, tensor.data(), in_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in, tensor.data(), in_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
gpu_out.device(gpu_device) = gpu_in.argmax(dim);
|
||||
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(tensor_arg.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
cudaFree(d_in);
|
||||
cudaFree(d_out);
|
||||
gpuFree(d_in);
|
||||
gpuFree(d_out);
|
||||
}
|
||||
}
|
||||
|
||||
template <int DataLayout>
|
||||
void test_cuda_argmin_dim()
|
||||
void test_gpu_argmin_dim()
|
||||
{
|
||||
Tensor<float, 4, DataLayout> tensor(2,3,5,7);
|
||||
std::vector<int> dims;
|
||||
@@ -186,12 +188,12 @@ void test_cuda_argmin_dim()
|
||||
|
||||
float* d_in;
|
||||
DenseIndex* d_out;
|
||||
cudaMalloc((void**)(&d_in), in_bytes);
|
||||
cudaMalloc((void**)(&d_out), out_bytes);
|
||||
gpuMalloc((void**)(&d_in), in_bytes);
|
||||
gpuMalloc((void**)(&d_out), out_bytes);
|
||||
|
||||
cudaMemcpy(d_in, tensor.data(), in_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in, tensor.data(), in_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 4, DataLayout>, Aligned > gpu_in(d_in, Eigen::array<DenseIndex, 4>(2, 3, 5, 7));
|
||||
@@ -199,8 +201,8 @@ void test_cuda_argmin_dim()
|
||||
|
||||
gpu_out.device(gpu_device) = gpu_in.argmin(dim);
|
||||
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(tensor_arg.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||
2*3*5*7 / tensor.dimension(dim));
|
||||
@@ -223,29 +225,29 @@ void test_cuda_argmin_dim()
|
||||
}
|
||||
}
|
||||
|
||||
cudaMemcpy(d_in, tensor.data(), in_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in, tensor.data(), in_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
gpu_out.device(gpu_device) = gpu_in.argmin(dim);
|
||||
|
||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(tensor_arg.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
cudaFree(d_in);
|
||||
cudaFree(d_out);
|
||||
gpuFree(d_in);
|
||||
gpuFree(d_out);
|
||||
}
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_cuda()
|
||||
void test_cxx11_tensor_gpu()
|
||||
{
|
||||
CALL_SUBTEST_1(test_cuda_simple_argmax<RowMajor>());
|
||||
CALL_SUBTEST_1(test_cuda_simple_argmax<ColMajor>());
|
||||
CALL_SUBTEST_2(test_cuda_argmax_dim<RowMajor>());
|
||||
CALL_SUBTEST_2(test_cuda_argmax_dim<ColMajor>());
|
||||
CALL_SUBTEST_3(test_cuda_argmin_dim<RowMajor>());
|
||||
CALL_SUBTEST_3(test_cuda_argmin_dim<ColMajor>());
|
||||
CALL_SUBTEST_1(test_gpu_simple_argmax<RowMajor>());
|
||||
CALL_SUBTEST_1(test_gpu_simple_argmax<ColMajor>());
|
||||
CALL_SUBTEST_2(test_gpu_argmax_dim<RowMajor>());
|
||||
CALL_SUBTEST_2(test_gpu_argmax_dim<ColMajor>());
|
||||
CALL_SUBTEST_3(test_gpu_argmin_dim<RowMajor>());
|
||||
CALL_SUBTEST_3(test_gpu_argmin_dim<ColMajor>());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_cast_float16_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_cast_float16_gpu
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
void test_cuda_conversion() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_conversion() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -72,8 +72,8 @@ void test_fallback_conversion() {
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_cast_float16_cuda()
|
||||
void test_cxx11_tensor_cast_float16_gpu()
|
||||
{
|
||||
CALL_SUBTEST(test_cuda_conversion());
|
||||
CALL_SUBTEST(test_gpu_conversion());
|
||||
CALL_SUBTEST(test_fallback_conversion());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void test_cuda_complex_cwise_ops() {
|
||||
cudaMalloc((void**)(&d_in2), complex_bytes);
|
||||
cudaMalloc((void**)(&d_out), complex_bytes);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<std::complex<T>, 1, 0, int>, Eigen::Aligned> gpu_in1(
|
||||
|
||||
@@ -34,7 +34,7 @@ void test_cuda_nullary() {
|
||||
cudaMemcpy(d_in1, in1.data(), complex_bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_in2, in2.data(), complex_bytes, cudaMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<std::complex<float>, 1, 0, int>, Eigen::Aligned> gpu_in1(
|
||||
@@ -70,7 +70,7 @@ void test_cuda_nullary() {
|
||||
|
||||
static void test_cuda_sum_reductions() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||
@@ -106,7 +106,7 @@ static void test_cuda_sum_reductions() {
|
||||
|
||||
static void test_cuda_mean_reductions() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||
@@ -142,7 +142,7 @@ static void test_cuda_mean_reductions() {
|
||||
|
||||
static void test_cuda_product_reductions() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||
|
||||
@@ -10,19 +10,20 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_gpu
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
#include <unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h>
|
||||
|
||||
using Eigen::Tensor;
|
||||
typedef Tensor<float, 1>::DimensionPair DimPair;
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_contraction(int m_size, int k_size, int n_size)
|
||||
void test_gpu_contraction(int m_size, int k_size, int n_size)
|
||||
{
|
||||
std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size << ")" << std::endl;
|
||||
// with these dimensions, the output has 300 * 140 elements, which is
|
||||
@@ -45,14 +46,14 @@ void test_cuda_contraction(int m_size, int k_size, int n_size)
|
||||
float* d_t_right;
|
||||
float* d_t_result;
|
||||
|
||||
cudaMalloc((void**)(&d_t_left), t_left_bytes);
|
||||
cudaMalloc((void**)(&d_t_right), t_right_bytes);
|
||||
cudaMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
gpuMalloc((void**)(&d_t_left), t_left_bytes);
|
||||
gpuMalloc((void**)(&d_t_right), t_right_bytes);
|
||||
gpuMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
|
||||
cudaMemcpy(d_t_left, t_left.data(), t_left_bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_t_right, t_right.data(), t_right_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_t_left, t_left.data(), t_left_bytes, gpuMemcpyHostToDevice);
|
||||
gpuMemcpy(d_t_right, t_right.data(), t_right_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> >
|
||||
@@ -66,7 +67,7 @@ void test_cuda_contraction(int m_size, int k_size, int n_size)
|
||||
gpu_t_result.device(gpu_device) = gpu_t_left.contract(gpu_t_right, dims);
|
||||
t_result = t_left.contract(t_right, dims);
|
||||
|
||||
cudaMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, cudaMemcpyDeviceToHost);
|
||||
gpuMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, gpuMemcpyDeviceToHost);
|
||||
for (DenseIndex i = 0; i < t_result.size(); i++) {
|
||||
if (fabs(t_result(i) - t_result_gpu(i)) < 1e-4f) {
|
||||
continue;
|
||||
@@ -79,9 +80,9 @@ void test_cuda_contraction(int m_size, int k_size, int n_size)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
cudaFree((void*)d_t_left);
|
||||
cudaFree((void*)d_t_right);
|
||||
cudaFree((void*)d_t_result);
|
||||
gpuFree((void*)d_t_left);
|
||||
gpuFree((void*)d_t_right);
|
||||
gpuFree((void*)d_t_result);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,14 +110,14 @@ void test_scalar(int m_size, int k_size, int n_size)
|
||||
float* d_t_right;
|
||||
float* d_t_result;
|
||||
|
||||
cudaMalloc((void**)(&d_t_left), t_left_bytes);
|
||||
cudaMalloc((void**)(&d_t_right), t_right_bytes);
|
||||
cudaMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
gpuMalloc((void**)(&d_t_left), t_left_bytes);
|
||||
gpuMalloc((void**)(&d_t_right), t_right_bytes);
|
||||
gpuMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
|
||||
cudaMemcpy(d_t_left, t_left.data(), t_left_bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_t_right, t_right.data(), t_right_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_t_left, t_left.data(), t_left_bytes, gpuMemcpyHostToDevice);
|
||||
gpuMemcpy(d_t_right, t_right.data(), t_right_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> >
|
||||
@@ -129,7 +130,7 @@ void test_scalar(int m_size, int k_size, int n_size)
|
||||
gpu_t_result.device(gpu_device) = gpu_t_left.contract(gpu_t_right, dims);
|
||||
t_result = t_left.contract(t_right, dims);
|
||||
|
||||
cudaMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, cudaMemcpyDeviceToHost);
|
||||
gpuMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, gpuMemcpyDeviceToHost);
|
||||
if (fabs(t_result() - t_result_gpu()) > 1e-4f &&
|
||||
!Eigen::internal::isApprox(t_result(), t_result_gpu(), 1e-4f)) {
|
||||
std::cout << "mismatch detected: " << t_result()
|
||||
@@ -137,39 +138,39 @@ void test_scalar(int m_size, int k_size, int n_size)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
cudaFree((void*)d_t_left);
|
||||
cudaFree((void*)d_t_right);
|
||||
cudaFree((void*)d_t_result);
|
||||
gpuFree((void*)d_t_left);
|
||||
gpuFree((void*)d_t_right);
|
||||
gpuFree((void*)d_t_result);
|
||||
}
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_contraction_m() {
|
||||
void test_gpu_contraction_m() {
|
||||
for (int k = 32; k < 256; k++) {
|
||||
test_cuda_contraction<ColMajor>(k, 128, 128);
|
||||
test_cuda_contraction<RowMajor>(k, 128, 128);
|
||||
test_gpu_contraction<ColMajor>(k, 128, 128);
|
||||
test_gpu_contraction<RowMajor>(k, 128, 128);
|
||||
}
|
||||
}
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_contraction_k() {
|
||||
void test_gpu_contraction_k() {
|
||||
for (int k = 32; k < 256; k++) {
|
||||
test_cuda_contraction<ColMajor>(128, k, 128);
|
||||
test_cuda_contraction<RowMajor>(128, k, 128);
|
||||
test_gpu_contraction<ColMajor>(128, k, 128);
|
||||
test_gpu_contraction<RowMajor>(128, k, 128);
|
||||
}
|
||||
}
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_contraction_n() {
|
||||
void test_gpu_contraction_n() {
|
||||
for (int k = 32; k < 256; k++) {
|
||||
test_cuda_contraction<ColMajor>(128, 128, k);
|
||||
test_cuda_contraction<RowMajor>(128, 128, k);
|
||||
test_gpu_contraction<ColMajor>(128, 128, k);
|
||||
test_gpu_contraction<RowMajor>(128, 128, k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_contraction_sizes() {
|
||||
void test_gpu_contraction_sizes() {
|
||||
int m_sizes[] = { 31, 39, 63, 64, 65,
|
||||
127, 129, 255, 257 , 511,
|
||||
512, 513, 1023, 1024, 1025};
|
||||
@@ -186,29 +187,32 @@ void test_cuda_contraction_sizes() {
|
||||
for (int i = 0; i < 15; i++) {
|
||||
for (int j = 0; j < 15; j++) {
|
||||
for (int k = 0; k < 17; k++) {
|
||||
test_cuda_contraction<DataLayout>(m_sizes[i], n_sizes[j], k_sizes[k]);
|
||||
test_gpu_contraction<DataLayout>(m_sizes[i], n_sizes[j], k_sizes[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_cuda()
|
||||
void test_cxx11_tensor_gpu()
|
||||
{
|
||||
CALL_SUBTEST_1(test_cuda_contraction<ColMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_1(test_cuda_contraction<RowMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_1(test_gpu_contraction<ColMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_1(test_gpu_contraction<RowMajor>(128, 128, 128));
|
||||
|
||||
CALL_SUBTEST_1(test_scalar<ColMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_1(test_scalar<RowMajor>(128, 128, 128));
|
||||
|
||||
CALL_SUBTEST_2(test_cuda_contraction_m<ColMajor>());
|
||||
CALL_SUBTEST_3(test_cuda_contraction_m<RowMajor>());
|
||||
CALL_SUBTEST_2(test_gpu_contraction_m<ColMajor>());
|
||||
CALL_SUBTEST_3(test_gpu_contraction_m<RowMajor>());
|
||||
|
||||
CALL_SUBTEST_4(test_cuda_contraction_k<ColMajor>());
|
||||
CALL_SUBTEST_5(test_cuda_contraction_k<RowMajor>());
|
||||
CALL_SUBTEST_4(test_gpu_contraction_k<ColMajor>());
|
||||
CALL_SUBTEST_5(test_gpu_contraction_k<RowMajor>());
|
||||
|
||||
CALL_SUBTEST_6(test_cuda_contraction_n<ColMajor>());
|
||||
CALL_SUBTEST_7(test_cuda_contraction_n<RowMajor>());
|
||||
CALL_SUBTEST_6(test_gpu_contraction_n<ColMajor>());
|
||||
CALL_SUBTEST_7(test_gpu_contraction_n<RowMajor>());
|
||||
|
||||
CALL_SUBTEST_8(test_cuda_contraction_sizes<ColMajor>());
|
||||
CALL_SUBTEST_9(test_cuda_contraction_sizes<RowMajor>());
|
||||
#if !defined(EIGEN_USE_HIP)
|
||||
// disable these subtests for HIP
|
||||
CALL_SUBTEST_8(test_gpu_contraction_sizes<ColMajor>());
|
||||
CALL_SUBTEST_9(test_gpu_contraction_sizes<RowMajor>());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
#include <unsupported/Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h>
|
||||
|
||||
using Eigen::Tensor;
|
||||
using Eigen::RowMajor;
|
||||
@@ -66,22 +67,22 @@ struct CPUContext {
|
||||
// Context for evaluation on GPU
|
||||
struct GPUContext {
|
||||
GPUContext(const Eigen::TensorMap<Eigen::Tensor<float, 3> >& in1, Eigen::TensorMap<Eigen::Tensor<float, 3> >& in2, Eigen::TensorMap<Eigen::Tensor<float, 3> >& out) : in1_(in1), in2_(in2), out_(out), gpu_device_(&stream_) {
|
||||
assert(cudaMalloc((void**)(&kernel_1d_), 2*sizeof(float)) == cudaSuccess);
|
||||
assert(gpuMalloc((void**)(&kernel_1d_), 2*sizeof(float)) == gpuSuccess);
|
||||
float kernel_1d_val[] = {3.14f, 2.7f};
|
||||
assert(cudaMemcpy(kernel_1d_, kernel_1d_val, 2*sizeof(float), cudaMemcpyHostToDevice) == cudaSuccess);
|
||||
assert(gpuMemcpy(kernel_1d_, kernel_1d_val, 2*sizeof(float), gpuMemcpyHostToDevice) == gpuSuccess);
|
||||
|
||||
assert(cudaMalloc((void**)(&kernel_2d_), 4*sizeof(float)) == cudaSuccess);
|
||||
assert(gpuMalloc((void**)(&kernel_2d_), 4*sizeof(float)) == gpuSuccess);
|
||||
float kernel_2d_val[] = {3.14f, 2.7f, 0.2f, 7.0f};
|
||||
assert(cudaMemcpy(kernel_2d_, kernel_2d_val, 4*sizeof(float), cudaMemcpyHostToDevice) == cudaSuccess);
|
||||
assert(gpuMemcpy(kernel_2d_, kernel_2d_val, 4*sizeof(float), gpuMemcpyHostToDevice) == gpuSuccess);
|
||||
|
||||
assert(cudaMalloc((void**)(&kernel_3d_), 8*sizeof(float)) == cudaSuccess);
|
||||
assert(gpuMalloc((void**)(&kernel_3d_), 8*sizeof(float)) == gpuSuccess);
|
||||
float kernel_3d_val[] = {3.14f, -1.0f, 2.7f, -0.3f, 0.2f, -0.7f, 7.0f, -0.5f};
|
||||
assert(cudaMemcpy(kernel_3d_, kernel_3d_val, 8*sizeof(float), cudaMemcpyHostToDevice) == cudaSuccess);
|
||||
assert(gpuMemcpy(kernel_3d_, kernel_3d_val, 8*sizeof(float), gpuMemcpyHostToDevice) == gpuSuccess);
|
||||
}
|
||||
~GPUContext() {
|
||||
assert(cudaFree(kernel_1d_) == cudaSuccess);
|
||||
assert(cudaFree(kernel_2d_) == cudaSuccess);
|
||||
assert(cudaFree(kernel_3d_) == cudaSuccess);
|
||||
assert(gpuFree(kernel_1d_) == gpuSuccess);
|
||||
assert(gpuFree(kernel_2d_) == gpuSuccess);
|
||||
assert(gpuFree(kernel_3d_) == gpuSuccess);
|
||||
}
|
||||
|
||||
const Eigen::GpuDevice& device() const { return gpu_device_; }
|
||||
@@ -102,7 +103,7 @@ struct GPUContext {
|
||||
float* kernel_2d_;
|
||||
float* kernel_3d_;
|
||||
|
||||
Eigen::CudaStreamDevice stream_;
|
||||
Eigen::GpuStreamDevice stream_;
|
||||
Eigen::GpuDevice gpu_device_;
|
||||
};
|
||||
|
||||
@@ -281,12 +282,12 @@ void test_gpu() {
|
||||
float* d_in1;
|
||||
float* d_in2;
|
||||
float* d_out;
|
||||
cudaMalloc((void**)(&d_in1), in1_bytes);
|
||||
cudaMalloc((void**)(&d_in2), in2_bytes);
|
||||
cudaMalloc((void**)(&d_out), out_bytes);
|
||||
gpuMalloc((void**)(&d_in1), in1_bytes);
|
||||
gpuMalloc((void**)(&d_in2), in2_bytes);
|
||||
gpuMalloc((void**)(&d_out), out_bytes);
|
||||
|
||||
cudaMemcpy(d_in1, in1.data(), in1_bytes, cudaMemcpyHostToDevice);
|
||||
cudaMemcpy(d_in2, in2.data(), in2_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in1, in1.data(), in1_bytes, gpuMemcpyHostToDevice);
|
||||
gpuMemcpy(d_in2, in2.data(), in2_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3> > gpu_in1(d_in1, 40,50,70);
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3> > gpu_in2(d_in2, 40,50,70);
|
||||
@@ -294,7 +295,7 @@ void test_gpu() {
|
||||
|
||||
GPUContext context(gpu_in1, gpu_in2, gpu_out);
|
||||
test_contextual_eval(&context);
|
||||
assert(cudaMemcpy(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost) == cudaSuccess);
|
||||
assert(gpuMemcpy(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 50; ++j) {
|
||||
for (int k = 0; k < 70; ++k) {
|
||||
@@ -304,7 +305,7 @@ void test_gpu() {
|
||||
}
|
||||
|
||||
test_forced_contextual_eval(&context);
|
||||
assert(cudaMemcpy(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost) == cudaSuccess);
|
||||
assert(gpuMemcpy(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 50; ++j) {
|
||||
for (int k = 0; k < 70; ++k) {
|
||||
@@ -314,7 +315,7 @@ void test_gpu() {
|
||||
}
|
||||
|
||||
test_compound_assignment(&context);
|
||||
assert(cudaMemcpy(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost) == cudaSuccess);
|
||||
assert(gpuMemcpy(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 50; ++j) {
|
||||
for (int k = 0; k < 70; ++k) {
|
||||
@@ -324,7 +325,7 @@ void test_gpu() {
|
||||
}
|
||||
|
||||
test_contraction(&context);
|
||||
assert(cudaMemcpy(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost) == cudaSuccess);
|
||||
assert(gpuMemcpy(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 40; ++j) {
|
||||
const float result = out(i,j,0);
|
||||
@@ -339,8 +340,8 @@ void test_gpu() {
|
||||
}
|
||||
|
||||
test_1d_convolution(&context);
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, context.device().stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(context.device().stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, context.device().stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(context.device().stream()) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 49; ++j) {
|
||||
for (int k = 0; k < 70; ++k) {
|
||||
@@ -350,8 +351,8 @@ void test_gpu() {
|
||||
}
|
||||
|
||||
test_2d_convolution(&context);
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, context.device().stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(context.device().stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, context.device().stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(context.device().stream()) == gpuSuccess);
|
||||
for (int i = 0; i < 40; ++i) {
|
||||
for (int j = 0; j < 49; ++j) {
|
||||
for (int k = 0; k < 69; ++k) {
|
||||
@@ -363,9 +364,13 @@ void test_gpu() {
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(EIGEN_USE_HIP)
|
||||
// disable this test on the HIP platform
|
||||
// 3D tensor convolutions seem to hang on the HIP platform
|
||||
|
||||
test_3d_convolution(&context);
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, context.device().stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(context.device().stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, context.device().stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(context.device().stream()) == gpuSuccess);
|
||||
for (int i = 0; i < 39; ++i) {
|
||||
for (int j = 0; j < 49; ++j) {
|
||||
for (int k = 0; k < 69; ++k) {
|
||||
@@ -378,6 +383,9 @@ void test_gpu() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_of_float16_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_of_float16_gpu
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
using Eigen::Tensor;
|
||||
|
||||
template<typename>
|
||||
void test_cuda_numext() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_numext() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -57,11 +57,11 @@ void test_cuda_numext() {
|
||||
}
|
||||
|
||||
|
||||
#ifdef EIGEN_HAS_CUDA_FP16
|
||||
#ifdef EIGEN_HAS_GPU_FP16
|
||||
|
||||
template<typename>
|
||||
void test_cuda_conversion() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_conversion() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -95,8 +95,8 @@ void test_cuda_conversion() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_unary() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_unary() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -132,8 +132,8 @@ void test_cuda_unary() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_elementwise() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_elementwise() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -174,8 +174,8 @@ void test_cuda_elementwise() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_trancendental() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_trancendental() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -268,8 +268,8 @@ void test_cuda_trancendental() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_contractions() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_contractions() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int rows = 23;
|
||||
int cols = 23;
|
||||
@@ -319,12 +319,12 @@ void test_cuda_contractions() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_reductions(int size1, int size2, int redux) {
|
||||
void test_gpu_reductions(int size1, int size2, int redux) {
|
||||
|
||||
std::cout << "Reducing " << size1 << " by " << size2
|
||||
<< " tensor along dim " << redux << std::endl;
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = size1*size2;
|
||||
int result_size = (redux == 1 ? size1 : size2);
|
||||
@@ -368,20 +368,20 @@ void test_cuda_reductions(int size1, int size2, int redux) {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_reductions() {
|
||||
test_cuda_reductions<void>(13, 13, 0);
|
||||
test_cuda_reductions<void>(13, 13, 1);
|
||||
void test_gpu_reductions() {
|
||||
test_gpu_reductions<void>(13, 13, 0);
|
||||
test_gpu_reductions<void>(13, 13, 1);
|
||||
|
||||
test_cuda_reductions<void>(35, 36, 0);
|
||||
test_cuda_reductions<void>(35, 36, 1);
|
||||
test_gpu_reductions<void>(35, 36, 0);
|
||||
test_gpu_reductions<void>(35, 36, 1);
|
||||
|
||||
test_cuda_reductions<void>(36, 35, 0);
|
||||
test_cuda_reductions<void>(36, 35, 1);
|
||||
test_gpu_reductions<void>(36, 35, 0);
|
||||
test_gpu_reductions<void>(36, 35, 1);
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_full_reductions() {
|
||||
Eigen::CudaStreamDevice stream;
|
||||
void test_gpu_full_reductions() {
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int size = 13;
|
||||
int num_elem = size*size;
|
||||
@@ -429,9 +429,9 @@ void test_cuda_full_reductions() {
|
||||
}
|
||||
|
||||
template<typename>
|
||||
void test_cuda_forced_evals() {
|
||||
void test_gpu_forced_evals() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
int num_elem = 101;
|
||||
|
||||
@@ -479,20 +479,20 @@ void test_cuda_forced_evals() {
|
||||
#endif
|
||||
|
||||
|
||||
void test_cxx11_tensor_of_float16_cuda()
|
||||
void test_cxx11_tensor_of_float16_gpu()
|
||||
{
|
||||
CALL_SUBTEST_1(test_cuda_numext<void>());
|
||||
CALL_SUBTEST_1(test_gpu_numext<void>());
|
||||
|
||||
#ifdef EIGEN_HAS_CUDA_FP16
|
||||
CALL_SUBTEST_1(test_cuda_conversion<void>());
|
||||
CALL_SUBTEST_1(test_cuda_unary<void>());
|
||||
CALL_SUBTEST_1(test_cuda_elementwise<void>());
|
||||
CALL_SUBTEST_1(test_cuda_trancendental<void>());
|
||||
CALL_SUBTEST_2(test_cuda_contractions<void>());
|
||||
CALL_SUBTEST_3(test_cuda_reductions<void>());
|
||||
CALL_SUBTEST_4(test_cuda_full_reductions<void>());
|
||||
CALL_SUBTEST_5(test_cuda_forced_evals<void>());
|
||||
#ifdef EIGEN_HAS_GPU_FP16
|
||||
CALL_SUBTEST_1(test_gpu_conversion<void>());
|
||||
CALL_SUBTEST_1(test_gpu_unary<void>());
|
||||
CALL_SUBTEST_1(test_gpu_elementwise<void>());
|
||||
CALL_SUBTEST_1(test_gpu_trancendental<void>());
|
||||
CALL_SUBTEST_2(test_gpu_contractions<void>());
|
||||
CALL_SUBTEST_3(test_gpu_reductions<void>());
|
||||
CALL_SUBTEST_4(test_gpu_full_reductions<void>());
|
||||
CALL_SUBTEST_5(test_gpu_forced_evals<void>());
|
||||
#else
|
||||
std::cout << "Half floats are not supported by this version of cuda: skipping the test" << std::endl;
|
||||
std::cout << "Half floats are not supported by this version of gpu: skipping the test" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -9,15 +9,16 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_random_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_random_gpu
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
#include "main.h"
|
||||
#include <Eigen/CXX11/Tensor>
|
||||
|
||||
#include <Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h>
|
||||
|
||||
void test_cuda_random_uniform()
|
||||
void test_gpu_random_uniform()
|
||||
{
|
||||
Tensor<float, 2> out(72,97);
|
||||
out.setZero();
|
||||
@@ -25,24 +26,24 @@ void test_cuda_random_uniform()
|
||||
std::size_t out_bytes = out.size() * sizeof(float);
|
||||
|
||||
float* d_out;
|
||||
cudaMalloc((void**)(&d_out), out_bytes);
|
||||
gpuMalloc((void**)(&d_out), out_bytes);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 2> > gpu_out(d_out, 72,97);
|
||||
|
||||
gpu_out.device(gpu_device) = gpu_out.random();
|
||||
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
|
||||
// For now we just check this code doesn't crash.
|
||||
// TODO: come up with a valid test of randomness
|
||||
}
|
||||
|
||||
|
||||
void test_cuda_random_normal()
|
||||
void test_gpu_random_normal()
|
||||
{
|
||||
Tensor<float, 2> out(72,97);
|
||||
out.setZero();
|
||||
@@ -50,9 +51,9 @@ void test_cuda_random_normal()
|
||||
std::size_t out_bytes = out.size() * sizeof(float);
|
||||
|
||||
float* d_out;
|
||||
cudaMalloc((void**)(&d_out), out_bytes);
|
||||
gpuMalloc((void**)(&d_out), out_bytes);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 2> > gpu_out(d_out, 72,97);
|
||||
@@ -60,8 +61,8 @@ void test_cuda_random_normal()
|
||||
Eigen::internal::NormalRandomGenerator<float> gen(true);
|
||||
gpu_out.device(gpu_device) = gpu_out.random(gen);
|
||||
|
||||
assert(cudaMemcpyAsync(out.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||
assert(gpuMemcpyAsync(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost, gpu_device.stream()) == gpuSuccess);
|
||||
assert(gpuStreamSynchronize(gpu_device.stream()) == gpuSuccess);
|
||||
}
|
||||
|
||||
static void test_complex()
|
||||
@@ -77,9 +78,9 @@ static void test_complex()
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_random_cuda()
|
||||
void test_cxx11_tensor_random_gpu()
|
||||
{
|
||||
CALL_SUBTEST(test_cuda_random_uniform());
|
||||
CALL_SUBTEST(test_cuda_random_normal());
|
||||
CALL_SUBTEST(test_gpu_random_uniform());
|
||||
CALL_SUBTEST(test_gpu_random_normal());
|
||||
CALL_SUBTEST(test_complex());
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_reduction_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_reduction_gpu
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
#include "main.h"
|
||||
@@ -19,7 +19,7 @@
|
||||
template<typename Type, int DataLayout>
|
||||
static void test_full_reductions() {
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||
@@ -67,7 +67,7 @@ static void test_first_dim_reductions() {
|
||||
Tensor<Type, 2, DataLayout> redux = in.sum(red_axis);
|
||||
|
||||
// Create device
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice dev(&stream);
|
||||
|
||||
// Create data(T)
|
||||
@@ -107,7 +107,7 @@ static void test_last_dim_reductions() {
|
||||
Tensor<Type, 2, DataLayout> redux = in.sum(red_axis);
|
||||
|
||||
// Create device
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice dev(&stream);
|
||||
|
||||
// Create data
|
||||
@@ -134,7 +134,7 @@ static void test_last_dim_reductions() {
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_reduction_cuda() {
|
||||
void test_cxx11_tensor_reduction_gpu() {
|
||||
CALL_SUBTEST_1((test_full_reductions<float, ColMajor>()));
|
||||
CALL_SUBTEST_1((test_full_reductions<double, ColMajor>()));
|
||||
CALL_SUBTEST_2((test_full_reductions<float, RowMajor>()));
|
||||
|
||||
@@ -9,19 +9,20 @@
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_scan_cuda
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_scan_gpu
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_GPU
|
||||
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
#include <Eigen/CXX11/src/Tensor/TensorGpuHipCudaDefines.h>
|
||||
|
||||
using Eigen::Tensor;
|
||||
typedef Tensor<float, 1>::DimensionPair DimPair;
|
||||
|
||||
template<int DataLayout>
|
||||
void test_cuda_cumsum(int m_size, int k_size, int n_size)
|
||||
void test_gpu_cumsum(int m_size, int k_size, int n_size)
|
||||
{
|
||||
std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size << ")" << std::endl;
|
||||
Tensor<float, 3, DataLayout> t_input(m_size, k_size, n_size);
|
||||
@@ -36,12 +37,12 @@ void test_cuda_cumsum(int m_size, int k_size, int n_size)
|
||||
float* d_t_input;
|
||||
float* d_t_result;
|
||||
|
||||
cudaMalloc((void**)(&d_t_input), t_input_bytes);
|
||||
cudaMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
gpuMalloc((void**)(&d_t_input), t_input_bytes);
|
||||
gpuMalloc((void**)(&d_t_result), t_result_bytes);
|
||||
|
||||
cudaMemcpy(d_t_input, t_input.data(), t_input_bytes, cudaMemcpyHostToDevice);
|
||||
gpuMemcpy(d_t_input, t_input.data(), t_input_bytes, gpuMemcpyHostToDevice);
|
||||
|
||||
Eigen::CudaStreamDevice stream;
|
||||
Eigen::GpuStreamDevice stream;
|
||||
Eigen::GpuDevice gpu_device(&stream);
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3, DataLayout> >
|
||||
@@ -52,7 +53,7 @@ void test_cuda_cumsum(int m_size, int k_size, int n_size)
|
||||
gpu_t_result.device(gpu_device) = gpu_t_input.cumsum(1);
|
||||
t_result = t_input.cumsum(1);
|
||||
|
||||
cudaMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, cudaMemcpyDeviceToHost);
|
||||
gpuMemcpy(t_result_gpu.data(), d_t_result, t_result_bytes, gpuMemcpyDeviceToHost);
|
||||
for (DenseIndex i = 0; i < t_result.size(); i++) {
|
||||
if (fabs(t_result(i) - t_result_gpu(i)) < 1e-4f) {
|
||||
continue;
|
||||
@@ -65,13 +66,13 @@ void test_cuda_cumsum(int m_size, int k_size, int n_size)
|
||||
assert(false);
|
||||
}
|
||||
|
||||
cudaFree((void*)d_t_input);
|
||||
cudaFree((void*)d_t_result);
|
||||
gpuFree((void*)d_t_input);
|
||||
gpuFree((void*)d_t_result);
|
||||
}
|
||||
|
||||
|
||||
void test_cxx11_tensor_scan_cuda()
|
||||
void test_cxx11_tensor_scan_gpu()
|
||||
{
|
||||
CALL_SUBTEST_1(test_cuda_cumsum<ColMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_2(test_cuda_cumsum<RowMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_1(test_gpu_cumsum<ColMajor>(128, 128, 128));
|
||||
CALL_SUBTEST_2(test_gpu_cumsum<RowMajor>(128, 128, 128));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user