Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion advisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::vector<Transform const *> *Advisor::recommend(

SizeOptimizer optimizer(CudaVersion::V_8, tr, allowTransposition);
std::vector<const Transform *> *result =
optimizer.optimize(howMany, maxSignalInc, maxMemory, squareOnly, crop);
optimizer.optimize(howMany, maxSignalInc, maxMemory, squareOnly, crop, tr.rank);
resetDevice();
return result;
}
Expand Down
20 changes: 18 additions & 2 deletions generalTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ GeneralTransform::GeneralTransform(int device, int X, int Y, int Z, int N,
isFloat(isFloat),
isForward(isForward),
isInPlace(isInPlace),
isReal(isReal) {}
isReal(isReal) {
setRankInfo();
}

GeneralTransform::GeneralTransform(int X, int Y, int Z,
const GeneralTransform &tr)
Expand All @@ -30,7 +32,9 @@ GeneralTransform::GeneralTransform(int X, int Y, int Z,
isFloat(tr.isFloat),
isForward(tr.isForward),
isInPlace(tr.isInPlace),
isReal(tr.isReal) {}
isReal(tr.isReal) {
setRankInfo();
}

GeneralTransform::GeneralTransform(const GeneralTransform &tr) { *this = tr; }

Expand All @@ -46,8 +50,20 @@ GeneralTransform &GeneralTransform::operator=(const GeneralTransform &tr) {
this->isForward = tr.isForward;
this->isInPlace = tr.isInPlace;
this->isReal = tr.isReal;
setRankInfo();
}
return *this;
}

void GeneralTransform::setRankInfo() {
rank = RANK_3D;
if (1 == Z) {
if (1 == Y) {
rank = RANK_1D;
} else {
rank = RANK_2D;
}
}
}

} // namespace cuFFTAdvisor
11 changes: 11 additions & 0 deletions generalTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace cuFFTAdvisor {

class GeneralTransform {
public:

enum Rank { RANK_1D = 1, RANK_2D = 2, RANK_3D = 3 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class enum

Copy link
Member

Choose a reason for hiding this comment

The 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,
Expand All @@ -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
Expand Down
120 changes: 98 additions & 22 deletions sizeOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
Expand Down Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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.
Is it true?
If so, pass filtering/sorting method to general
template
optimizeXYZ(..., G &generator)

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);
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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;
}
Expand Down
18 changes: 16 additions & 2 deletions sizeOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class SizeOptimizer {
size_t exponent3;
size_t exponent5;
size_t exponent7;

bool operator < (const Polynom& cmp) const
{
return (value < cmp.value);
}

bool operator > (const Polynom& cmp) const
{
return (value > cmp.value);
}
};

struct valueComparator {
Expand All @@ -46,7 +56,7 @@ class SizeOptimizer {
bool allowTrans);
std::vector<const Transform *> *optimize(size_t nBest, int maxPercIncrease,
int maxMemMB, bool squareOnly,
bool crop);
bool crop, int rank);

private:
int getNoOfPrimes(Polynom &poly);
Expand All @@ -59,7 +69,11 @@ class SizeOptimizer {
std::set<Polynom, valueComparator> *filterOptimal(
std::vector<Polynom> *input, bool crop);
std::vector<Polynom> *generatePolys(size_t num, bool isFloat, bool crop);
std::vector<GeneralTransform> *optimizeXYZ(GeneralTransform &tr, size_t nBest,
void cutter(std::vector<Polynom>* polys, GeneralTransform &tr, bool crop, size_t nBest);
std::vector<GeneralTransform> *optimizeXYZ_3D(GeneralTransform &tr, size_t nBest,
int maxPercIncrease, bool squareOnly,
bool crop);
std::vector<GeneralTransform> *optimizeXYZ_1D_2D(GeneralTransform &tr, size_t nBest,
int maxPercIncrease, bool squareOnly,
bool crop);
std::vector<const Transform *> *optimizeN(
Expand Down
5 changes: 2 additions & 3 deletions transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cstdio>
#include <stdexcept>
#include "utils.h"
#include "generalTransform.h"

namespace cuFFTAdvisor {

Expand All @@ -13,8 +14,6 @@ class Transform {
void print(FILE *stream = stdout) const;
static void printHeader(FILE *stream = stdout);

enum Rank { RANK_1D = 1, RANK_2D = 2, RANK_3D = 3 };

Transform(int device, int X, int Y, int Z, int N, bool isBatched,
bool isFloat, bool isForward, bool isInPlace, bool isReal)
: device(device),
Expand Down Expand Up @@ -48,7 +47,7 @@ class Transform {
bool isForward; // otherwise inverse

// derived
Rank rank;
GeneralTransform::Rank rank;
size_t elems; // of the transform // FIXME remove
size_t inTypeSize;
size_t outTypeSize;
Expand Down