// workaround issue between gcc >= 4.7 and cuda 5.5 #if (defined __GNUC__) && (__GNUC__>4 || __GNUC_MINOR__>=7) #undef _GLIBCXX_ATOMIC_BUILTINS #undef _GLIBCXX_USE_INT128 #endif #define EIGEN_TEST_NO_LONGDOUBLE #define EIGEN_TEST_NO_COMPLEX #define EIGEN_TEST_FUNC cuda_basic #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int #include "main.h" #include "cuda_common.h" #include // struct Foo{ // EIGEN_DEVICE_FUNC // void operator()(int i, const float* mats, float* vecs) const { // using namespace Eigen; // // Matrix3f M(data); // // Vector3f x(data+9); // // Map(data+9) = M.inverse() * x; // Matrix3f M(mats+i/16); // Vector3f x(vecs+i*3); // // using std::min; // // using std::sqrt; // Map(vecs+i*3) << x.minCoeff(), 1, 2;// / x.dot(x);//(M.inverse() * x) / x.x(); // //x = x*2 + x.y() * x + x * x.maxCoeff() - x / x.sum(); // } // }; template struct coeff_wise { EIGEN_DEVICE_FUNC void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const { using namespace Eigen; T x1(in+i); T x2(in+i+1); T x3(in+i+2); Map res(out+i*T::MaxSizeAtCompileTime); res.array() += (in[0] * x1 + x2).array() * x3.array(); } }; template struct redux { EIGEN_DEVICE_FUNC void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const { using namespace Eigen; int N = 6; T x1(in+i); out[i*N+0] = x1.minCoeff(); out[i*N+1] = x1.maxCoeff(); out[i*N+2] = x1.sum(); out[i*N+3] = x1.prod(); // out[i*N+4] = x1.colwise().sum().maxCoeff(); // out[i*N+5] = x1.rowwise().maxCoeff().sum(); } }; template struct prod { EIGEN_DEVICE_FUNC void operator()(int i, const typename T1::Scalar* in, typename T1::Scalar* out) const { using namespace Eigen; typedef Matrix T3; T1 x1(in+i); T2 x2(in+i+1); Map res(out+i*T3::MaxSizeAtCompileTime); res += in[i] * x1 * x2; } }; template struct diagonal { EIGEN_DEVICE_FUNC void operator()(int i, const typename T1::Scalar* in, typename T1::Scalar* out) const { using namespace Eigen; T1 x1(in+i); Map res(out+i*T2::MaxSizeAtCompileTime); res += x1.diagonal(); } }; template struct eigenvalues { EIGEN_DEVICE_FUNC void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const { using namespace Eigen; typedef Matrix Vec; T M(in+i); Map res(out+i*Vec::MaxSizeAtCompileTime); T A = M*M.adjoint(); SelfAdjointEigenSolver eig; eig.computeDirect(M); res = eig.eigenvalues(); } }; void test_cuda_basic() { ei_test_init_cuda(); int nthreads = 100; Eigen::VectorXf in, out; #ifndef __CUDA_ARCH__ int data_size = nthreads * 16; in.setRandom(data_size); out.setRandom(data_size); #endif CALL_SUBTEST( run_and_compare_to_cuda(coeff_wise(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(coeff_wise(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(redux(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(redux(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(prod(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(prod(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(diagonal(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_c(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(eigenvalues(), nthreads, in, out) ); CALL_SUBTEST( run_and_compare_to_cuda(eigenvalues(), nthreads, in, out) ); }