Kaydet (Commit) 05785bfb authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Andras Timar

tdf#94924: Return correct result 0 from OpenCL MIN and MAX when all args empty

Used the same style as existing code, added a new virtual isMinOrMax()
and add some special casing in Reduction::GenSlidingWindowFunction(),
and fsim_count() and fmax_count() functions that count how many
non-NaN numbers we actually see. As such, I am not sure at all that
this is an ideal way to do this, but will have to do for now.

Change-Id: I846a8d24f4563f8fae1a45971a4ce202ed918487
Signed-off-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
(cherry picked from commit 127c2683)
üst 876a2be1
...@@ -64,6 +64,18 @@ static const char* publicFunc = ...@@ -64,6 +64,18 @@ static const char* publicFunc =
" (*p) += t?0:1;\n" " (*p) += t?0:1;\n"
" return t?b:a+b;\n" " return t?b:a+b;\n"
"}\n" "}\n"
"double fmin_count(double a, double b, __private int *p) {\n"
" double result = fmin(a, b);\n"
" bool t = isnan(result);\n"
" (*p) += t?0:1;\n"
" return result;\n"
"}\n"
"double fmax_count(double a, double b, __private int *p) {\n"
" double result = fmax(a, b);\n"
" bool t = isnan(result);\n"
" (*p) += t?0:1;\n"
" return result;\n"
"}\n"
"double fsum(double a, double b) { return isNan(a)?b:a+b; }\n" "double fsum(double a, double b) { return isNan(a)?b:a+b; }\n"
"double legalize(double a, double b) { return isNan(a)?b:a;}\n" "double legalize(double a, double b) { return isNan(a)?b:a;}\n"
"double fsub(double a, double b) { return a-b; }\n" "double fsub(double a, double b) { return a-b; }\n"
...@@ -1698,7 +1710,7 @@ public: ...@@ -1698,7 +1710,7 @@ public:
ss << ") {\n"; ss << ") {\n";
ss << "double tmp = " << GetBottom() << ";\n"; ss << "double tmp = " << GetBottom() << ";\n";
ss << "int gid0 = get_global_id(0);\n"; ss << "int gid0 = get_global_id(0);\n";
if (isAverage()) if (isAverage() || isMinOrMax())
ss << "int nCount = 0;\n"; ss << "int nCount = 0;\n";
ss << "double tmpBottom;\n"; ss << "double tmpBottom;\n";
unsigned i = vSubArguments.size(); unsigned i = vSubArguments.size();
...@@ -1778,12 +1790,17 @@ public: ...@@ -1778,12 +1790,17 @@ public:
ss << ss <<
"if (nCount==0)\n" "if (nCount==0)\n"
" return CreateDoubleError(errDivisionByZero);\n"; " return CreateDoubleError(errDivisionByZero);\n";
else if (isMinOrMax())
ss <<
"if (nCount==0)\n"
" return 0;\n";
ss << "return tmp"; ss << "return tmp";
if (isAverage()) if (isAverage())
ss << "*pow((double)nCount,-1.0)"; ss << "*pow((double)nCount,-1.0)";
ss << ";\n}"; ss << ";\n}";
} }
virtual bool isAverage() const { return false; } virtual bool isAverage() const { return false; }
virtual bool isMinOrMax() const { return false; }
virtual bool takeString() const SAL_OVERRIDE { return false; } virtual bool takeString() const SAL_OVERRIDE { return false; }
virtual bool takeNumeric() const SAL_OVERRIDE { return true; } virtual bool takeNumeric() const SAL_OVERRIDE { return true; }
}; };
...@@ -2198,12 +2215,13 @@ class OpMin : public Reduction ...@@ -2198,12 +2215,13 @@ class OpMin : public Reduction
public: public:
OpMin( int nResultSize ) : Reduction(nResultSize) {} OpMin( int nResultSize ) : Reduction(nResultSize) {}
virtual std::string GetBottom() SAL_OVERRIDE { return "MAXFLOAT"; } virtual std::string GetBottom() SAL_OVERRIDE { return "NAN"; }
virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE
{ {
return "fmin(" + lhs + "," + rhs + ")"; return "fmin_count(" + lhs + "," + rhs + ", &nCount)";
} }
virtual std::string BinFuncName() const SAL_OVERRIDE { return "min"; } virtual std::string BinFuncName() const SAL_OVERRIDE { return "min"; }
virtual bool isMinOrMax() const SAL_OVERRIDE { return true; }
}; };
class OpMax : public Reduction class OpMax : public Reduction
...@@ -2211,12 +2229,13 @@ class OpMax : public Reduction ...@@ -2211,12 +2229,13 @@ class OpMax : public Reduction
public: public:
OpMax( int nResultSize ) : Reduction(nResultSize) {} OpMax( int nResultSize ) : Reduction(nResultSize) {}
virtual std::string GetBottom() SAL_OVERRIDE { return "-MAXFLOAT"; } virtual std::string GetBottom() SAL_OVERRIDE { return "NAN"; }
virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE
{ {
return "fmax(" + lhs + "," + rhs + ")"; return "fmax_count(" + lhs + "," + rhs + ", &nCount)";
} }
virtual std::string BinFuncName() const SAL_OVERRIDE { return "max"; } virtual std::string BinFuncName() const SAL_OVERRIDE { return "max"; }
virtual bool isMinOrMax() const SAL_OVERRIDE { return true; }
}; };
class OpSumProduct : public SumOfProduct class OpSumProduct : public SumOfProduct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment