mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -18,11 +18,10 @@
|
||||
struct AddKernel {
|
||||
// Parameters must be POD or serializable Eigen types (e.g. Matrix,
|
||||
// Array). The return value must be a POD or serializable value type.
|
||||
template<typename Type1, typename Type2, typename Type3>
|
||||
EIGEN_DEVICE_FUNC
|
||||
Type3 operator()(const Type1& A, const Type2& B, Type3& C) const {
|
||||
C = A + B; // Populate output parameter.
|
||||
Type3 D = A + B; // Populate return value.
|
||||
template <typename Type1, typename Type2, typename Type3>
|
||||
EIGEN_DEVICE_FUNC Type3 operator()(const Type1& A, const Type2& B, Type3& C) const {
|
||||
C = A + B; // Populate output parameter.
|
||||
Type3 D = A + B; // Populate return value.
|
||||
return D;
|
||||
}
|
||||
};
|
||||
@@ -36,7 +35,7 @@ void test_add(const T& type) {
|
||||
// Create random inputs.
|
||||
const T A = T::Random(rows, cols);
|
||||
const T B = T::Random(rows, cols);
|
||||
T C; // Output parameter.
|
||||
T C; // Output parameter.
|
||||
|
||||
// Create kernel.
|
||||
AddKernel add_kernel;
|
||||
@@ -54,16 +53,15 @@ void test_add(const T& type) {
|
||||
// In a GPU-only test, we can verify that the CPU and GPU produce the
|
||||
// same results.
|
||||
T C_cpu, C_gpu;
|
||||
T D_cpu = run_on_cpu(add_kernel, A, B, C_cpu); // Runs on CPU.
|
||||
T D_gpu = run_on_gpu(add_kernel, A, B, C_gpu); // Runs on GPU.
|
||||
T D_cpu = run_on_cpu(add_kernel, A, B, C_cpu); // Runs on CPU.
|
||||
T D_gpu = run_on_gpu(add_kernel, A, B, C_gpu); // Runs on GPU.
|
||||
VERIFY_IS_CWISE_EQUAL(C_cpu, C_gpu);
|
||||
VERIFY_IS_CWISE_EQUAL(D_cpu, D_gpu);
|
||||
};
|
||||
|
||||
struct MultiplyKernel {
|
||||
template<typename Type1, typename Type2, typename Type3>
|
||||
EIGEN_DEVICE_FUNC
|
||||
Type3 operator()(const Type1& A, const Type2& B, Type3& C) const {
|
||||
template <typename Type1, typename Type2, typename Type3>
|
||||
EIGEN_DEVICE_FUNC Type3 operator()(const Type1& A, const Type2& B, Type3& C) const {
|
||||
C = A * B;
|
||||
return A * B;
|
||||
}
|
||||
@@ -85,9 +83,9 @@ void test_multiply(const T1& type1, const T2& type2, const T3& type3) {
|
||||
|
||||
// 2 outputs of size (A * B). For each matrix output, the buffer will store
|
||||
// the number of rows, columns, and the data.
|
||||
size_t buffer_capacity_hint = 2 * ( // 2 output parameters
|
||||
2 * sizeof(typename T3::Index) // # Rows, # Cols
|
||||
+ A.rows() * B.cols() * sizeof(typename T3::Scalar)); // Output data
|
||||
size_t buffer_capacity_hint = 2 * ( // 2 output parameters
|
||||
2 * sizeof(typename T3::Index) // # Rows, # Cols
|
||||
+ A.rows() * B.cols() * sizeof(typename T3::Scalar)); // Output data
|
||||
|
||||
T3 D = run_with_hint(buffer_capacity_hint, multiply_kernel, A, B, C);
|
||||
|
||||
@@ -97,34 +95,26 @@ void test_multiply(const T1& type1, const T2& type2, const T3& type3) {
|
||||
|
||||
T3 C_cpu, C_gpu;
|
||||
T3 D_cpu = run_on_cpu(multiply_kernel, A, B, C_cpu);
|
||||
T3 D_gpu = run_on_gpu_with_hint(buffer_capacity_hint,
|
||||
multiply_kernel, A, B, C_gpu);
|
||||
T3 D_gpu = run_on_gpu_with_hint(buffer_capacity_hint, multiply_kernel, A, B, C_gpu);
|
||||
VERIFY_IS_CWISE_APPROX(C_cpu, C_gpu);
|
||||
VERIFY_IS_CWISE_APPROX(D_cpu, D_gpu);
|
||||
}
|
||||
|
||||
// Declare the test fixture.
|
||||
EIGEN_DECLARE_TEST(gpu_example)
|
||||
{
|
||||
EIGEN_DECLARE_TEST(gpu_example) {
|
||||
// For the number of repeats, call the desired subtests.
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
for (int i = 0; i < g_repeat; i++) {
|
||||
// Call subtests with different sized/typed inputs.
|
||||
CALL_SUBTEST( test_add(Eigen::Vector3f()) );
|
||||
CALL_SUBTEST( test_add(Eigen::Matrix3d()) );
|
||||
CALL_SUBTEST( test_add(Eigen::MatrixX<int>(10, 10)) );
|
||||
CALL_SUBTEST(test_add(Eigen::Vector3f()));
|
||||
CALL_SUBTEST(test_add(Eigen::Matrix3d()));
|
||||
CALL_SUBTEST(test_add(Eigen::MatrixX<int>(10, 10)));
|
||||
|
||||
CALL_SUBTEST( test_add(Eigen::Array44f()) );
|
||||
CALL_SUBTEST( test_add(Eigen::ArrayXd(20)) );
|
||||
CALL_SUBTEST( test_add(Eigen::ArrayXXi(13, 17)) );
|
||||
CALL_SUBTEST(test_add(Eigen::Array44f()));
|
||||
CALL_SUBTEST(test_add(Eigen::ArrayXd(20)));
|
||||
CALL_SUBTEST(test_add(Eigen::ArrayXXi(13, 17)));
|
||||
|
||||
CALL_SUBTEST( test_multiply(Eigen::Matrix3d(),
|
||||
Eigen::Matrix3d(),
|
||||
Eigen::Matrix3d()) );
|
||||
CALL_SUBTEST( test_multiply(Eigen::MatrixX<int>(10, 10),
|
||||
Eigen::MatrixX<int>(10, 10),
|
||||
Eigen::MatrixX<int>()) );
|
||||
CALL_SUBTEST( test_multiply(Eigen::MatrixXf(12, 1),
|
||||
Eigen::MatrixXf(1, 32),
|
||||
Eigen::MatrixXf()) );
|
||||
CALL_SUBTEST(test_multiply(Eigen::Matrix3d(), Eigen::Matrix3d(), Eigen::Matrix3d()));
|
||||
CALL_SUBTEST(test_multiply(Eigen::MatrixX<int>(10, 10), Eigen::MatrixX<int>(10, 10), Eigen::MatrixX<int>()));
|
||||
CALL_SUBTEST(test_multiply(Eigen::MatrixXf(12, 1), Eigen::MatrixXf(1, 32), Eigen::MatrixXf()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user