-
Notifications
You must be signed in to change notification settings - Fork 3
Reimplementation of the 3D Optimizer #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c4cec0e
d571398
514fc9e
c86ff23
b70fb38
dd1b9fd
29a85b9
6188cbd
0626cca
d36168e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ namespace cuFFTAdvisor { | |
|
|
||
| class GeneralTransform { | ||
| public: | ||
|
|
||
| enum Rank { RANK_1D = 1, RANK_2D = 2, RANK_3D = 3 }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove it from transform.h |
||
|
|
||
| GeneralTransform(int device, int X, int Y, int Z, int N, | ||
| Tristate::Tristate isBatched, Tristate::Tristate isFloat, | ||
| Tristate::Tristate isForward, Tristate::Tristate isInPlace, | ||
|
|
@@ -30,6 +33,14 @@ class GeneralTransform { | |
| Tristate::Tristate isForward; // otherwise inverse | ||
| Tristate::Tristate isInPlace; // otherwise out-of-place | ||
| Tristate::Tristate isReal; // otherwise C2C | ||
|
|
||
| Rank rank; | ||
|
|
||
| private: | ||
| /** | ||
| * Sets fields that describe rank (dimensionality) | ||
| */ | ||
| void setRankInfo(); | ||
| }; | ||
|
|
||
| } // namespace cuFFTAdvisor | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ SizeOptimizer::SizeOptimizer(CudaVersion::CudaVersion version, | |
| log_5(1.0 / std::log(5)), | ||
| log_7(1.0 / std::log(7)) { | ||
| if (Tristate::BOTH == tr.isFloat) { | ||
| // if user is not sure if he/she needs double, then he/she doesn't need it | ||
| // if user is not sure if they needs double, then they doesn't need it | ||
| tr.isFloat = Tristate::TRUE; | ||
| } | ||
|
|
||
|
|
@@ -37,11 +37,15 @@ std::vector<const Transform *> *SizeOptimizer::optimize(size_t nBest, | |
| int maxPercIncrease, | ||
| int maxMemMB, | ||
| bool squareOnly, | ||
| bool crop) { | ||
| bool crop, int rank) { | ||
| std::vector<GeneralTransform> preoptimized; | ||
| for (auto in : input) { | ||
| std::vector<GeneralTransform> *tmp = | ||
| optimizeXYZ(in, nBest, maxPercIncrease, squareOnly, crop); | ||
| std::vector<GeneralTransform> *tmp; | ||
| if(rank == GeneralTransform::RANK_3D){ | ||
| tmp = optimizeXYZ_3D(in, nBest, maxPercIncrease, squareOnly, crop); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to decide here. Check it within the optimizeXYZ (and call appropriate version there) |
||
| }else{ | ||
| tmp = optimizeXYZ_1D_2D(in, nBest, maxPercIncrease, squareOnly, crop); | ||
| } | ||
| preoptimized.insert(preoptimized.end(), tmp->begin(), tmp->end()); | ||
| delete tmp; | ||
| } | ||
|
|
@@ -161,11 +165,83 @@ size_t SizeOptimizer::getMinSize(GeneralTransform &tr, int maxPercDecrease, bool | |
| return std::max(0.f, afterPercInc); | ||
| } | ||
|
|
||
| std::vector<GeneralTransform> *SizeOptimizer::optimizeXYZ(GeneralTransform &tr, | ||
| void SizeOptimizer::cutter(std::vector<Polynom>* polys, GeneralTransform &tr, bool crop, size_t nBest){ | ||
| //This function generate Polynom, sort them resize the vector | ||
| if(crop){ | ||
| std::sort (polys->begin(), polys->end(), std::greater<Polynom>()); | ||
| }else{ | ||
| std::sort (polys->begin(), polys->end(), std::less<Polynom>()); | ||
| } | ||
| polys->resize(nBest); | ||
| } | ||
|
|
||
| std::vector<GeneralTransform> *SizeOptimizer::optimizeXYZ_3D(GeneralTransform &tr, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems to me that the only difference to 1D/2D case is filtering vs sorting. |
||
| size_t nBest, | ||
| int maxPercIncrease, | ||
| bool squareOnly, | ||
| bool crop) { | ||
|
|
||
| std::vector<Polynom> *polysX = generatePolys(tr.X, tr.isFloat, crop); | ||
| cutter(polysX, tr, crop, nBest); | ||
| std::vector<Polynom> *polysY; | ||
| std::vector<Polynom> *polysZ; | ||
|
|
||
| if ((tr.X == tr.Y) || squareOnly) { | ||
| polysY = polysX; | ||
| } else { | ||
| polysY = generatePolys(tr.Y, tr.isFloat, crop); | ||
| cutter(polysY, tr, crop, nBest); | ||
| } | ||
|
|
||
| if ((tr.X == tr.Z) || squareOnly) { | ||
| polysZ = polysX; | ||
| } else if (tr.Y == tr.Z) { | ||
| polysZ = polysY; | ||
| } else { | ||
| polysZ = generatePolys(tr.Z, tr.isFloat, crop); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. repetitive code, please extract helper method |
||
| cutter(polysZ, tr, crop, nBest); | ||
| } | ||
|
|
||
| size_t minSize = getMinSize(tr, maxPercIncrease, crop); | ||
| size_t maxSize = getMaxSize(tr, maxPercIncrease, squareOnly, crop); | ||
|
|
||
| std::vector<GeneralTransform> *result = new std::vector<GeneralTransform>; | ||
| size_t found = 0; | ||
| for (auto& x : *polysX) { | ||
| for (auto& y : *polysY) { | ||
| if (squareOnly && (x.value != y.value)) continue; | ||
| size_t xy = x.value * y.value; | ||
| if (xy > maxSize) | ||
| break; // polynoms are sorted by size, we're already above the limit | ||
| for (auto& z : *polysZ) { | ||
| if (squareOnly && (x.value != z.value)) continue; | ||
| size_t xyz = xy * z.value; | ||
| if ((found < nBest) && (xyz >= minSize) && (xyz <= maxSize)) { | ||
| // we can take nbest only, as others very probably won't be faster | ||
| found++; | ||
| GeneralTransform t((int)x.value, (int)y.value, (int)z.value, tr); | ||
| result->push_back(t); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ((polysZ != polysY) && (polysZ != polysX)) { | ||
| delete polysZ; | ||
| } | ||
| if (polysY != polysX) { | ||
| delete polysY; | ||
| } | ||
| delete polysX; | ||
| return result; | ||
| } | ||
|
|
||
| std::vector<GeneralTransform> *SizeOptimizer::optimizeXYZ_1D_2D(GeneralTransform &tr, | ||
| size_t nBest, | ||
| int maxPercIncrease, | ||
| bool squareOnly, | ||
| bool crop) { | ||
|
|
||
| std::vector<Polynom> *polysX = generatePolys(tr.X, tr.isFloat, crop); | ||
| std::vector<Polynom> *polysY; | ||
| std::vector<Polynom> *polysZ; | ||
|
|
@@ -198,27 +274,27 @@ std::vector<GeneralTransform> *SizeOptimizer::optimizeXYZ(GeneralTransform &tr, | |
| size_t maxSize = getMaxSize(tr, maxPercIncrease, squareOnly, crop); | ||
|
|
||
| std::vector<GeneralTransform> *result = new std::vector<GeneralTransform>; | ||
| size_t found = 0; | ||
| for (auto& x : *recPolysX) { | ||
| for (auto& y : *recPolysY) { | ||
| if (squareOnly && (x.value != y.value) && (y.value != 1)) continue; | ||
| size_t xy = x.value * y.value; | ||
| if (xy > maxSize) | ||
| break; // polynoms are sorted by size, we're already above the limit | ||
| for (auto& z : *recPolysZ) { | ||
| if (squareOnly && (x.value != z.value) && (z.value != 1)) continue; | ||
| size_t xyz = xy * z.value; | ||
| if ((found < nBest) && (xyz >= minSize) && (xyz <= maxSize)) { | ||
| // we can take nbest only, as others very probably won't be faster | ||
| found++; | ||
| GeneralTransform t((int)x.value, (int)y.value, (int)z.value, tr); | ||
| result->push_back(t); | ||
| size_t found = 0; | ||
| for (auto& x : *recPolysX) { | ||
| for (auto& y : *recPolysY) { | ||
| if (squareOnly && (x.value != y.value) && (y.value != 1)) continue; | ||
| size_t xy = x.value * y.value; | ||
| if (xy > maxSize) | ||
| break; // polynoms are sorted by size, we're already above the limit | ||
| for (auto& z : *recPolysZ) { | ||
| if (squareOnly && (x.value != z.value) && (z.value != 1)) continue; | ||
| size_t xyz = xy * z.value; | ||
| if ((found < nBest) && (xyz >= minSize) && (xyz <= maxSize)) { | ||
| // we can take nbest only, as others very probably won't be faster | ||
| found++; | ||
| GeneralTransform t((int)x.value, (int)y.value, (int)z.value, tr); | ||
| result->push_back(t); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (polysZ != polysY) { | ||
| if ((polysZ != polysY) && (polysZ != polysX)) { | ||
| delete polysZ; | ||
| delete recPolysZ; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class enum