math.hpp modified to remove ambiguis calls in cuda build

This commit is contained in:
Hamidreza Norouzi 2023-10-19 12:18:29 +03:30
parent d2cd132b62
commit 66fc880fcd
4 changed files with 130 additions and 169 deletions

View File

@ -11,7 +11,7 @@
#include "TypeTools.hpp"
// [CLI11:public_includes:set]
#include <cmath>
#include "math.hpp"
#include <cstdint>
#include <functional>
#include <iostream>

View File

@ -21,16 +21,16 @@ Licence:
#ifndef __math_hpp__
#define __math_hpp__
#include <cmath>
#include "pFlowMacros.hpp"
#include "builtinTypes.hpp"
#ifdef __CUDACC__
#include "math.h"
#else
#include <cmath>
#endif
#include "pFlowMacros.hpp"
#include "builtinTypes.hpp"
//* * * * * * * * * * * List of functinos * * * * * * * * //
@ -44,7 +44,8 @@ namespace pFlow
{
INLINE_FUNCTION_HD real abs(real x)
INLINE_FUNCTION_HD
real abs(real x)
{
#ifdef __CUDACC__
return ::fabs(x);
@ -53,24 +54,20 @@ INLINE_FUNCTION_HD real abs(real x)
#endif
}
INLINE_FUNCTION_HD int64 abs(int64 x)
{
#ifdef __CUDACC__
return ::abs(x);
#else
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 abs(int64 x)
{
return std::abs(x);
}
#endif
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD int32 abs(int32 x)
{
#ifdef __CUDACC__
return ::abs(x);
#else
return std::abs(x);
#endif
}
#endif
INLINE_FUNCTION_HD real mod(real x, real y)
@ -102,163 +99,132 @@ INLINE_FUNCTION_HD auto mod(uint32 x, uint32 y)
return x%y;
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD real remainder(real x, real y)
{
#ifdef __CUDACC__
return ::remainder(x,y);
#else
return std::remainder(x,y);
#endif
}
#endif
INLINE_FUNCTION_HD real exp(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_H
real exp(real x)
{
#ifdef __CUDACC__
return ::exp(x);
#else
return std::exp(x);
#endif
}
#endif
INLINE_FUNCTION_HD real log(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log(real x)
{
#ifdef __CUDACC__
return ::log(x);
#else
return std::log(x);
#endif
}
#endif
INLINE_FUNCTION_HD real log10(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log10(real x)
{
#ifdef __CUDACC__
return ::log10(x);
#else
return std::log10(x);
#endif
}
#endif
INLINE_FUNCTION_HD real pow(real x, real y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real pow(real x, real y)
{
#ifdef __CUDACC__
return ::pow(x, y);
#else
return std::pow(x, y);
}
#endif
}
INLINE_FUNCTION_HD real sqrt(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sqrt(real x)
{
#ifdef __CUDACC__
return ::sqrt(x);
#else
return std::sqrt(x);
#endif
}
#endif
INLINE_FUNCTION_HD real cbrt (real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cbrt (real x)
{
#ifdef __CUDACC__
return ::cbrt (x);
#else
return std::cbrt (x);
#endif
}
#endif
INLINE_FUNCTION_HD real sin(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sin(real x)
{
#ifdef __CUDACC__
return ::sin(x);
#else
return std::sin(x);
#endif
}
#endif
INLINE_FUNCTION_HD real cos(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cos(real x)
{
#ifdef __CUDACC__
return ::cos(x);
#else
return std::cos(x);
#endif
}
#endif
INLINE_FUNCTION_HD real tan(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real tan(real x)
{
#ifdef __CUDACC__
return ::tan(x);
#else
return std::tan(x);
#endif
}
#endif
INLINE_FUNCTION_HD real asin(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real asin(real x)
{
#ifdef __CUDACC__
return ::asin(x);
#else
return std::asin(x);
}
#endif
}
INLINE_FUNCTION_HD real acos(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real acos(real x)
{
#ifdef __CUDACC__
return ::acos(x);
#else
return std::acos(x);
#endif
}
#endif
INLINE_FUNCTION_HD real atan(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atan(real x)
{
#ifdef __CUDACC__
return ::atan(x);
#else
return std::atan(x);
}
#endif
}
INLINE_FUNCTION_HD real atan2(real y, real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD real
atan2(real y, real x)
{
#ifdef __CUDACC__
return ::atan2(y, x);
#else
return std::atan2(y, x);
#endif
}
#endif
INLINE_FUNCTION_HD real sinh(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sinh(real x)
{
#ifdef __CUDACC__
return ::sinh(x);
#else
return std::sinh(x);
#endif
}
#endif
INLINE_FUNCTION_HD real cosh(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cosh(real x)
{
#ifdef __CUDACC__
return ::cosh(x);
#else
return std::cosh(x);
#endif
}
#endif
INLINE_FUNCTION_HD real tanh(real x)
{
@ -287,14 +253,14 @@ INLINE_FUNCTION_HD real acosh(real x)
#endif
}
INLINE_FUNCTION_HD real atanh(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atanh(real x)
{
#ifdef __CUDACC__
return ::atanh(x);
#else
return std::atanh(x);
#endif
}
#endif
INLINE_FUNCTION_HD real min(real x, real y)
{
@ -305,43 +271,36 @@ INLINE_FUNCTION_HD real min(real x, real y)
#endif
}
INLINE_FUNCTION_HD int64 min(int32 x, int32 y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 min(int32 x, int32 y)
{
#ifdef __CUDACC__
return ::min(x, y);
#else
return std::min(x, y);
#endif
}
INLINE_FUNCTION_HD int64 min(int64 x, int64 y)
{
#ifdef __CUDACC__
return ::min(x, y);
#else
return std::min(x, y);
#endif
}
INLINE_FUNCTION_HD uint64 min(uint64 x, uint64 y)
{
#ifdef __CUDACC__
return ::min(x, y);
#else
return std::min(x, y);
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 min(int64 x, int64 y)
{
return std::min(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
uint64 min(uint64 x, uint64 y)
{
return std::min(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint32 min(uint32 x, uint32 y)
{
#ifdef __CUDACC__
return ::min(x, y);
#else
return std::min(x, y);
#endif
}
#endif
INLINE_FUNCTION_HD real max(real x, real y)
@ -353,42 +312,34 @@ INLINE_FUNCTION_HD real max(real x, real y)
#endif
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD int64 max(int64 x, int64 y)
{
#ifdef __CUDACC__
return ::max(x, y);
#else
return std::max(x, y);
#endif
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD int32 max(int32 x, int32 y)
{
#ifdef __CUDACC__
return ::max(x, y);
#else
return std::max(x, y);
#endif
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint64 max(uint64 x, uint64 y)
{
#ifdef __CUDACC__
return ::max(x, y);
#else
return std::max(x, y);
#endif
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint32 max(uint32 x, uint32 y)
{
#ifdef __CUDACC__
return ::max(x, y);
#else
return std::max(x, y);
#endif
}
#endif
} // pFlow

View File

@ -18,18 +18,22 @@ Licence:
-----------------------------------------------------------------------------*/
namespace pFlow
{
#define T3Func(fnName) \
template<typename T> \
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::fnName(const pFlow::triple<T>& v) \
INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& v) \
{ \
return pFlow::triple<T>(fnName(v.x_), fnName(v.y_), fnName(v.z_)); \
return triple<T>(fnName(v.x_), fnName(v.y_), fnName(v.z_)); \
}
#define T3Func2(fnName) \
template<typename T> \
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::fnName(const pFlow::triple<T>& arg1, const pFlow::triple<T>& arg2) \
INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& arg1, const triple<T>& arg2) \
{ \
return pFlow::triple<T>(fnName(arg1.x_, arg2.x_), fnName(arg1.y_,arg2.y_), fnName(arg1.z_, arg2.z_)); \
return triple<T>(fnName(arg1.x_, arg2.x_), fnName(arg1.y_,arg2.y_), fnName(arg1.z_, arg2.z_)); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
@ -68,21 +72,21 @@ T3Func2(max);
// elements of t3 raised by e
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::pow(const pFlow::triple<T>& t3, T e)
INLINE_FUNCTION_HD triple<T> pow(const triple<T>& t3, T e)
{
return pFlow::triple<T>( pow(t3.x_, e), pow(t3.y_,e), pow(t3.z_,e));
return triple<T>( pow(t3.x_, e), pow(t3.y_,e), pow(t3.z_,e));
}
// return the min of 3 elements x, y, z
template<typename T>
INLINE_FUNCTION_HD T pFlow::min(const pFlow::triple<T>& t3)
INLINE_FUNCTION_HD T min(const triple<T>& t3)
{
return min( min(t3.x_, t3.y_), t3.z_);
}
// return the max of 3 elements x, y, z
template<typename T>
INLINE_FUNCTION_HD T pFlow::max(const pFlow::triple<T>& t3)
INLINE_FUNCTION_HD T max(const triple<T>& t3)
{
return max( max(t3.x_, t3.y_), t3.z_);
}
@ -91,3 +95,5 @@ INLINE_FUNCTION_HD T pFlow::max(const pFlow::triple<T>& t3)
#undef T3Func
#undef T3Func2
}

View File

@ -50,6 +50,8 @@ using realx3x3 = triple<realx3>;
using realx4 = quadruple<real>;
using realx4x3 = quadruple<realx3>;
template<>
inline word basicTypeName<int8x3>(){ return "int8x3"; }
@ -85,6 +87,8 @@ inline word basicTypeName<realx3x3>(){ return "realx3x3"; }
template<>
inline word basicTypeName<realx4>(){ return "realx4"; }
template<>
inline word basicTypeName<realx4x3>(){ return "realx4x3"; }
extern const realx3 zero3;
extern const realx3 one3;