Bugzilla – Attachment 422 Details for
Bug 404
Optimize products for small objects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
Test case for small products
small_product.cpp (text/plain), 1.33 KB, created by
Christoph Hertzberg
on 2014-03-06 16:12:12 UTC
(
hide
)
Description:
Test case for small products
Filename:
MIME Type:
Creator:
Christoph Hertzberg
Created:
2014-03-06 16:12:12 UTC
Size:
1.33 KB
patch
obsolete
>#include <iostream> >#include <Eigen/Core> >#include <bench/BenchTimer.h> > >// Choose either one: >//typedef Eigen::MatrixXd Mat; >typedef Eigen::MatrixXf Mat; > >EIGEN_DONT_INLINE void trivial_product(Mat& res, const Mat& A, const Mat& B) { > typedef Mat::Scalar Scalar; > typedef Mat::Index Index; > Index rows = A.rows(), cols = B.cols(), inner = A.cols(); > res.resize(rows, cols); > for(Index i=0; i<cols; ++i) { > for(Index j=0; j<rows; ++j) { > Scalar r = A(j,0) * B(0,i); > for(Index k=1; k<inner; ++k) { > r+= A(j,k) * B(k,i); > } > res(j,i) = r; > } > } >} > >EIGEN_DONT_INLINE void default_product(Mat& res, const Mat& A, const Mat& B) { > res.noalias() = A*B; >} > > >int main() { > // Choose size limits here: > for(int s1=1; s1<=8; ++s1) { > for(int s2=1; s2<=8; ++s2) { > for(int s3=1; s3<=8; ++s3) { > > std::cout << "Size=" << s1 << "x" << s2 << " * " << s2 << "x" << s3 << "\t"; > Mat res(s1,s3), res2(s1,s3), A, B; > A.setRandom(s1, s2); B.setRandom(s2, s3); > int rep = 5000, tries = 100; > Eigen::BenchTimer t0, t1; > BENCH(t0, tries, rep, trivial_product(res, A, B)); > BENCH(t1, tries, rep, default_product(res2, A, B)); > double flops = s1*s3*(2*s2-1) * rep / 1e6; // calculate MFLOPS > std::cout << "ratio: " << t1.best() / t0.best() << "\ttrivial: " << flops/t0.best() << "\tdefault: " << flops/t1.best() << std::endl; > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 404
: 422 |
457
|
629