Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix-c-compat' into add_gamess_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed May 21, 2024
2 parents 9fa6e03 + 37871e0 commit b2f7a2b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 233 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,15 @@ add_to_config(_versionInfo HIP_VERSION_GITHASH "${HIP_VERSION_GITHASH}")
file(WRITE ${PROJECT_BINARY_DIR}/bin/.hipVersion ${_versionInfo})
install(FILES ${PROJECT_BINARY_DIR}/bin/.hipVersion DESTINATION bin)

file(COPY ${CMAKE_SOURCE_DIR}/HIP/include/
DESTINATION ${CMAKE_BINARY_DIR}/include)
file(COPY ${CMAKE_SOURCE_DIR}/include/
DESTINATION ${CMAKE_BINARY_DIR}/include)
if(CHIP_BUILD_HIPBLAS)
file(COPY ${CMAKE_SOURCE_DIR}/H4I-HipBLAS/include/
DESTINATION ${CMAKE_BINARY_DIR}/include)
endif()

# Setup .hipInfo. One for install and another for build directory.
string(TIMESTAMP _timestamp UTC)
set(_hipInfo_install "# Auto-generated by cmake on ${_timestamp} UTC\n")
Expand Down
301 changes: 69 additions & 232 deletions include/hip/spirv_hip_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,295 +39,132 @@ THE SOFTWARE.
#endif
#endif // !defined(__HIPCC_RTC__)

#if __cplusplus
#define COMPLEX_NEG_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type operator-(const type &op) { \
type ret; \
ret.x = -op.x; \
ret.y = -op.y; \
return ret; \
}

#define COMPLEX_EQ_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline bool operator==(const type &lhs, \
const type &rhs) { \
return lhs.x == rhs.x && lhs.y == rhs.y; \
}

#define COMPLEX_NE_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline bool operator!=(const type &lhs, \
const type &rhs) { \
return !(lhs == rhs); \
}

#define COMPLEX_ADD_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type operator+(const type &lhs, \
const type &rhs) { \
type ret; \
ret.x = lhs.x + rhs.x; \
ret.y = lhs.y + rhs.y; \
return ret; \
}

#define COMPLEX_SUB_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type operator-(const type &lhs, \
const type &rhs) { \
type ret; \
ret.x = lhs.x - rhs.x; \
ret.y = lhs.y - rhs.y; \
return ret; \
}

#define COMPLEX_MUL_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type operator*(const type &lhs, \
const type &rhs) { \
type ret; \
ret.x = lhs.x * rhs.x - lhs.y * rhs.y; \
ret.y = lhs.x * rhs.y + lhs.y * rhs.x; \
return ret; \
}

#define COMPLEX_DIV_OP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type operator/(const type &lhs, \
const type &rhs) { \
type ret; \
ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); \
ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); \
ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); \
ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); \
return ret; \
}

#define COMPLEX_ADD_PREOP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type &operator+=(type &lhs, const type &rhs) { \
lhs.x += rhs.x; \
lhs.y += rhs.y; \
return lhs; \
}

#define COMPLEX_SUB_PREOP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type &operator-=(type &lhs, const type &rhs) { \
lhs.x -= rhs.x; \
lhs.y -= rhs.y; \
return lhs; \
}

#define COMPLEX_MUL_PREOP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type &operator*=(type &lhs, const type &rhs) { \
lhs = lhs * rhs; \
return lhs; \
}

#define COMPLEX_DIV_PREOP_OVERLOAD(type) \
__HOST_DEVICE__ static inline type &operator/=(type &lhs, const type &rhs) { \
lhs = lhs / rhs; \
return lhs; \
}

#define COMPLEX_SCALAR_PRODUCT(type, type1) \
__HOST_DEVICE__ static inline type operator*(const type &lhs, type1 rhs) { \
type ret; \
ret.x = lhs.x * rhs; \
ret.y = lhs.y * rhs; \
return ret; \
}

#endif

class hipFloatComplex : public HIP_vector_type<float, 2U> {};
typedef float2 hipFloatComplex;

__HOST_DEVICE__ static inline float hipCrealf(hipFloatComplex z) { return z.x; }

__HOST_DEVICE__ static inline float hipCimagf(hipFloatComplex z) { return z.y; }

__HOST_DEVICE__ static inline hipFloatComplex make_hipFloatComplex(float a,
float b) {
hipFloatComplex z;
z.x = a;
z.y = b;
return z;
__HOST_DEVICE__ static inline hipFloatComplex make_hipFloatComplex(float a, float b) {
hipFloatComplex z;
z.x = a;
z.y = b;
return z;
}

__HOST_DEVICE__ static inline hipFloatComplex hipConjf(hipFloatComplex z) {
hipFloatComplex ret;
ret.x = z.x;
ret.y = -z.y;
return ret;
hipFloatComplex ret;
ret.x = z.x;
ret.y = -z.y;
return ret;
}

__HOST_DEVICE__ static inline float hipCsqabsf(hipFloatComplex z) {
return z.x * z.x + z.y * z.y;
return z.x * z.x + z.y * z.y;
}

__HOST_DEVICE__ static inline hipFloatComplex hipCaddf(hipFloatComplex p,
hipFloatComplex q) {
return make_hipFloatComplex(p.x + q.x, p.y + q.y);
__HOST_DEVICE__ static inline hipFloatComplex hipCaddf(hipFloatComplex p, hipFloatComplex q) {
return make_hipFloatComplex(p.x + q.x, p.y + q.y);
}

__HOST_DEVICE__ static inline hipFloatComplex hipCsubf(hipFloatComplex p,
hipFloatComplex q) {
return make_hipFloatComplex(p.x - q.x, p.y - q.y);
__HOST_DEVICE__ static inline hipFloatComplex hipCsubf(hipFloatComplex p, hipFloatComplex q) {
return make_hipFloatComplex(p.x - q.x, p.y - q.y);
}

__HOST_DEVICE__ static inline hipFloatComplex hipCmulf(hipFloatComplex p,
hipFloatComplex q) {
return make_hipFloatComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
__HOST_DEVICE__ static inline hipFloatComplex hipCmulf(hipFloatComplex p, hipFloatComplex q) {
return make_hipFloatComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
}

__HOST_DEVICE__ static inline hipFloatComplex hipCdivf(hipFloatComplex p,
hipFloatComplex q) {
float sqabs = hipCsqabsf(q);
hipFloatComplex ret;
ret.x = (p.x * q.x + p.y * q.y) / sqabs;
ret.y = (p.y * q.x - p.x * q.y) / sqabs;
return ret;
__HOST_DEVICE__ static inline hipFloatComplex hipCdivf(hipFloatComplex p, hipFloatComplex q) {
float sqabs = hipCsqabsf(q);
hipFloatComplex ret;
ret.x = (p.x * q.x + p.y * q.y) / sqabs;
ret.y = (p.y * q.x - p.x * q.y) / sqabs;
return ret;
}

__HOST_DEVICE__ static inline float hipCabsf(hipFloatComplex z) {
return sqrtf(hipCsqabsf(z));
}
__HOST_DEVICE__ static inline float hipCabsf(hipFloatComplex z) { return sqrtf(hipCsqabsf(z)); }

class hipDoubleComplex : public HIP_vector_type<double, 2U> {};

__HOST_DEVICE__ static inline double hipCreal(hipDoubleComplex z) {
return z.x;
}
typedef double2 hipDoubleComplex;

__HOST_DEVICE__ static inline double hipCimag(hipDoubleComplex z) {
return z.y;
}
__HOST_DEVICE__ static inline double hipCreal(hipDoubleComplex z) { return z.x; }

__HOST_DEVICE__ static inline hipDoubleComplex make_hipDoubleComplex(double a,
double b) {
hipDoubleComplex z;
z.x = a;
z.y = b;
return z;
__HOST_DEVICE__ static inline double hipCimag(hipDoubleComplex z) { return z.y; }

__HOST_DEVICE__ static inline hipDoubleComplex make_hipDoubleComplex(double a, double b) {
hipDoubleComplex z;
z.x = a;
z.y = b;
return z;
}

__HOST_DEVICE__ static inline hipDoubleComplex hipConj(hipDoubleComplex z) {
hipDoubleComplex ret;
ret.x = z.x;
ret.y = -z.y;
return ret;
hipDoubleComplex ret;
ret.x = z.x;
ret.y = -z.y;
return ret;
}

__HOST_DEVICE__ static inline double hipCsqabs(hipDoubleComplex z) {
return z.x * z.x + z.y * z.y;
}

__HOST_DEVICE__ static inline hipDoubleComplex hipCadd(hipDoubleComplex p,
hipDoubleComplex q) {
return make_hipDoubleComplex(p.x + q.x, p.y + q.y);
return z.x * z.x + z.y * z.y;
}

__HOST_DEVICE__ static inline hipDoubleComplex hipCsub(hipDoubleComplex p,
hipDoubleComplex q) {
return make_hipDoubleComplex(p.x - q.x, p.y - q.y);
__HOST_DEVICE__ static inline hipDoubleComplex hipCadd(hipDoubleComplex p, hipDoubleComplex q) {
return make_hipDoubleComplex(p.x + q.x, p.y + q.y);
}

__HOST_DEVICE__ static inline hipDoubleComplex hipCmul(hipDoubleComplex p,
hipDoubleComplex q) {
return make_hipDoubleComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
__HOST_DEVICE__ static inline hipDoubleComplex hipCsub(hipDoubleComplex p, hipDoubleComplex q) {
return make_hipDoubleComplex(p.x - q.x, p.y - q.y);
}

__HOST_DEVICE__ static inline hipDoubleComplex hipCdiv(hipDoubleComplex p,
hipDoubleComplex q) {
double sqabs = hipCsqabs(q);
hipDoubleComplex ret;
ret.x = (p.x * q.x + p.y * q.y) / sqabs;
ret.y = (p.y * q.x - p.x * q.y) / sqabs;
return ret;
__HOST_DEVICE__ static inline hipDoubleComplex hipCmul(hipDoubleComplex p, hipDoubleComplex q) {
return make_hipDoubleComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
}

__HOST_DEVICE__ static inline double hipCabs(hipDoubleComplex z) {
return sqrt(hipCsqabs(z));
__HOST_DEVICE__ static inline hipDoubleComplex hipCdiv(hipDoubleComplex p, hipDoubleComplex q) {
double sqabs = hipCsqabs(q);
hipDoubleComplex ret;
ret.x = (p.x * q.x + p.y * q.y) / sqabs;
ret.y = (p.y * q.x - p.x * q.y) / sqabs;
return ret;
}

#if __cplusplus

COMPLEX_NEG_OP_OVERLOAD(hipFloatComplex)
COMPLEX_EQ_OP_OVERLOAD(hipFloatComplex)
COMPLEX_NE_OP_OVERLOAD(hipFloatComplex)
COMPLEX_ADD_OP_OVERLOAD(hipFloatComplex)
COMPLEX_SUB_OP_OVERLOAD(hipFloatComplex)
COMPLEX_MUL_OP_OVERLOAD(hipFloatComplex)
COMPLEX_DIV_OP_OVERLOAD(hipFloatComplex)
COMPLEX_ADD_PREOP_OVERLOAD(hipFloatComplex)
COMPLEX_SUB_PREOP_OVERLOAD(hipFloatComplex)
COMPLEX_MUL_PREOP_OVERLOAD(hipFloatComplex)
COMPLEX_DIV_PREOP_OVERLOAD(hipFloatComplex)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned short)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed short)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned int)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed int)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, float)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned long)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed long)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, double)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed long long)
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned long long)

COMPLEX_NEG_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_EQ_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_NE_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_ADD_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_SUB_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_MUL_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_DIV_OP_OVERLOAD(hipDoubleComplex)
COMPLEX_ADD_PREOP_OVERLOAD(hipDoubleComplex)
COMPLEX_SUB_PREOP_OVERLOAD(hipDoubleComplex)
COMPLEX_MUL_PREOP_OVERLOAD(hipDoubleComplex)
COMPLEX_DIV_PREOP_OVERLOAD(hipDoubleComplex)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned short)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed short)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned int)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed int)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, float)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned long)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed long)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, double)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed long long)
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned long long)

#endif
__HOST_DEVICE__ static inline double hipCabs(hipDoubleComplex z) { return sqrt(hipCsqabs(z)); }

typedef hipFloatComplex hipComplex;

__HOST_DEVICE__ static inline hipComplex make_hipComplex(float x, float y) {
return make_hipFloatComplex(x, y);
return make_hipFloatComplex(x, y);
}

__HOST_DEVICE__ static inline hipFloatComplex
hipComplexDoubleToFloat(hipDoubleComplex z) {
return make_hipFloatComplex((float)z.x, (float)z.y);
__HOST_DEVICE__ static inline hipFloatComplex hipComplexDoubleToFloat(hipDoubleComplex z) {
return make_hipFloatComplex((float)z.x, (float)z.y);
}

__HOST_DEVICE__ static inline hipDoubleComplex
hipComplexFloatToDouble(hipFloatComplex z) {
return make_hipDoubleComplex((double)z.x, (double)z.y);
__HOST_DEVICE__ static inline hipDoubleComplex hipComplexFloatToDouble(hipFloatComplex z) {
return make_hipDoubleComplex((double)z.x, (double)z.y);
}

__HOST_DEVICE__ static inline hipComplex hipCfmaf(hipComplex p, hipComplex q,
hipComplex r) {
float real = (p.x * q.x) + r.x;
float imag = (q.x * p.y) + r.y;
__HOST_DEVICE__ static inline hipComplex hipCfmaf(hipComplex p, hipComplex q, hipComplex r) {
float real = (p.x * q.x) + r.x;
float imag = (q.x * p.y) + r.y;

real = -(p.y * q.y) + real;
imag = (p.x * q.y) + imag;
real = -(p.y * q.y) + real;
imag = (p.x * q.y) + imag;

return make_hipComplex(real, imag);
return make_hipComplex(real, imag);
}

__HOST_DEVICE__ static inline hipDoubleComplex
hipCfma(hipDoubleComplex p, hipDoubleComplex q, hipDoubleComplex r) {
double real = (p.x * q.x) + r.x;
double imag = (q.x * p.y) + r.y;
__HOST_DEVICE__ static inline hipDoubleComplex hipCfma(hipDoubleComplex p, hipDoubleComplex q,
hipDoubleComplex r) {
double real = (p.x * q.x) + r.x;
double imag = (q.x * p.y) + r.y;

real = -(p.y * q.y) + real;
imag = (p.x * q.y) + imag;
real = -(p.y * q.y) + real;
imag = (p.x * q.y) + imag;

return make_hipDoubleComplex(real, imag);
return make_hipDoubleComplex(real, imag);
}

#endif // SPIRV_HIP_COMPLEX_H
1 change: 0 additions & 1 deletion scripts/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ else
cmake ../ -DCMAKE_BUILD_TYPE="$build_type" -DCHIP_BUILD_HIPBLAS=ON -DCMAKE_INSTALL_PREFIX=${CHIPSTAR_INSTALL_DIR}
make all build_tests install -j $(nproc) #&> /dev/null
echo "chipStar build complete."

fi
module unload opencl/dgpu

Expand Down
Loading

0 comments on commit b2f7a2b

Please sign in to comment.